def test_ignore_definitions(self): # there are several valid ways of specifying the ignored property. with open(_test_data_file_path('ignorant-schema-v3.json'), 'r') as f: s = schema.from_json_file(f, validate=True) self.assertIsInstance(s.fields[0], clkhash.field_formats.Ignore) self.assertIsInstance(s.fields[1], clkhash.field_formats.Ignore) self.assertIsInstance(s.fields[2], clkhash.field_formats.StringSpec)
def test_no_version(self): invalid_schema_file = io.StringIO('{}') # Missing version. msg = 'Schema with no version should raise SchemaError.' with self.assertRaises(SchemaError, msg=msg): schema.from_json_file(invalid_schema_file)
def test_string_schema(self): invalid_schema_file = io.StringIO('"foo"') # Must be dict. msg = 'Literal as top element should raise SchemaError.' with self.assertRaises(SchemaError, msg=msg): schema.from_json_file(invalid_schema_file)
def test_list_schema(self): invalid_schema_file = io.StringIO('[]') # Must be dict instead. msg = 'List as top element should raise SchemaError.' with self.assertRaises(SchemaError, msg=msg): schema.from_json_file(invalid_schema_file)
def test_invalid_json_schema(self): invalid_schema_file = io.StringIO('{') # Invalid json. msg = 'Invalid JSON in schema should raise SchemaError.' with self.assertRaises(SchemaError, msg=msg): schema.from_json_file(invalid_schema_file)
def test_valid_but_unsupported_schema(self): # This schema has an unsupported version. with open(_test_data_file_path( 'good-but-unsupported-schema-v1.json')) as f: with self.assertRaises(SchemaError): schema.from_json_file(f)
def test_invalid_schema(self): # This schema is not valid (missing encoding in its feature). with open(_test_data_file_path(BAD_SCHEMA_V1_PATH)) as f: with self.assertRaises(SchemaError): schema.from_json_file(f)
def test_good_schema_repr(self): with open(_test_data_file_path(GOOD_SCHEMA_V1_PATH)) as f: s = schema.from_json_file(f) schema_repr = repr(s) assert "v3" in schema_repr # v1 schema is converted to v2 and then to v3 :) assert "12 fields" in schema_repr
def test_good_schema(self): # These are some perfectly fine schemas. with open(_test_data_file_path(GOOD_SCHEMA_V1_PATH)) as f: schema.from_json_file(f)
def test_good_schema3_repr(self): with open(_test_data_file_path(GOOD_SCHEMA_V3_PATH)) as f: s = schema.from_json_file(f) schema_repr = repr(s) assert "v3" in schema_repr assert "12 fields" in schema_repr
def _test_schema(file_name): with open(_test_data_file_path(file_name)) as f: return schema.from_json_file(f)
def test_good_schema2_repr(self): with open(_test_data_file_path('good-schema-v2.json')) as f: s = schema.from_json_file(f) schema_repr = repr(s) assert "v2" in schema_repr assert "12 fields" in schema_repr
def test_good_schema_repr(self): with open(_test_data_file_path('good-schema-v1.json')) as f: s = schema.from_json_file(f) schema_repr = repr(s) assert "v2" in schema_repr # v1 schema is converted to v2 assert "12 fields" in schema_repr
def test_good_schema(self): # These are some perfectly fine schemas. with open(_test_data_file_path('good-schema-v1.json')) as f: schema.from_json_file(f)