Exemplo n.º 1
0
 def test_restore_unknown(self, root, grid):
     a, b, c, d, e = grid
     with pytest.raises(NotRestorableError):
         root.restore(Node('x'))
     d.remove()
     with pytest.raises(NotRestorableError):
         root.restore(Node('x'))
     root.restore(d)
     assert root.tree == [a, [b, [c, d, e]]]
Exemplo n.º 2
0
 def test_last_access(self, grid):
     a, b, c, d, e = grid
     f = Node('f')
     a.flip_with(f)
     d.access()
     assert b.down is d
     b.access()
     assert f.right is b
     f.access()
     assert b.left is f
Exemplo n.º 3
0
 def test_add_child_after(self, root, grid):
     a, b, c, d, e = grid
     f = Node('f')
     g = Node('g')
     h = Node('h')
     root.add_child_after(f, a)
     assert root.tree == [a, f, [b, [c, d, e]]]
     b.parent.add_child_after(g, b)
     assert root.tree == [a, f, [b, g, [c, d, e]]]
     d.parent.add_child_after(h, d)
     assert root.tree == [a, f, [b, g, [c, d, h, e]]]
Exemplo n.º 4
0
 def test_contains(self, root, grid):
     x = Node('x')
     nodes = list(grid)
     nodes += [n.parent for n in nodes]
     nodes.append(root)
     for n in nodes:
         assert n in root
     assert x not in root
Exemplo n.º 5
0
 def test_restore_same_payload(self, root, grid):
     """Restore a node that's not identical with the removed one but carries
     the same payload.
     """
     a, b, c, d, e = grid
     d.remove()
     new_d = Node('d')
     root.restore(new_d)
     assert root.tree == [a, [b, [c, new_d, e]]]
Exemplo n.º 6
0
 def test_add_child(self, root):
     child = Node('a')
     root.add_child(child)
     assert root.children == [child]
     assert child.parent == root
     assert root.width == child.width == 120
     assert root.height == child.height == 50
     assert root.x == child.x == 0
     assert root.y == child.y == 0
Exemplo n.º 7
0
 def test_move_and_integrate(self, root, grid):
     a, b, c, d, e = grid
     c.integrate_left()
     assert root.tree == [[a, c], [b, [d, e]]]
     a.integrate_right()
     assert root.tree == [c, [b, [d, e], a]]
     d.integrate_down()
     assert root.tree == [c, [b, e, [a, d]]]
     a.integrate_up()
     assert root.tree == [c, [b, [e, a], d]]
     e.integrate_left()
     assert root.tree == [[c, e], [b, a, d]]
     f = Node('f')
     a.flip_with(f)
     g = Node('g')
     a.flip_with(g)
     g.integrate_left()
     assert root.tree == [[c, e, g], [b, [a, f], d]]
Exemplo n.º 8
0
 def test_single_node(self):
     n = Node(None, 0, 0, 120, 50)
     assert n.x == 0
     assert n.y == 0
     assert n.width == 120
     assert n.height == 50
     assert n.is_root is True
     assert n.is_leaf is True
     assert n.parent is None
     assert n.children == []
     assert n.orient == HORIZONTAL
     assert n.horizontal is True
     assert n.vertical is False
     assert n.size is None
     assert (n.x, n.y) == n.pos
Exemplo n.º 9
0
 def test_add_children(self, root):
     a, b = Nodes('a b')
     root.add_child(a)
     root.add_child(b)
     assert root.width == 120
     assert a.width == b.width == 60
     assert root.height == 50
     assert a.height == b.height == 50
     assert a.pos == (0, 0)
     assert b.pos == (60, 0)
     c = Node('c')
     root.add_child(c)
     assert a.width == b.width == c.width == 40
     assert a.pos == (0, 0)
     assert b.pos == (40, 0)
     assert c.pos == (80, 0)
Exemplo n.º 10
0
 def test_resize_bubbles3(self, root, complex_grid):
     a, b, c, d, e, f, g = complex_grid
     h = Node('h')
     c.flip_with(h)
     f.size += 10
     g.size += 10
     assert f.size == g.size == c.size == h.size == 10
     a.size = 10
     assert a.size == 10
     assert f.size == g.size == c.size == h.size == 10
     assert d.size == e.size == 45
     d.size = 10
     assert d.size == 10
     assert e.size == 80
     e.size = 10
     assert e.size == 10
     assert f.size == g.size == c.size == h.size == d.size == 100/3
Exemplo n.º 11
0
 def test_resize_bubbles2(self, root, complex_grid):
     a, b, c, d, e, f, g = complex_grid
     c.flip_with(Node('h'))
     f.size += 10
     g.size += 10
     assert f.size == g.size == 10
     assert f.fixed and g.fixed
     assert d.size == e.size == 20
     assert d.flexible and e.flexible
     a.size -= 40
     assert a.size == 20
     assert f.size == g.size == 10
     assert d.size == e.size == 40
     d.size = 10
     assert d.size == 10
     assert e.size == 70
     assert f.size == g.size == 10
     assert e.flexible
     e.size = 10
     assert e.fixed
Exemplo n.º 12
0
def Nodes(string):
    for x in string.split():
        yield Node(x)
Exemplo n.º 13
0
def root():
    root = Node('root', 0, 0, 120, 50)
    return root
Exemplo n.º 14
0
 def test_root_without_dimensions(self):
     """A root node with undef. dimensions should be able to add a child."""
     root = Node()
     x = Node('x')
     root.add_child(x)
Exemplo n.º 15
0
    def test_resize_nested(self, root):
        a, b, c, d, e, f, g, h = Nodes('a b c_abs d_abs e f g h_abs')
        nu1, nu2, nd, mu, md1, md2 = Nodes('nu1_abs nu2_abs nd mu md1_abs md2')
        ou1, ou2, od, pu, pd1, pd2 = Nodes('ou1_abs ou2_abs od pu pd1_abs '
                                           'pd2_abs')
        root.add_child(a)
        root.add_child(b)
        b.flip_with(c)
        b.parent.add_child(e)
        b.parent.add_child(g)
        c.flip_with(d)
        e.flip_with(f)
        g.flip_with(h)

        b.parent.add_child(nu1)
        nu1.flip_with(mu)
        nu1.flip_with(nd)
        nu1.flip_with(nu2)
        mu.flip_with(md1)
        md1.flip_with(md2)

        b.parent.add_child(ou1)
        ou1.flip_with(pu)
        ou1.flip_with(od)
        ou1.flip_with(ou2)
        pu.flip_with(pd1)
        pd1.flip_with(pd2)

        def assert_first_state():
            assert b.parent.size == 60
            assert c.size == 40
            assert d.size == 20
            assert e.size == f.size == 30
            assert g.size == 40
            assert h.size == 20
            assert nu1.size == 10
            assert nu2.size == 20
            assert nd.parent.size == 30
            assert mu.parent.size == 30
            assert md1.size == 10
            assert md2.size == 20
            assert ou1.size == 10
            assert ou2.size == 20
            assert od.parent.size == 30
            assert pu.parent.size == 30
            assert pd1.size == 10
            assert pd2.size == 20

        def assert_second_state():
            assert a.size == 30
            assert b.parent.size == 90
            assert c.size == 60
            assert d.size == 30
            assert e.size == f.size == 45
            assert g.size == 70
            assert h.size == 20
            assert nu1.size == 10
            assert nu2.size == 20
            assert nd.parent.size == 30
            assert mu.parent.size == 60
            assert md1.size == 10
            assert md2.size == 50
            assert ou1.size == 15
            assert ou2.size == 30
            assert od.parent.size == 45
            assert pd1.size == 15
            assert pd2.size == 30
            assert pu.parent.size == 45

        b.parent.size = 60
        c.size += 5
        d.size -= 5
        h.size = 20
        nu1.size = 10
        nu2.size = 20
        md1.size = 10
        ou1.size = 10
        ou2.size = 20
        pd1.size = 10
        pd2.size = 20

        assert a.size == 60
        assert_first_state()
        a.size -= 30
        assert_second_state()
        a.size += 30
        assert a.size == 60
        assert_first_state()
        b.parent.size += 30
        assert_second_state()
        b.parent.size -= 30
        assert a.size == 60
        assert_first_state()

        a.size = 30
        x = Node('x')
        root.add_child(x)
        assert x.size == 40
        assert_first_state()
        x.remove()
        assert_second_state()

        a.remove()
        assert b.width == 120
        y = Node('y')
        root.add_child(y)
        assert_first_state()
Exemplo n.º 16
0
 def test_deny_only_child_resize(self, root):
     a = Node('a')
     root.add_child(a)
     a.size = 10
     assert a.size == 120
Exemplo n.º 17
0
 def test_move_root(self, root):
     a = Node('a')
     root.add_child(a)
     root.move_up()
     assert root.tree == [a]