예제 #1
0
    def test_dict_type_basic(self):
        d = Dict('name')
        with self.assertRaises(ValueError):
            d({'foo': 'bar'})

        d = Dict(Any, 'name')
        d({'foo': 'bar'})  # doesn't raise
예제 #2
0
    def test_dict_type_basic(self):
        d = Dict("name")
        with self.assertRaises(ValueError):
            d({"foo": "bar"})

        d = Dict(Any, "name")
        d({"foo": "bar"})  # doesn't raise
예제 #3
0
    def test_tuple_type_with_recursive_item_types(self):
        t = Tuple((Dict(List(Any)), List(Dict(Any)), Unicode), 'name')
        with self.assertRaises(ValueError):
            t(({'foo': 'bar'}, [{'foo': 'bar'}], 'foo'))

        with self.assertRaises(ValueError):
            t(({'foo': ['bar']}, ['foo'], 'foo'))

        t(({'foo': ['bar']}, [{'foo': 'bar'}], 'foo'))  # doesn't raise
예제 #4
0
    def test_tuple_type_with_recursive_item_types(self):
        t = Tuple((Dict(List(Any)), List(Dict(Any)), Unicode), "name")
        with self.assertRaises(ValueError):
            t(({"foo": "bar"}, [{"foo": "bar"}], "foo"))

        with self.assertRaises(ValueError):
            t(({"foo": ["bar"]}, ["foo"], "foo"))

        t(({"foo": ["bar"]}, [{"foo": "bar"}], "foo"))  # doesn't raise
예제 #5
0
    def test_dict_type_with_recursive_item_types(self):
        d = Dict(Dict({Unicode: List(Int)}), 'name')
        with self.assertRaises(ValueError):
            d({'foo': 'bar'})

        with self.assertRaises(ValueError):
            d({'foo': {'bar': 'baz'}})

        with self.assertRaises(ValueError):
            d({'foo': {'bar': ['baz']}})

        d({'foo': {'bar': [1]}})  # doesn't raise
예제 #6
0
    def test_dict_type_with_recursive_item_types(self):
        d = Dict(Dict({Unicode: List(Int)}), "name")
        with self.assertRaises(ValueError):
            d({"foo": "bar"})

        with self.assertRaises(ValueError):
            d({"foo": {"bar": "baz"}})

        with self.assertRaises(ValueError):
            d({"foo": {"bar": ["baz"]}})

        d({"foo": {"bar": [1]}})  # doesn't raise
예제 #7
0
    def test_dict_type_with_dictionary_item_type(self):
        d = Dict({Int: Int}, 'name')
        with self.assertRaises(ValueError):
            d({'foo': 1})

        with self.assertRaises(ValueError):
            d({1: 'foo'})

        d({1: 2})  # doesn't raise
예제 #8
0
    def test_dict_type_with_dictionary_item_type(self):
        d = Dict({Int: Int}, "name")
        with self.assertRaises(ValueError):
            d({"foo": 1})

        with self.assertRaises(ValueError):
            d({1: "foo"})

        d({1: 2})  # doesn't raise
예제 #9
0
    def test_list_type_with_recursive_item_types(self):
        l = List(Dict(List(Tuple((Unicode, Int)))), 'name')
        with self.assertRaises(ValueError):
            l(['foo'])

        with self.assertRaises(ValueError):
            l([{'foo': 'bar'}])

        with self.assertRaises(ValueError):
            l([{'foo': ['bar']}])

        l([{'foo': [('bar', 1)]}])  # doesn't raise
예제 #10
0
    def test_list_type_with_recursive_item_types(self):
        l = List(Dict(List(Tuple((Unicode, Int)))), "name")
        with self.assertRaises(ValueError):
            l(["foo"])

        with self.assertRaises(ValueError):
            l([{"foo": "bar"}])

        with self.assertRaises(ValueError):
            l([{"foo": ["bar"]}])

        l([{"foo": [("bar", 1)]}])  # doesn't raise