def testMutability_03(self):
        # Makes sure that stored branches are handled correctly
        
        p1 = TreeDict('root')
        
        p1.a = (13, (123, 32))
        p1.b = 123
        p1.c.a = 145
        p1.c.b = "1231321321231321"
        
        p2 = TreeDict('node')

        p2.a = 432

        p1.node = p2

        self.assert_(p1.isMutable())

        p1.freeze()
        
        self.assert_(p1.isMutable())

        p2.freeze()
        
        self.assert_(not p1.isMutable())
示例#2
0
    def testEqualityWithDanglingNode_06(self):
        p1 = TreeDict()
        p2 = TreeDict()
        p1.a = p1.b
        p2.a = p2.b

        self.assert_(p1 == p2)
    def testFreezingStructure_01(self):
        p = TreeDict()

        p.a = 1

        p.freeze(structure_only = True)

        p.a = 2

        self.assert_(p.a == 2)
        self.assertRaises(TypeError, lambda: p.set('b',1))
示例#4
0
    def test_EqualitySubtree(self):
        t1 = TreeDict()
        t2 = TreeDict()
        
        t1.a = 1
        t2.a = 2
        t1.b.c.d = 1
        t2.b.c.d = 1

        self.assert_(t1.b == t2.b)
        self.assert_(t1 != t2)
示例#5
0
    def testUpdate_WithFreezing_StructureOnly_01(self):

        p = TreeDict()
        
        p.a = 1
        p.freeze(structure_only = True)

        q = TreeDict()
        q.a = 2

        p.update(q)

        self.assert_(p.a == 2)
示例#6
0
    def testUpdate_WithFreezing_StructureOnly_02(self):

        p = TreeDict()
        
        p.a = 1
        p.freeze(structure_only = True)

        q = TreeDict()
        q.a = 2
        q.b = 3

        self.assertRaises(TypeError, lambda: p.update(q))

        self.assert_(p.a == 1)
        self.assert_('b' not in p)
示例#7
0
    def testEqualityWithDanglingNode_04(self):
        p1 = TreeDict()
        p2 = TreeDict()
        p1.a = 1
        p2.a

        self.assert_(p1 != p2)
示例#8
0
    def testRecursiveAttach_03_recursive_with_linked_nodes(self):
        p = TreeDict()

        p.a = p.adef.a
        p.adef.a.v = 1

        p.attach(recursive=True)
示例#9
0
    def testBranchStructureFrozen_01(self):

        p = TreeDict()
        p.a = TreeDict(x = 1)
        p.freeze(structure_only = True)

        self.assertRaises(TypeError, lambda: p.attach(recursive = True))
示例#10
0
    def testOrdering_01(self):
        t = TreeDict()

        t.a = 1
        t.b = 2

        self.assert_(t._getSettingOrderPosition('a') == (0,), t._getSettingOrderPosition('a'))
        self.assert_(t._getSettingOrderPosition('b') == (1,), t._getSettingOrderPosition('b'))
示例#11
0
    def testSet_20_setting_linked_branch_02(self):
        p = TreeDict()

        p.a = p.defs.a1

        p.set("defs.a1.v", 1)

        self.assert_(p.a.v == 1)
示例#12
0
    def testCopying_01d(self):
        p1 = TreeDict('root')
        p1.a = 123

        p2 = deepcopy(p1)

        self.assert_(p1 == p2)
        self.assert_(p1.hash() == p2.hash())
示例#13
0
 def test03(self):
     
     test_tree = TreeDict()
     test_tree.x = 2
     test_tree.a = 1
     test_tree.b = 2
     
     runTest(['data.set_X_2'], 'data', test_tree)
示例#14
0
    def testSet_19_overwriting_value_with_branch_01_okay(self):
        p = TreeDict()

        p.a = 12

        p.set("a.b.c", 1, protect_values=False)

        self.assert_(p.a.b.c == 1)
示例#15
0
    def testBranchHasValuePropegationFlags_02(self):

        p = TreeDict()
        p.a = 1
        p.freeze(values_only = True)
        p.makeBranch('b')

        self.assert_(p.b.valuesAreFrozen())
示例#16
0
    def testConvertTo_04_root_linked_01(self):

        t = TreeDict()
        t.a = t

        d = t.convertTo('nested_dict')

        self.assert_(d['a'] is d)
示例#17
0
 def test02(self):
     
     test_tree = TreeDict()
     test_tree.x = 1
     test_tree.a = 10
     test_tree.b = 2
     
     runTest(['change_default_a'], 'data', test_tree)
示例#18
0
    def testPickling_Dangling_02(self):

        p = TreeDict()
        p.a = p.b

        p2 = cPickle.loads(cPickle.dumps(p, protocol=2))

        self.assert_(p2 == p)
示例#19
0
 def test01(self):
     
     test_tree = TreeDict()
     test_tree.x = 1
     test_tree.a = 1
     test_tree.b = 2
     
     runTest([], 'data', test_tree)
示例#20
0
    def testConvertTo_04_root_linked_01(self):

        t = TreeDict()
        t.a = t

        d = t.convertTo("nested_dict")

        self.assert_(d["a"] is d)
示例#21
0
    def testAttaching_01(self):
        p1 = TreeDict('root')
        p2 = TreeDict('node')

        p2.a = 123
        p1.attach(p2)

        self.assert_(p1.node.a == 123)
        self.assert_(p1.node.rootNode() is p1)
        self.assert_(p2.rootNode() is p2)
示例#22
0
    def testCopying_09_LinkedValuesPreserved_Reversed(self):

        p = TreeDict()
        p.b.x = 1
        p.a = p.b

        q = p.copy()

        self.assert_(p.b is not q.b)
        self.assert_(q.b is q.a)
示例#23
0
    def testDeletion_01(self):

        p = TreeDict()
        p.a = 1

        self.assert_('a' in p)

        del p['a']

        self.assert_('a' not in p)
示例#24
0
    def testDeletion_01(self):

        p = TreeDict()
        p.a = 1

        self.assert_("a" in p)

        del p["a"]

        self.assert_("a" not in p)
示例#25
0
    def testSet_19_overwriting_value_with_branch_02_nochange_on_bad(self):
        p = TreeDict()

        p.a = 12

        pc = p.copy()

        self.assertRaises(NameError, lambda: p.set("a.b.c.123.d", 1, protect_structure = False))

        self.assert_(p.a == 12)
        self.assert_(p == pc)
示例#26
0
    def testDetach_07_nonbranch(self):
        # Test to make sure the behavior is like pop() (perhaps we
        # should chang the name ??)

        p = TreeDict()
        p.a = 1

        v = p.pop('a')

        self.assert_(v == 1)
        self.assert_('a' not in p)
示例#27
0
    def testUpdate_16_DanglingNodesIgnored(self):
        p = TreeDict()
        p.a = 1

        q = TreeDict()
        q.a

        def check(r):
            self.assert_(r.a == 1)

        self.checkUpdate(p, q, False, check, overwrite=True, protect_structure=True)
示例#28
0
    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)
示例#29
0
    def testDangling_13_CorrectCountsThroughSiblingReferences(self):

        p = TreeDict()

        p.a = p.d
        self.assert_(p._numDangling() == 2)

        # Overwrite p.d; p.a still points to the dangling node, so the
        # count should not go down.

        p.d = 1
        self.assert_(p._numDangling() == 1)
示例#30
0
    def testAttaching_03(self):
        p1 = TreeDict('root')
        p2 = TreeDict('node')

        p2.a = 123
        p1.attach('attachnode', p2)

        self.assert_(p1.attachnode.a == 123)
        self.assert_(p1.attachnode.rootNode() is p1)
        self.assert_(p1.attachnode == p2)
        self.assert_(p1.attachnode.branchName(True,True) == "root.attachnode")
        self.assert_(p2.rootNode() is p2)
示例#31
0
t.t1 is t1
t.t1.rootNode()

from treedict import TreeDict
t = TreeDict('root')
t1 = TreeDict('t1')
t.attach(t1, name="new_t1", copy=False)
t1.rootNode()
t.new_t1 is t1

from treedict import TreeDict
t = TreeDict('root')
t1 = TreeDict('t1', x1=1, y1=2)
t2 = TreeDict('t2', x2=10, y2=20)

t.a = 1
t.t1 = t1
t.attach(t2)
print t.makeReport()
t.attach(recursive=True)
print t.makeReport()

#########################################
# For branch name

from treedict import TreeDict
t = TreeDict('root')
t.makeBranch("a.b.c")
t.a.b.c.branchName()
t.a.b.c.branchName(add_path=True)
t.a.b.c.branchName(add_path=True, add_tree_name=True)