def test_add_unexpected_child(self): tracker = self.tracker() parent = Node("parent", None, tracker.root) parent2 = Node("parent2", None, tracker.root) child = Node("child", None, parent) with pytest.raises(exceptions.LoadError): parent2.addchild(child)
def test_copy_sibling(self): tracker = self.tracker() node = Node("node", "text", tracker.root) tracker.root.addchild(node) newnode = node.copy() tracker.root.addchild(newnode) assert list(tracker.root.children) == [node, newnode] assert newnode.node_type == node.node_type assert newnode.text == node.text assert newnode.parent is node.parent assert newnode.root is node.root
def test_detach_noop(self): tracker = self.tracker() node = Node("node", None, None) node = node.detach() assert not node.parent assert not node.root parent2 = Node("parent2", None, tracker.root) parent2.addchild(node) assert list(parent2.children) == [node] assert node.root is tracker.root assert node.parent is parent2
def test_copy_newplace(self): tracker = self.tracker() parent1 = Node("parent1", None, tracker.root) parent2 = Node("parent2", None, tracker.root) node = Node("node", None, parent1) newnode = node.copy(parent2) parent2.addchild(newnode) assert newnode.node_type == node.node_type assert newnode.text == node.text assert newnode.parent is parent2 assert newnode.root is tracker.root
def test_allowed_parents(self): tracker = self.tracker() class ChildNode(Node): children_of = ("allowed-parent",) allowed_parent = Node("allowed-parent", None, tracker.root) child1 = ChildNode("child1", None, allowed_parent) child1._validate() allowed_parent.addchild(child1) disallowed_parent = Node("some-other-node", None, tracker.root) child2 = ChildNode("child2", None, disallowed_parent) with pytest.raises(exceptions.LoadError): child2._validate()
def test_copy_new_tracker(self): tracker1 = self.tracker() tracker2 = self.tracker() node1 = Node("node", "text", tracker1.root) tracker1.root.addchild(node1) node1_child = Node("nodechild", None, node1) node1.addchild(node1_child) node2 = node1.copy(tracker2.root) tracker2.root.addchild(node2) assert node2.root is tracker2.root assert node2.parent is tracker2.root node2_child = node2.children.next_neighbor assert node2_child.root is tracker2.root assert node2_child.parent is node2 assert node1.node_type == node2.node_type assert node1.text == node2.text assert node1_child.node_type == node2_child.node_type assert node1_child.text == node2_child.text
def test_remove_child(self): tracker = self.tracker() parent1 = Node("parent1", None, tracker.root) parent2 = Node("parent2", None, tracker.root) child = Node("child", None, parent1) parent1.addchild(child) assert list(parent1.children) == [child] assert child.parent is parent1 child = child.detach() assert child.parent is None assert list(parent1.children) == [] child.parent = parent2 parent2.addchild(child) assert list(parent2.children) == [child] assert child.parent is parent2
def search_tags(self): tags = Node.search_tags(self) if self.finished: tags.add("finished") else: tags.add("unfinished") if self.started: tags.add("started") else: tags.add("unstarted") if self is self.root.active_node: tags.add("active") else: tags.add("inactive") return tags
def __init__(self, *args, **kw): Node.__init__(self, *args, **kw) alarms.NodeMixin.__init__(self)
def __init__(self, *args, **kw): self.origin_time = datetime.now() Node.__init__(self, *args, **kw)
def __init__(self, *args, **kwargs): Node.__init__(self, *args, **kwargs)
def test_cant_activate(self): node = Node("herp", None, None) with pytest.raises(exceptions.LoadError): node.start()
def __str__(self): if self._px_target is None: return Node.__str__(self) result = "%s: %s" % (self.node_type, self._px_target.text) return result.partition("\n")[0]