コード例 #1
0
 def test_doesnt_allow_changing_schema_properties(self):
     schema_dict = {
         'foo': 'bar',
     }
     schema = Schema(schema_dict)
     with pytest.raises(AttributeError):
         schema.foo = 'baz'
コード例 #2
0
 def test_to_dict_modifying_the_dict_doesnt_modify_the_schema(self):
     original_schema_dict = {
         'foo': 'bar',
     }
     schema = Schema(original_schema_dict)
     schema_dict = schema.to_dict()
     schema_dict['bar'] = 'baz'
     assert 'bar' not in schema.to_dict()
コード例 #3
0
    def test_init_changing_the_original_schema_dict_doesnt_change_schema(self):
        schema_dict = {
            'foo': 'bar'
        }
        schema = Schema(schema_dict)
        schema_dict['bar'] = 'baz'

        assert 'bar' not in schema.to_dict()
コード例 #4
0
    def test_init_loads_schema_from_dict(self):
        schema_dict = {
            'foo': 'bar'
        }
        schema = Schema(schema_dict)

        assert schema.to_dict().keys() == schema_dict.keys()
        assert schema.to_dict()['foo'] == schema_dict['foo']
コード例 #5
0
 def test_validate_should_raise_when_invalid(self):
     schema_dict = {
         'properties': {
             'name': {
                 'type': 'string',
             }
         },
         'required': ['name'],
     }
     data = {}
     schema = Schema(schema_dict)
     with pytest.raises(datapackage_validate.exceptions.ValidationError):
         schema.validate(data)
コード例 #6
0
 def test_validate(self):
     schema_dict = {
         'properties': {
             'name': {
                 'type': 'string',
             }
         },
         'required': ['name'],
     }
     data = {
         'name': 'Sample Package',
     }
     schema = Schema(schema_dict)
     schema.validate(data)
コード例 #7
0
 def test_to_dict_converts_schema_to_dict(self):
     original_schema_dict = {
         'foo': 'bar',
     }
     schema = Schema(original_schema_dict)
     assert schema.to_dict() == original_schema_dict
コード例 #8
0
 def test_allow_changing_properties_not_in_schema(self):
     schema_dict = {}
     schema = Schema(schema_dict)
     schema.foo = 'bar'
     assert schema.foo == 'bar'