def test_use_schema_fails(self): schema = ('a', 2) hybrid = Hybrid(validator, schema) with raises(Invalid) as exc: hybrid({0: ('a', 1)}) error = exc.value.args[0] assert 'a -> 1 did not match 2' in error
def test_use_validator_fails(self): schema = () hybrid = Hybrid(validator, schema) with raises(Invalid) as exc: hybrid(0) error = exc.value.args[0] assert '0 did not pass validation against callable' in error
def test_hybrid_delegates_when_dict_or_list(self): # send off to Recursive when isinstance(value, (dict, list)) data = {'a': ['a']} hybrid = Hybrid(types.string, iterables.AllItems('b')) schema = ('a', hybrid) with raises(Invalid) as exc: validate(data, schema) error = exc.value.args[0] assert "list[0] item did not match 'b'" in error
def test_extra_unexpected_items(self): optional_schema = (optional(1), 1) schema = ('a', Hybrid(validator, optional_schema)) data = {'a': {'foo': 'bar'}} with raises(Invalid) as exc: validate(data, schema) error = exc.value.args[0] assert '-> a did not match {}' in error assert exc.value.reason == 'unexpected extra items'
def test_fail_object(self): sschema = (1, 1) schema = ('a', Hybrid(validator, sschema)) data = {'a': {1: 2}} with raises(Invalid) as exc: validate(data, schema) error = exc.value.args[0] assert '1 -> 2 did not match 1' in error assert error.startswith('-> a -> 1')
def test_all_objects_pass_with_hybrid(self): data = {'a': {'a': 1, 'b': 2, 'c': 3}} dawg = Hybrid(lambda x: True, (types.string, types.integer)) yo_dawg = recursive.AllObjects(dawg) schema = ('a', yo_dawg) assert validate(data, schema) is None
def test_hybrid_delegates_when_dict_or_empty_list(self): # send off to Recursive when isinstance(value, (dict, list)) data = {'a': []} hybrid = Hybrid(types.string, iterables.AllItems('b')) schema = ('a', hybrid) assert validate(data, schema) is None
def test_passes_object(self): sschema = (1, 2) schema = ('a', Hybrid(validator, sschema)) data = {'a': {1: 2}} assert validate(data, schema) is None
def test_passes_single_value(self): sschema = (1, 2) schema = ('a', Hybrid(validator, sschema)) data = {'a': 2} assert validate(data, schema) is None
def test_use_schema_passes(self): schema = ('a', 1) hybrid = Hybrid(validator, schema) hybrid({0: ('a', 1)})
def test_use_validator_passes(self): schema = () hybrid = Hybrid(validator, schema) assert hybrid(1) is None