Exemple #1
0
 def test_move_to(self):
     Menu.move(find('C'), to=find('B'))
     expected = [[x,] for x in 'A,B,D,E,F'.split(',')]
     for i in range(len(expected)):
         if expected[i][0] == 'B':
             expected[i].append(['C',])
     self.assertEqualTree(expected)
Exemple #2
0
 def test_drop_sub(self):
     insert(self.subtree, parent=find('C'))
     Menu.drop(find('c'))
     expected = [[x,] for x in 'A,B,C,D,E,F'.split(',')]
     for i in range(len(expected)):
         if expected[i][0] == 'C':
             expected[i].append([[x,] for x in 'a,b,d,e,f'.split(',')])
     self.assertEqualTree(expected)
Exemple #3
0
 def test_insert_sub(self):
     k = 'A,B,C,D,E,F'.split(',')[randint(0,5)]
     Menu.insert(name='G', parent=find(k))
     expected = [[x,] for x in 'A,B,C,D,E,F'.split(',')]
     for i in range(len(expected)):
         if expected[i][0] == k:
             expected[i].append(['G',])
     self.assertEqualTree(expected)
Exemple #4
0
 def test_move_sub_tree_prepend(self):
     insert(self.subtree, parent=find('A'))
     Menu.relocate(find('A'), relative_to=find('D'), mode=APPEND)
     expected = [[x,] for x in 'B,C,D,A,E,F'.split(',')]
     for i in range(len(expected)):
         if expected[i][0] == 'A':
             expected[i].append([[x,] for x in 'a,b,c,d,e,f'.split(',')])
             break
     self.assertEqualTree(expected)
Exemple #5
0
def insert(data, parent=None):
    for d in data:
        if len(d) > 1:
            node, tree = d
        else:
            node = d[0]
            tree = None
        Menu.insert(name=node, parent=parent)
        if tree:
            insert(tree, find(node))
Exemple #6
0
 def test_move_one_up_middle_prepend(self):
     parent = 'B,C,D,E,F'.split(',')[randint(0,4)]
     insert(self.subtree, parent=find(parent))
     Menu.relocate(find('A'), relative_to=find('d'))
     expected = [[x,] for x in 'B,C,D,E,F'.split(',')]
     for i in range(len(expected)):
         if expected[i][0] == parent:
             expected[i].append([[x,] for x in 'a,b,c,A,d,e,f'.split(',')])
             break
     self.assertEqualTree(expected)
Exemple #7
0
 def test_move_one_up_last_append(self):
     parent = 'A,B,C,D,E'.split(',')[randint(0,4)]
     insert(self.subtree, parent=find(parent))
     Menu.relocate(find('F'), relative_to=find('f'), mode=APPEND)
     expected = [[x,] for x in 'A,B,C,D,E'.split(',')]
     for i in range(len(expected)):
         if expected[i][0] == parent:
             expected[i].append([[x,] for x in 'a,b,c,d,e,f,F'.split(',')])
             break
     self.assertEqualTree(expected)
Exemple #8
0
def detail():
    t = '\n' + '-' * 30 + '\n'
    print t.join(["Name: %s\n Key: %s\nPath: %s\n Pos: %d\nSibs: %s\nClds: %s\nAncs: %s" \
          % (n.name, n.get_key(),
             n.path, n.pos,
             ', '.join([s.name for s in db.get(n.siblings)]),
             ', '.join([s.name for s in db.get(n.children)]),
             ', '.join([s.name for s in db.get(n.ancestors)]))
   for n in Menu.all()])
Exemple #9
0
def list():
    nodes = Menu.all()
    d = {}
    for node in nodes:
        d[node.path] = node
    keys = d.keys()
    sort_nicely( keys )
    for key in keys:
        print key + ' ' + d[key].name
Exemple #10
0
def debug_list(test='undef'):
    nodes = {}
    keys = []
    for node in Menu.all():
        nodes[node.path] = node
        nodes[node.get_key()] = node
        keys.append(node.path)

    sort_nicely(keys)
    for key in keys:
        logging.info(u'[%s] %-10s %5s (%-12s | %-20s)' % (test, key, nodes[key].name,
                     u', '.join([nodes[n].name for n in nodes[key].siblings]),
                     u' > '.join([nodes[n].name for n in nodes[key].ancestors])))
Exemple #11
0
 def test_add_to(self):
     Menu.add(name='G', to=find('A'))
     expected = (('A',(('G',),)),('B',),('C',),('D',),('E',),('F',))
     self.assertEqualTree(expected)
Exemple #12
0
 def test_add_before(self):
     Menu.add(name='G', before=find('A'))
     expected = ((x,) for x in 'G,A,B,C,D,E,F'.split(','))
     self.assertEqualTree(expected)
Exemple #13
0
    def test_append_to_node(self):
        Menu.relocate(find('F'), relative_to=find('E'), mode=SUBTREE)
        expected = [['A',],['B',],['C',],['D',],['E',['F',]],]
        self.assertEqualTree(expected)

        Menu.relocate(find('B'), relative_to=find('A'), mode=SUBTREE)
        expected = [['A',['B',]],['C',],['D',],['E',['F',]],]
        self.assertEqualTree(expected)

        Menu.relocate(find('D'), relative_to=find('C'), mode=SUBTREE)
        expected = [['A',['B',]],['C',['D',]],['E',['F',]],]
        self.assertEqualTree(expected)

        Menu.relocate(find('C'), relative_to=find('A'), mode=SUBTREE)
        expected = [['A',[['B',],['C',['D',]]]],['E',['F',]],]
        self.assertEqualTree(expected)

        Menu.relocate(find('A'), relative_to=find('F'), mode=SUBTREE)
        expected = (('E',(('F',(('A',(('B',),('C',('D',)),)),)),)),)
        self.assertEqualTree(expected)

        Menu.relocate(find('C'), relative_to=find('B'), mode=SUBTREE)
        expected = (('E',(('F',(('A',(('B',(('C',('D',)),)),)),)),)),)
        self.assertEqualTree(expected)

        Menu.relocate(find('B'), relative_to=find('E'), mode=APPEND)
        Menu.relocate(find('F'), relative_to=find('E'), mode=APPEND)
        Menu.relocate(find('C'), relative_to=find('E'), mode=APPEND)
        Menu.relocate(find('A'), relative_to=find('E'), mode=APPEND)
        Menu.relocate(find('D'), relative_to=find('E'))
        expected = ((x,) for x in 'D,E,A,C,F,B'.split(','))
        self.assertEqualTree(expected)
Exemple #14
0
 def test_add_after(self):
     Menu.add(name='G', after=find('A'))
     expected = ((x,) for x in 'A,G,B,C,D,E,F'.split(','))
     self.assertEqualTree(expected)
Exemple #15
0
 def test_drop(self):
     Menu.drop(find('C'))
     expected = [[x,] for x in 'A,B,D,E,F'.split(',')]
     debug_list('test_drop C post')
     self.assertEqualTree(expected)
Exemple #16
0
 def test_move_last_append(self):
     Menu.relocate(find('E'), relative_to=find('F'), mode=APPEND)
     expected = ((x,) for x in 'A,B,C,D,F,E'.split(','))
     self.assertEqualTree(expected)
Exemple #17
0
 def test_drop_noncascade(self):
     insert(self.subtree, parent=find('C'))
     Menu.drop(find('C'))
     expected = [[x,] for x in 'A,B,a,b,c,d,e,f,D,E,F'.split(',')]
     self.assertEqualTree(expected)
Exemple #18
0
 def test_move_middle_append(self):
     Menu.relocate(find('C'), relative_to=find('D'), mode=APPEND)
     expected = ((x,) for x in 'A,B,D,C,E,F'.split(','))
     self.assertEqualTree(expected)
Exemple #19
0
 def test_move_last_prepend(self):
     Menu.relocate(find('E'), relative_to=find('F'))
     expected = ((x,) for x in 'A,B,C,D,E,F'.split(','))
     self.assertEqualTree(expected)
Exemple #20
0
 def test_remove_simple(self):
     Menu.remove(find('A'))
     Menu.remove(find('F'), all=True)
     expected = ((x,) for x in 'B,C,D,E'.split(','))
     self.assertEqualTree(expected)
Exemple #21
0
 def test_move_after(self):
     Menu.move(find('C'), after=find('D'))
     expected = [[x,] for x in 'A,B,D,C,E,F'.split(',')]
     self.assertEqualTree(expected)
Exemple #22
0
 def test_remove_complex_node_only(self):
     insert(self.subtree, parent=find('A'))
     Menu.remove(find('A'))
     expected = ((x,) for x in 'a,b,c,d,e,f,B,C,D,E,F'.split(','))
     self.assertEqualTree(expected)
Exemple #23
0
 def test_insert_first(self):
     Menu.insert(name='G', before=find('A'))
     expected = (('G',),('A',),('B',),('C',),('D',),('E',),('F',))
     self.assertEqualTree(expected)
Exemple #24
0
 def test_insert_last(self):
     Menu.insert(name='G')
     expected = (('A',),('B',),('C',),('D',),('E',),('F',),('G',))
     self.assertEqualTree(expected)
Exemple #25
0
 def setUp(self):
     db.delete(Menu.all())
     insert(self.tree)
Exemple #26
0
 def test_drop_cascade(self):
     insert(self.subtree, parent=find('C'))
     Menu.drop(find('C'), cascade=True)
     expected = [[x,] for x in 'A,B,D,E,F'.split(',')]
     self.assertEqualTree(expected)
Exemple #27
0
 def test_remove_complex_all(self):
     insert(self.subtree, parent=find('A'))
     Menu.remove(find('A'), all=True)
     expected = ((x,) for x in 'B,C,D,E,F'.split(','))
     self.assertEqualTree(expected)
Exemple #28
0
 def test_move_before(self):
     Menu.move(find('C'), before=find('B'))
     expected = [[x,] for x in 'A,C,B,D,E,F'.split(',')]
     self.assertEqualTree(expected)
Exemple #29
0
 def test_move_first_prepend(self):
     Menu.relocate(find('B'), relative_to=find('A'))
     expected = ((x,) for x in 'B,A,C,D,E,F'.split(','))
     self.assertEqualTree(expected)
Exemple #30
0
 def test_add(self):
     Menu.add(name='G')
     expected = (('A',),('B',),('C',),('D',),('E',),('F',),('G',))
     self.assertEqualTree(expected)