Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_remove(self):
a = Node('a')
b = Node('b')
c = Node('c', a, b)
d = Node('d', c)
e = Node('e', c)
c.remove(keep_parents=False, keep_children=False)
assert c.children == []
assert c.parents == []
assert b.children == []
assert e.parents == []
def test_remove(self):
a = Node('a')
b = Node('b')
c = Node('c', a, b)
d = Node('d', c)
e = Node('e', c)
c.remove(keep_parents=False, keep_children=False)
assert c.children == []
assert c.parents == []
assert b.children == []
assert e.parents == []
def test_construction_add_index(self):
b = Node('b')
c = Node('c', b)
d = Node('d')
e = Node('e')
c.add_parent(d, index=0, index_child=0)
assert c.parents == [d, b]
assert b.children == [c]
assert d.children == [c]
b._add_child(e, index=0)
assert b.children == [e, c]
assert e.parents == [] # _add_child doesn't call add_parent
def test_component(self):
a = Node('a')
b = Node('b')
c = Node('c', b)
d = Node('d', a, c)
e = Node('e', d)
f = Node('f', d, c)
g = Node('g', e, f)
ext = Node('ext')
assert set(c.component) == {a, b, c, d, e, f, g}
assert set(g.component) == {a, b, c, d, e, f, g}
assert ext.component == [ext]
def test_component(self):
a = Node('a')
b = Node('b')
c = Node('c', b)
d = Node('d', a, c)
e = Node('e', d)
f = Node('f', d, c)
g = Node('g', e, f)
ext = Node('ext')
assert set(c.component) == {a, b, c, d, e, f, g}
assert set(g.component) == {a, b, c, d, e, f, g}
assert ext.component == [ext]
def test_remove_parent(self):
a = Node('a')
b = Node('b', a)
c = Node('c', b)
c.remove_parent(0)
assert c.parents == []
assert b.children == []
b.remove_parent(a)
assert b.parents == []
assert a.children == []
def test_construction_add_index(self):
b = Node('b')
c = Node('c', b)
d = Node('d')
e = Node('e')
c.add_parent(d, index=0, index_child=0)
assert c.parents == [d, b]
assert b.children == [c]
assert d.children == [c]
b._add_child(e, index=0)
assert b.children == [e, c]
assert e.parents == [] # _add_child doesn't call add_parent
def test_consistent_order(self):
def assert_order(node, attr):
prev = getattr(node, attr)
assert isinstance(prev, list)
for i in range(10):
cur = getattr(node, attr)
assert prev == cur
prev = cur
a = Node('a')
b = Node('b')
c = Node('c', b)
d = Node('d', a, c)
e = Node('e', d)
f = Node('f', d, c)
g = Node('g', e, f)
assert_order(g, "component")
assert_order(g, "ancestors")
assert_order(g, "parents")
assert_order(a, "children")
assert_order(a, "descendants")
def test_none_parent(self):
a = Node('a', None)
assert a.parents == []
def test_change_to(self):
a = Node('a')
b = Node('b')
c = Node('c', a, b)
d = Node('d', c)
e = Node('e', c)
f = Node('f')
c_new = Node('c_new', a, f)
c = c.change_to(c_new, transfer_parents=False, transfer_children=True)
assert c.parents == [a, f]
assert c.children == [d, e]
c_new2 = Node('c_new2', a)
c = c.change_to(c_new2, transfer_parents=True, transfer_children=False)
assert c.parents == [a, f]
assert c.children == []