def testConvertTo_01(self):
        
        t = TreeDict()
        t.z = 3
        t.a.x = 1
        t.a.y = 2

        # Test default
        self.assert_(t.convertTo() == t.convertTo('nested_dict'))
        
        self.assert_(t.convertTo() == {'a' : {'x' : 1, 'y' : 2}, 'z' : 3})
    def testConvertTo_01(self):

        t = TreeDict()
        t.z = 3
        t.a.x = 1
        t.a.y = 2

        # Test default
        self.assert_(t.convertTo() == t.convertTo("nested_dict"))

        self.assert_(t.convertTo() == {"a": {"x": 1, "y": 2}, "z": 3})
    def testConvertTo_08_self_referencing_lists(self):
        t = TreeDict()

        t.a = [t]

        d = t.convertTo("nested_dict", expand_lists=False)

        self.assert_(d["a"][0] is t)

        d2 = t.convertTo("nested_dict", expand_lists=True)

        self.assert_(d2["a"][0] is d2)
    def testConvertTo_07_lists(self):
        t = TreeDict()

        t.a.b = [1, TreeDict(x=1)]

        d = t.convertTo("nested_dict", expand_lists=False)

        self.assert_(d == {"a": {"b": [1, TreeDict(x=1)]}})

        d2 = t.convertTo("nested_dict", expand_lists=True)

        self.assert_(d2 == {"a": {"b": [1, {"x": 1}]}})
    def testConvertTo_07_lists(self):
        t = TreeDict()

        t.a.b = [1, TreeDict(x = 1)]

        d = t.convertTo('nested_dict', expand_lists = False)

        self.assert_(d == {'a' : {'b' : [1, TreeDict(x = 1)]}})
        
        d2 = t.convertTo('nested_dict', expand_lists = True)

        self.assert_(d2 == {'a' : {'b' : [1, {'x' : 1} ]}})
    def testConvertTo_06_prune_empty_02(self):

        t = TreeDict()

        t.a.x = 1
        t.a.makeBranch("b")

        d = t.convertTo("nested_dict", prune_empty=False)

        self.assert_(d == {"a": {"x": 1, "b": {}}})

        d2 = t.convertTo("nested_dict", prune_empty=True)

        self.assert_(d2 == {"a": {"x": 1}})
    def testConvertTo_06_prune_empty_02(self):

        t = TreeDict()

        t.a.x = 1
        t.a.makeBranch('b')

        d = t.convertTo('nested_dict', prune_empty = False)

        self.assert_(d == {'a' : {'x' : 1, 'b' : {} } } )
        
        d2 = t.convertTo('nested_dict', prune_empty = True)

        self.assert_(d2 == {'a' : {'x' : 1 } } )
    def testConvertTo_04_root_linked_01(self):

        t = TreeDict()
        t.a = t

        d = t.convertTo("nested_dict")

        self.assert_(d["a"] is d)
    def testConvertTo_04_root_linked_01(self):

        t = TreeDict()
        t.a = t

        d = t.convertTo('nested_dict')

        self.assert_(d['a'] is d)
    def testConvertTo_06_prune_empty_01(self):

        t = TreeDict()

        t.makeBranch("a")

        d = t.convertTo("nested_dict", prune_empty=True)

        self.assert_(d == {})
    def testConvertTo_04_root_linked_02(self):

        t = TreeDict()
        t.a.b.c = t
        t.a.b.x = t.a

        d = t.convertTo("nested_dict")

        self.assert_(d["a"]["b"]["c"] is d)
        self.assert_(d["a"]["b"]["x"] is d["a"])
Exemple #12
0
    def testConvertTo_04_root_linked_02(self):

        t = TreeDict()
        t.a.b.c = t
        t.a.b.x = t.a

        d = t.convertTo('nested_dict')

        self.assert_(d['a']['b']['c'] is d)
        self.assert_(d['a']['b']['x'] is d['a'])
    def testConvertTo_03_self_linked_01(self):

        t = TreeDict()
        t.makeBranch("b")
        t.a.b = t.b
        t.b.a = t.a

        d = t.convertTo("nested_dict")

        self.assert_(type(d["a"]) is dict)
        self.assert_(type(d["b"]) is dict)

        self.assert_(d["a"]["b"] is d["b"])
        self.assert_(d["b"]["a"] is d["a"])
Exemple #14
0
    def testConvertTo_03_self_linked_01(self):

        t = TreeDict()
        t.makeBranch('b')
        t.a.b = t.b
        t.b.a = t.a

        d = t.convertTo('nested_dict')

        self.assert_(type(d['a']) is dict)
        self.assert_(type(d['b']) is dict)
        
        self.assert_(d['a']['b'] is d['b'])
        self.assert_(d['b']['a'] is d['a'])