Пример #1
0
    def testUpdate_WithFreezing_ValuesOnly_03(self):

        p = TreeDict()

        p.b = 1
        p.freeze(values_only=True)

        q = TreeDict()
        q.b = 2

        self.assertRaises(TypeError, lambda: p.update(q))
Пример #2
0
    def testDangling_14_CorrectParentingSetAtFixing_03(self):

        p = TreeDict()
        v = unique_object()

        p.b = p.c
        p.a = p.b

        # Set c and fix p.b
        p.c = 1
        p.b = 1
        p.a.x = 1

        # Now b should be
        self.assert_(p.a.branchName() == 'a')
Пример #3
0
    def testDangling_14_CorrectParentingSetAtFixing_05(self):

        p = TreeDict()

        p.makeBranch('cc')

        p.b = p.cc.c
        p.aa.a = p.b

        # Set c and fix p.b
        p.cc.c = 1
        p.b = 1

        # Now b should be
        self.assert_(p.aa.a.branchName() == 'a')
Пример #4
0
    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())
    def testIterators_14_Links_are_not_branches_02(self):

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

        self.assert_('b' not in p.keys(recursive = False, branch_mode = 'only'))
Пример #6
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'))
Пример #7
0
    def test_existance_06b_dangling_node(self):
        p = TreeDict('roor')

        p.b = 123
        p.a

        self.assert_('b' in p)
        self.assert_('a' not in p)
Пример #8
0
 def test01(self):
     
     test_tree = TreeDict()
     test_tree.x = 1
     test_tree.a = 1
     test_tree.b = 2
     
     runTest([], 'data', test_tree)
Пример #9
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)
Пример #10
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)
Пример #11
0
    def test_existance_06b_dangling_node(self):
        p = TreeDict("roor")

        p.b = 123
        p.a

        self.assert_("b" in p)
        self.assert_("a" not in p)
Пример #12
0
    def testCopying_07a_Regression(self):

        p = TreeDict()

        p.a.b = [1,2,3,4,534]
        p.a.c = [1,22,534]
        p.b   = [1,2,3]

        p2 = TreeDict()

        p2.a.b = [1,2,3,4,534]
        p2.a.c = [1,22,534]
        p2.b   = [1,2,3]

        p3 = copy(p)
        
        self.assert_(p == p2)
        self.assert_(p == p3)
Пример #13
0
    def testDrySet_04_value_overwrite(self):
        p = TreeDict()
        p.b = 1

        p_before = p.copy()

        self.assertRaises(TypeError, lambda: p.checkset("b.a", None, protect_structure = True))

        self.assert_(p_before == p)
Пример #14
0
    def testPickling_Dangling_03(self):

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

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

        self.assert_(p2 == p)
Пример #15
0
    def testCopying_09_LinkedValuesPreserved(self):

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

        q = p.copy()

        self.assert_(p.a is not q.a)
        self.assert_(q.b is q.a)
Пример #16
0
    def testDangling_11_ReferenceEquivalence_01(self):

        p = TreeDict()

        b = p.a = p.b

        self.assert_(p.a is p.b)

        p.b = 1

        self.assert_(p.a is b)
Пример #17
0
    def testRecursiveAttach_04_error_on_frozen(self):

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

        self.assertRaises(TypeError, lambda: p.attach(recursive = True))

        self.assert_(p.b.isRoot())
        self.assert_(p.b not in p.branches())
        self.assert_(p.size() == 1)
Пример #18
0
    def test_existance_06c_dangling_node(self):
        p = TreeDict("roor")

        p.b = 123
        p.a
        p.aa.b.c
        p.bb.c.d = None

        self.assert_("a" not in p)
        self.assert_("b" in p)
        self.assert_("aa" not in p)
        self.assert_("bb" in p)
Пример #19
0
    def test_existance_06c_dangling_node(self):
        p = TreeDict('roor')

        p.b = 123
        p.a
        p.aa.b.c
        p.bb.c.d = None

        self.assert_('a' not in p)
        self.assert_('b' in p)
        self.assert_('aa' not in p)
        self.assert_('bb' in p)
Пример #20
0
    def testCopying_07a_Regression_mutability_count_test(self):
        
        p = TreeDict()

        p.a.b = [1,2,3,4,534]
        p.a.c = [1,22,534]
        p.b   = [1,2,3]

        p2 = copy(p)

        self.assert_(p._numMutable() == p2._numMutable())
        self.assert_(p.a._numMutable() == p2.a._numMutable())
Пример #21
0
    def testMutability_01(self):
        p1 = TreeDict('root')

        p1.a = (13, (123, 32))
        p1.b = 123
        p1.c.a = 145
        p1.c.b = "1231321321231321"

        self.assert_(p1.isMutable())

        p1.freeze()

        self.assert_(not p1.isMutable())
Пример #22
0
    def testUpdate_WithFreezing_ValuesOnly_01(self):

        p = TreeDict()

        p.a = 1
        p.freeze(values_only=True)

        q = TreeDict()
        q.b = 2

        p.update(q)

        self.assert_(p.a == 1)
        self.assert_(p.b == 2)
Пример #23
0
    def testUpdate_WithFreezing_01(self):

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

        q = TreeDict()

        q.b = 2

        p.update(q)

        self.assert_(p.a.x == 1)
        self.assert_(p.b == 2)
Пример #24
0
    def testUpdate_WithFreezing_StructureOnly_04(self):

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

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

        p.update(q)

        self.assert_(p.a.x == 2)
        self.assert_(p.b == 3)
Пример #25
0
    def testDangling_11_ReferenceEquivalence_02(self):

        p = TreeDict()

        a1 = p.a1 = p.b
        a2 = p.a2 = p.b

        self.assert_(p.a1 is p.b)
        self.assert_(p.a2 is p.b)
        self.assert_(a1 is a2)

        p.b = 1

        self.assert_(p.a1 is a1)
        self.assert_(p.a2 is a1)
Пример #26
0
    def testFreezingValues_01(self):
        p1 = TreeDict('root')
        
        p1.a = (13, (123, 32))
        p1.b = 123
        p1.c.a = 145
        p1.c.b = "1231321321231321"
      
        p1.freeze("a")
        self.assertRaises(TypeError, lambda: p1.freeze("b", quiet=False))
        p1.freeze("b", quiet=True)

        p1.freeze("c", quiet=False)

        self.assert_(p1.c.isFrozen())
Пример #27
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)
Пример #28
0
    def testPicklingWithIteratorReferencing(self):

        p = TreeDict()

        p.a = 1
        p.b = 2
        p.c = 3

        it = p.iteritems()

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

        self.assert_(p == p2)

        self.assertRaises(RuntimeError, lambda: p.set('d', 4))
        p2.d = 4
Пример #29
0
    def testDangling_14_CorrectParentingSetAtFixing_04(self):

        p = TreeDict()
        v = unique_object()

        p.makeBranch('cc')
        
        p.b = p.cc.c
        p.a = p.b

        # Set c and fix p.b
        p.cc.c = 1
        p.b.x = 1

        # Now b should be 
        self.assert_(p.b.branchName() == 'b')
        self.assert_(p.a is p.b)
    def testIterators_12_Deletion(self):
        p = TreeDict()

        p.a = 1
        p.b = 2
        p.c = 3
        p.d = 4 
        p.e = 5

        it = p.iterkeys()
        
        self.assertRaises(RuntimeError, lambda: p.pop('a'))
        it.next()
        self.assertRaises(RuntimeError, lambda: p.pop('a'))
        
        del it

        p.pop('a')