diff --git a/tests/test_formats.py b/tests/test_formats.py index 42a354c7..25c27f28 100755 --- a/tests/test_formats.py +++ b/tests/test_formats.py @@ -292,6 +292,13 @@ def test_build_dict_conforming_to_schema(self): # Test construction of a few metadata formats using # build_dict_conforming_to_schema(). + # Try the wrong type of schema object. + STRING_SCHEMA = securesystemslib.schema.AnyString() + + with self.assertRaises(ValueError): + tuf.formats.build_dict_conforming_to_schema( + STRING_SCHEMA, string='some string') + # Try building Timestamp metadata. spec_version = tuf.SPECIFICATION_VERSION version = 8 diff --git a/tuf/formats.py b/tuf/formats.py index 9846fa4f..2c5128db 100755 --- a/tuf/formats.py +++ b/tuf/formats.py @@ -516,9 +516,9 @@ def build_dict_conforming_to_schema(schema, **kwargs): """ # Check the schema argument type (must provide check_match and _required). - if not isinstance(schema, SCHEMA.Schema): + if not isinstance(schema, SCHEMA.Object): raise ValueError( - 'The first argument must be a schema.Schema object, but is not. ' + 'The first argument must be a schema.Object instance, but is not. ' 'Given schema: ' + repr(schema)) # Make a copy of the provided fields so that the caller's provided values