Beispiel #1
0
 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)
Beispiel #2
0
 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)
Beispiel #3
0
 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)
Beispiel #4
0
 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)
Beispiel #5
0
 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)
Beispiel #6
0
 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)
Beispiel #7
0
 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)
Beispiel #8
0
 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
Beispiel #9
0
 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)
Beispiel #10
0
 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
Beispiel #11
0
def _test_schema(file_name):
    with open(_test_data_file_path(file_name)) as f:
        return schema.from_json_file(f)
Beispiel #12
0
 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
Beispiel #13
0
 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
Beispiel #14
0
 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)