def length_equality(self, data, schema, index, tree): try: data = data[index] try: schema = schema[index] except KeyError: if not hasattr(schema, 'must_validate'): reason = 'has unexpected item in data: %s' % data_item(data) raise Invalid(None, tree, msg=reason, reason=reason, pair='value') except (KeyError, TypeError): if not hasattr(schema, 'must_validate'): reason = "has less items in schema than in data" raise SchemaError(data, tree, reason=reason) if hasattr(schema, '__validator_leaf__'): return if len(data) != len(schema): raise SchemaError(data, tree, reason='length did not match schema')
def length_equality(self, data, schema, index, tree): try: data = data[index] try: schema = schema[index] except KeyError: if not hasattr(schema, 'must_validate'): reason = 'has unexpected item in data: %s' % data_item( data) raise Invalid(None, tree, msg=reason, reason=reason, pair='value') except (KeyError, TypeError): if not hasattr(schema, 'must_validate'): reason = "has less items in schema than in data" raise SchemaError(data, tree, reason=reason) if hasattr(schema, '__validator_leaf__'): return if len(data) != len(schema): raise SchemaError(data, tree, reason='length did not match schema')
def test_return_key_from_ndict(self): self.ndict[0] = ('a', 'b') assert utils.data_item(self.ndict) == "'a'"
def test_return_key_from_non_ndict(self): data = {'b': 'b'} assert utils.data_item(data) == "'b'"
def test_return_first_item_in_list(self): data = ['a', 'b', 'c'] assert utils.data_item(data) == "'a'"
def test_fallback_to_repr_of_obj(self): assert utils.data_item(self.ndict) == "{}"
def test_return_key_from_non_ndict(self): data = {"b": "b"} assert utils.data_item(data) == "'b'"
def test_return_key_from_ndict(self): self.ndict[0] = ("a", "b") assert utils.data_item(self.ndict) == "'a'"
def test_return_first_item_in_list(self): data = ["a", "b", "c"] assert utils.data_item(data) == "'a'"