def testRecall_copying(self):
        p1 = getTree('rt_r01')
        p1.makeBranch('rt_b01')

        p1c = p1.rt_b01.copy()

        p2 = getTree('rt_b01')
        
        self.assertTrue(p1c is not p2)
    def testRecall_copying(self):
        p1 = getTree('rt_r01')
        p1.makeBranch('rt_b01')

        p1c = p1.rt_b01.copy()

        p2 = getTree('rt_b01')
        
        self.assert_(p1c is not p2)
    def testRecall_01(self):
        self.assert_(not treedict.treeExists('testtree'))

        p = treedict.getTree('testtree')

        self.assert_(treedict.treeExists('testtree'))

        p2 = treedict.getTree('testtree')
        
        self.assert_(p is p2)
    def testRecall_01(self):
        name = 'testtree-%d' % common._inheritance_level

        self.assertTrue(not treedict.treeExists(name))

        p = treedict.getTree(name)

        self.assertTrue(treedict.treeExists(name))

        p2 = treedict.getTree(name)
        
        self.assertTrue(p is p2)
Beispiel #5
0
    def testRecall_01(self):
        name = 'testtree-%d' % common._inheritance_level

        self.assert_(not treedict.treeExists(name))

        p = treedict.getTree(name)

        self.assert_(treedict.treeExists(name))

        p2 = treedict.getTree(name)
        
        self.assert_(p is p2)
    def testConstraint_21_global__branches_track_original_deep(self):
        n = 100
        tn = unique_name()
        bnl = [unique_name() for i in range(n)]
        p = getTree(tn)

        fullbn = '.'.join(bnl)

        p.makeBranch(fullbn)

        bl = [None]*n

        for i, bn in enumerate(bnl):
            bl[i] = (p if i == 0 else bl[i-1])[bn]

        treedict.addGlobalConstraint(fullbn + '.x', [1], "not 1")

        for i, b in enumerate(bnl[:-1]):

            def f():
                bl[i]['.'.join(bnl[i+1:]) + '.x'] = 2

            self.assertRaises(ValueError, f)

        for i, b in enumerate(bnl[:-1]):
            bl[i]['.'.join(bnl[i+1:]) + '.x'] = 1
    def testConstraint_17_global_constraint_not_added_on_failure(self):
        tn1 = unique_name()
        tn2 = unique_name()
        bn = unique_name()
        
        p1 = getTree(tn1)
        p1[bn] = 2

        p2 = getTree(tn2)

        def f():
            treedict.addGlobalConstraint(bn, [1], "not 1")
            
        self.assertRaises(ValueError, f)

        # Should be fine still, as the constraint should be backed out
        p2[bn] = 2
    def testConstraint_07_afterwards_global_2(self):
        tn = unique_name()
        bn = unique_name()

        p = getTree(tn)
        p[bn] = "bork"
        
        treedict.addGlobalConstraint(bn, ["bork", "bork1"])
    def testConstraint_06_afterwards_2(self):
        tn = unique_name()
        bn = unique_name()

        p = getTree(tn)
        p[bn] = "bork"  # passes
        
        treedict.addConstraint(unique_name(), bn,["bork", "bork1"])
    def testConstraint_09_branches_in_tree_names_03_control(self):
        tn = unique_name()
        tnb = tn + '.b'
        p = getTree(tnb)

        treedict.addConstraint(tnb, 'a', [1], "not 1")

        # shouldn't throw
        p.a = 1
    def testConstraint_09_branches_in_tree_names_02(self):
        tn = unique_name()

        p = getTree(tn)

        treedict.addConstraint(tn + '.b', 'a', [1], "not 1")

        # shouldn't throw
        p.b.a = 2
    def testConstraint_25_Links_01(self):
        tn = unique_name()
        p = treedict.getTree(tn)
        treedict.addConstraint(tn, 'a.b.link.v', [1], "not 1")

        p.d.v = 1
        p.a.b.link = p.d

        self.assert_(p.a.b.link.v == 1)
    def testConstraint_11_copying_02_aferwards(self):
        tn, bn = unique_name(), unique_name()

        p1 = getTree(tn)
        p1c = p1.makeBranch(bn).copy()
        p2 = getTree(bn)
        
        
        # Should work fine; not part of p2's family
        p1c.a = 2
        self.assert_(p1c.branchName() == bn)
        
        # Should cause throw, cause it's part of p2's family
        p2.a = 2
        
        def f(): treedict.addConstraint(bn, 'a', [1], "not 1")

        self.assertRaises(ValueError, f)
    def testConstraint_07_afterwards_global_1_copy_control(self):
        tn = unique_name()
        bn = unique_name()

        p = getTree(tn)
        b = p.copy()
        b[bn] = 1
        
        # Should be fine
        treedict.addGlobalConstraint(bn, [1], "not 1")
    def testConstraint_08_global_branch_copy_afterwards_1_control(self):
        bn = unique_name()

        p = getTree(unique_name())
        p.makeBranch(bn).makeBranch('a')

        q = p[bn].copy()
        q.a.b = "bork"  # should be bad

        treedict.addGlobalConstraint(bn + '.a.b', ["bork"])
    def testConstraint_06_afterwards_2_copy(self):
        tn = unique_name()
        bn = unique_name()

        p = getTree(tn)
        p[bn] = "bork"  # passes
        q = p.copy(deep = True)
        q[bn] = "bork1"  # passes

        treedict.addConstraint(tn, bn, ["bork", "bork1"])
    def testConstraint_17_constraint_not_added_on_failure__control(self):
        tn1 = unique_name()
        tn2 = unique_name()
        bn = unique_name()
        
        p1 = getTree(tn1)
        p1[bn] = 1

        p2 = getTree(tn2)

        treedict.addGlobalConstraint(bn, [1], "not 1")
            
        # Should throw, as the constraint succeeded
        def f():
            p2[bn] = 2

        self.assertRaises(ValueError, f)

        # Control, should pass
        p2[bn] = 1
Beispiel #18
0
    def testSetGet06(self):

        # regression test
        p = getTree('upt_08_bcg1_')
        p.a18462.a1732643.x = 1
        q = p.a18462.copy()
        q.a1732643.a1232 = "borkbork"  # should be bad

        self.assert_(p.a18462.a1732643.x == 1)
        self.assert_(q.a1732643.a1232 == "borkbork")
        self.assert_(q.a1732643.x == 1)
    def testConstraint_25_Links_03_set_in_linked_root(self):
        tn = unique_name()
        p = treedict.getTree(tn)
        treedict.addConstraint(tn, 'a.b.link.v', [1], "not 1")

        p.a.b.link = p.d

        def f():
            p.d.v = 1

        self.assertRaises(ValueError, f)
    def testConstraint_07_afterwards_global_1(self):
        tn = unique_name()
        bn = unique_name()

        p = getTree(tn)
        p[bn] = "borkbork"
        
        def f():
            treedict.addGlobalConstraint(bn, ["bork", "bork1"])

        self.assertRaises(ValueError, f)
    def testConstraint_27_after_Links_02_bad_value(self):
        tn = unique_name()
        p = treedict.getTree(tn)
        
        p.a.b.link = p.d
        p.d.v = 2

        def f():
            treedict.addConstraint(tn, 'a.b.link.v', [1], "not 1")
        
        self.assertRaises(ValueError, f)
Beispiel #22
0
    def testSetGet06(self):

        # regression test
        p = getTree('upt_08_bcg1_')
        p.a18462.a1732643.x = 1
        q = p.a18462.copy()
        q.a1732643.a1232 = "borkbork"  # should be bad

        self.assertTrue(p.a18462.a1732643.x == 1)
        self.assertTrue(q.a1732643.a1232 == "borkbork")
        self.assertTrue(q.a1732643.x == 1)
Beispiel #23
0
    def testSetGet07(self):

        # Regression
        p = getTree('upt_08_bcg2_whodunit_')
        self.assert_(not p.isFrozen())
        p.a18462.a1732643.x = 1
        q = p.a18462.a1732643.copy()
        q.a1232 = "borkbork"

        self.assert_(p.a18462.a1732643.x == 1)
        self.assert_(q.a1232 == "borkbork")
        self.assert_(q.x == 1)
Beispiel #24
0
    def testCopying_05b_central_system(self):
        # This test constrains the central system to have the same
        # name system as regular trees (I was tempted to do it
        # otherwise to make the constraints of copied branches
        # easier.)

        p = getTree('tc_root')
        b = p.makeBranch('b').copy()
    
        self.assert_(b.branchName(add_tree_name = True) == 'b', b.branchName(add_tree_name = True))
        self.assert_(p.b.branchName(add_path = True, add_tree_name = True) == 'tc_root.b',
                     p.b.branchName(add_path = True, add_tree_name = True))
    def testConstraint_07_afterwards_global_1_copy(self):
        tn = unique_name()
        bn = unique_name()

        p = getTree(tn)
        b = p.copy()
        b[bn]= 2
        
        def f():
            treedict.addGlobalConstraint(bn, [1], "not 1")

        self.assertRaises(ValueError, f)
    def testConstraint_30_Link_Conf_01_control(self):
        
        tn = unique_name()
        p = treedict.getTree(tn)

        treedict.addConstraint(tn, 'a.b.c', [1], "not 1")

        p.aa.a.bb.b.c = 1
        p.a = p.aa.a

        def f():
           p.a.b = p.a.bb.b 
Beispiel #27
0
    def testSetGet07(self):

        # Regression
        p = getTree('upt_08_bcg2_whodunit_')
        self.assertTrue(not p.isFrozen())
        p.a18462.a1732643.x = 1
        q = p.a18462.a1732643.copy()
        q.a1232 = "borkbork"

        self.assertTrue(p.a18462.a1732643.x == 1)
        self.assertTrue(q.a1232 == "borkbork")
        self.assertTrue(q.x == 1)
    def testConstraint_08_branch_copy_2(self):
        tn = unique_name()

        treedict.addConstraint(tn, 'a.b.c', [1], "not 1")
        
        p = getTree(tn)
        p.makeBranch('a.b')
        q = p.a.b.copy()

        def f():
            q.c = 2  # should be bad

        self.assertRaises(ValueError, f)
    def testConstraint_26_global_Links_01(self):
        tn = unique_name()
        bn = unique_name()

        link_key = bn + '.a.b.link'

        p = treedict.getTree(tn)
        treedict.addConstraint(tn, link_key + '.v', [1], "not 1")

        p[link_key] = p.d
        p.d.v = 1

        self.assert_(p[link_key].v == 1)
Beispiel #30
0
    def testSet_11_validation_first(self):
        d = {}

        tn = unique_name()

        for i in range(10000):
            d["a%d" % i] = i

        p = treedict.getTree(tn)

        p1 = deepcopy(p)

        self.assertTrue(p1 == p)
    def testConstraint_08_branch_copy_afterwards_2(self):
        tn = unique_name()

        p = getTree(tn)
        p.makeBranch('a18462.a1732643')

        q = p.a18462.a1732643.copy()
        q.a1232 = "borkbork"  # should be bad

        def f():
            treedict.addConstraint(tn, 'a18462.a1732643.a1232', ["bork"])

        self.assertRaises(ValueError, f)
    def testConstraint_08_global_branch_copy_afterwards_1(self):
        bn = unique_name()

        p = getTree(unique_name())
        p.makeBranch(bn).makeBranch('a')

        q = p[bn].copy()
        q.a.b = "borkbork"  # should be bad

        def f():
            treedict.addGlobalConstraint(bn + '.a.b', ["bork"])
            
        self.assertRaises(ValueError, f)
    def testConstraint_09_branches_in_tree_names_03(self):
        tn = unique_name()
        tnb = tn + '.b'

        p = getTree(tnb)

        treedict.addConstraint(tnb, 'a', [1], "not 1")

        # should throw
        def f():
            p.a = 2

        self.assertRaises(ValueError, f)
    def testConstraint_16_constraint_not_added_on_failure__control(self):
        tn = unique_name()
        
        p = getTree(tn)
        p["a.b.c.d"] = 1

        treedict.addConstraint(tn, 'a.b.c.d', [1], "not 1")
            
        # Should now throw, as the constraint is in place
        def f():
            p["a.b.c.d"] = 2

        self.assertRaises(ValueError, f)
    def testConstraint_16_constraint_not_added_on_failure(self):
        tn = unique_name()
        
        p = getTree(tn)
        p["a.b.c.d"] = 2

        def f():
            treedict.addConstraint(tn, 'a.b.c.d', [1], "not 1")
            
        self.assertRaises(ValueError, f)

        # Should be fine still, as 
        p["a.b.c.d"] = 2
Beispiel #36
0
    def testCopying_05b_central_system(self):
        # This test constrains the central system to have the same
        # name system as regular trees (I was tempted to do it
        # otherwise to make the constraints of copied branches
        # easier.)

        p = getTree('tc_root')
        b = p.makeBranch('b').copy()

        self.assert_(
            b.branchName(add_tree_name=True) == 'b',
            b.branchName(add_tree_name=True))
        self.assert_(
            p.b.branchName(add_path=True, add_tree_name=True) == 'tc_root.b',
            p.b.branchName(add_path=True, add_tree_name=True))
Beispiel #37
0
 def testSetGet05(self):
     p = getTree('a_s3kkdf93kd9k3ikdkmd')  # unique
     p.a.b.c.d.e.f = 1
     self.assertTrue(p.get("a.b.c.d.e.f") == 1)