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_07_afterwards_global_2(self): tn = unique_name() bn = unique_name() p = getTree(tn) p[bn] = "bork" treedict.addGlobalConstraint(bn, ["bork", "bork1"])
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_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_22_IntermediatesMustBeBranches_04_global_after(self): bn = unique_name() tn = unique_name() p = treedict.getTree(tn) p[bn + ".a.b"] = 1 def f(): treedict.addGlobalConstraint(bn + '.a.b.c.d.v', [1], "not 1") self.assertRaises(ValueError, f) treedict.addGlobalConstraint(bn + '.a.b', [1], "not 1")
def testConstraint_22_IntermediatesMustBeBranches_03_global(self): tn = unique_name() bn = unique_name() treedict.addGlobalConstraint(bn + '.a.b.c.d.v', [1], "not 1") p = treedict.getTree(tn) def f(): p[bn + ".a.b"] = 1 self.assertRaises(ValueError, f) # control p.makeBranch(bn + ".a.b")
def testConstraint_19_global__copying_original_tracks_constraints_01_after(self): tn = unique_name() bn = unique_name() p1 = getTree(tn) p2 = p1.copy() p2[bn] = 2 # Should throw def f(): treedict.addGlobalConstraint(bn, [1], "not 1") self.assertRaises(ValueError, f) # And the control treedict.addGlobalConstraint(bn, [2], "not 2")
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
def testConstraint_23_IntermediatesMustBeBranches_copied_04_global_after(self): tn = unique_name() bn = unique_name() pb = treedict.getTree(tn) pb.makeBranch(bn) pb[bn].makeBranch('a.b') p = pb[bn].a.b.copy() p["c.d"] = 1 def f(): treedict.addGlobalConstraint(bn + '.a.b.c.d.v', [1], "not 1") self.assertRaises(ValueError, f) # control treedict.addGlobalConstraint(bn + '.a.b.c.d', [1], "not 1")
def testConstraint_19_global__copying_original_tracks_constraints_02_after(self): tn = unique_name() bn = unique_name() p = getTree(tn) p.a = 1 p.b = 2 for i in range(1000): p = p.copy(deep = True) p[bn] = 2 # Should throw def f(): treedict.addGlobalConstraint(bn, [1], "not 1") self.assertRaises(ValueError, f) # And the control treedict.addGlobalConstraint(bn, [2], "not 2")
def f(): treedict.addGlobalConstraint(fullbn + '.x', [1], "not 1")
def f(): treedict.addGlobalConstraint('%s.%s.x' % (bn1, bn2), [1], "not 1")
def f(): treedict.addGlobalConstraint(bn, [1], "not 1")
def setUp(self): treedict.addConstraint("a_is_int", "a", lambda x: type(x) is int, "Not an integer.") treedict.addConstraint("a_in_125", "a", lambda x: x == 1 or x == 2 or x == 5, "Not 1,2,or 5.") treedict.addGlobalConstraint("in_134", set([1,3,4]), "Not 1, 3, or 4") treedict.addGlobalConstraint("l_in_134", [1,3,4], "Not 1, 3, or 4") treedict.addGlobalConstraint("in_134l", [1,3,4,[]], "Not 1, 3, 5 or []")
def f(): treedict.addGlobalConstraint(bn + '.a.b', ["bork"])
def f(): treedict.addGlobalConstraint(bn + '.a.b.c.d.v', [1], "not 1")
def f(): treedict.addGlobalConstraint(bn, ["bork", "bork1"])