예제 #1
0
    def test_can_convert_namedtuple_containing_namedtuple_to_dict(self):
        n = namedtuple("X", ["prop_1", "prop_2"])(prop_1=1, prop_2=2)
        t = namedtuple("Y", ["nested"])(nested=n)

        d = namedtuple_to_dict(t)

        self.assertDictEqual(d, {"nested": {"prop_1": 1, "prop_2": 2}})
예제 #2
0
    def test_can_convert_namedtuple_containing_list_with_namedtuple_to_dict(self):
        n = namedtuple("X", ["prop_1", "prop_2"])(prop_1=1, prop_2=2)
        l = [n]
        t = namedtuple("Y", ["nested"])(nested=l)

        d = namedtuple_to_dict(t)

        self.assertDictEqual(d, {"nested": [{"prop_1": 1, "prop_2": 2}]})
예제 #3
0
    def test_can_convert_flat_namedtuple_to_dict(self):
        t = namedtuple("X", ["prop_1", "prop_2"])(prop_1=1, prop_2=2)

        d = namedtuple_to_dict(t)

        self.assertDictEqual(d, {"prop_1": 1, "prop_2": 2})