def testItemlists_01_flat(self): p = TreeDict() items = [('a', 1), ('b', 2), ('c', 3)] p.set(**dict(items)) self.assert_(set(p.keys()) == set([k for k, v in items])) self.assert_(set(p.values()) == set([v for k, v in items])) self.assert_(set(p.items()) == set(items))
def testItemlists_02_recursive(self): p = TreeDict() items = [('a.v', 1), ('b', 2), ('c', 3), ('aa.b.c.d.e', 4)] p.set(**dict(items)) self.assert_(set(p.keys()) == set([k for k, v in items])) self.assert_(set(p.values()) == set([v for k, v in items])) self.assert_(set(p.items()) == set(items))
def testItemLists_06_single_deep(self): depth = 500 p = TreeDict() pt = p for i in range(depth-1): pt = pt.a pt.a = 1 self.assert_(p.keys() == ['.'.join(['a']*depth)]) self.assert_(p.values() == [1])
def testItemlists_05_branches(self): p = TreeDict() items = [('a.v', 1), ('b', 2), ('c', 3), ('aa.b.c.d.e', 4)] p.set(**dict(items)) bl = [(k, p.get(k)) for k in ['a', 'aa']] p.freeze() self.assert_(set(p.values(False, "only")) == set([v for k, v in bl])) self.assert_(set(p.keys(False, "only")) == set([k for k, v in bl])) self.assert_(set(p.items(False, "only")) == set(bl))
def testItemlists_03_nonrecursive_skipbranches(self): p = TreeDict() items = [('a.v', 1), ('b', 2), ('c', 3), ('aa.b.c.d.e', 4)] p.set(**dict(items)) non_recursive = [(k,v) for k, v in items if '.' not in k] self.assert_(set(p.keys(recursive=False)) == set([k for k, v in non_recursive])) self.assert_(set(p.values(recursive=False)) == set([v for k, v in non_recursive])) self.assert_(set(p.items(recursive=False)) == set(non_recursive))
def testItemlists_04_nonrecursive_withbranches(self): p = TreeDict() items = [('a.v', 1), ('b', 2), ('c', 3), ('aa.b.c.d.e', 4)] p.set(**dict(items)) nrwb = [(k, p.get(k)) for k in ['a', 'b', 'c', 'aa']] p.freeze() self.assert_(set(p.keys(recursive=False, branch_mode = "all")) == set([k for k, v in nrwb])) self.assert_(set(p.values(recursive=False, branch_mode = "all")) == set([v for k, v in nrwb])) self.assert_(set(p.items(recursive=False, branch_mode = "all")) == set(nrwb))
def testItemLists_07_empty_fo(self): p = TreeDict() self.assert_(p.keys(False, "only") == []) self.assert_(p.items(False, "only") == []) self.assert_(p.values(False, "only") == [])
def testItemLists_07_empty_ra(self): p = TreeDict() self.assert_(p.keys(True, "all") == []) self.assert_(p.items(True, "all") == []) self.assert_(p.values(True, "all") == [])