def test_key_dict_multiple_items(self): schema = KeyDict({"one": Int(), "two": List(Float())}) input = {"one": 32, "two": [1.5, 2.3]} self.assertEquals(schema.coerce(input, PATH), { "one": 32, "two": [1.5, 2.3] })
def test_key_dict_unknown_key(self): """ Unknown key/value pairs processed by a KeyDict are left untouched. This is an attempt at not eating values by mistake due to something like different application versions operating on the same data. """ schema = KeyDict({"foo": Int()}) self.assertEquals(schema.coerce({"foo": 1, "bar": "hi"}, PATH), {"foo": 1, "bar": "hi"})
def test_key_dict_unknown_key(self): """ Unknown key/value pairs processed by a KeyDict are left untouched. This is an attempt at not eating values by mistake due to something like different application versions operating on the same data. """ schema = KeyDict({"foo": Int()}) self.assertEquals(schema.coerce({ "foo": 1, "bar": "hi" }, PATH), { "foo": 1, "bar": "hi" })
def test_key_dict_pass_optional_key(self): """Regression test. It should be possible to pass an optional key. """ schema = KeyDict({"foo": Int()}, optional=["foo"]) self.assertEquals(schema.coerce({"foo": 32}, PATH), {"foo": 32})
def test_key_dict_optional_keys(self): """KeyDict allows certain keys to be optional. """ schema = KeyDict({"foo": Int(), "bar": Int()}, optional=["bar"]) self.assertEquals(schema.coerce({"foo": 32}, PATH), {"foo": 32})
def test_key_dict_multiple_items(self): schema = KeyDict({"one": Int(), "two": List(Float())}) input = {"one": 32, "two": [1.5, 2.3]} self.assertEquals(schema.coerce(input, PATH), {"one": 32, "two": [1.5, 2.3]})
def test_key_dict_pass_optional_key(self): """Regression test. It should be possible to pass an optional key. """ schema = KeyDict({"foo": Int()}, optional=["foo"]) self.assertEquals(schema.coerce({"foo": 32}, PATH), {"foo": 32})
def test_key_dict_optional_keys(self): """KeyDict allows certain keys to be optional. """ schema = KeyDict({"foo": Int(), "bar": Int()}, optional=["bar"]) self.assertEquals(schema.coerce({"foo": 32}, PATH), {"foo": 32})