def test_create(self): """ Test creation of a graph. """ g = Graph(name="graph", strict=True, directed=False) self.failUnless(g.name == "graph") self.assertTrue(g.strict) self.assertFalse(g.directed)
def init(self, parent): """ Finishes initialising the editor by creating the underlying toolkit widget. """ self._graph = graph = Graph() ui = graph.edit_traits(parent=parent, kind="panel") self.control = ui.control
def test_add_cluster(self): """ Test adding clusters to a graph. """ g = Graph() cluster = Cluster(ID="cluster0", level=1) g.add_cluster(cluster) g.add_cluster("cluster1") self.assertEqual(len(g.clusters), 2)
def test_add_subgraph(self): """ Test adding subgraphs to a graph. """ g = Graph() subgraph = Subgraph(ID="sub1", level=1) g.add_subgraph(subgraph) g.add_subgraph("sub2") self.assertEqual(len(g.subgraphs), 2)
def test_add_node(self): """ Test adding nodes to a graph. """ g = Graph() g.nodes.append( Node(ID="node1") ) g.add_node("node2") g.add_node( Node("node3") ) self.assertEqual(len(g), 3)
def test_add_nonstring_nodes(self): """ Test adding nodes with non-string names. """ g = Graph() n = g.add_node(6) self.assertEqual(n.ID, "6") n = g.add_node(3.14) self.assertEqual(n.ID, "3.14") self.assertEqual(len(g), 2)
def test_delete_node(self): """ Test removing a node from a graph. """ g = Graph() added1 = g.add_node("node1") added2 = g.add_node("node2") self.assertEqual(len(g.nodes), 2) g.delete_node("node1") g.delete_node(added2) self.assertEqual(len(g.nodes), 0)
def new_model(self, info): """ Handles the new Graph action. """ if info.initialized: retval = confirm(parent = info.ui.control, message = "Replace existing graph?", title = "New Graph", default = YES) if retval == YES: self.model = Graph()
def test_add_edge(self): """ Test adding edges to a graph. """ g = Graph() n1, n2, n3 = Node("N1"), Node("N2"), Node("N3") g.edges.append( Edge(n1, n2) ) g.add_edge("tail", "head", label="edge1") g.add_edge(n2, n3, color="blue") self.assertEqual(len(g.edges), 3) self.assertEqual(g.edges[1].label, "edge1")
def test_add_equal_nodes(self): """ Test adding nodes with existing names. """ g = Graph() g.add_node("a", label="test1") g.add_node("a", fixedsize=True) g.add_node("a", label="test2", shape="circle") self.assertEqual(len(g), 1) n = g.get_node("a") self.assertTrue(n.fixedsize) self.assertEqual(n.label, "test2") self.assertEqual(n.shape, "circle")
def test_create_with_attributes(self): """ Test creation of a graph with attributes. """ g = Graph(mode="KK", label="testgraph") self.assertEqual(g.mode, "KK") self.assertEqual(g.label, "testgraph")
def get_content(self, name): """ Returns the content for the new resource. Override in subclasses. """ return Graph(name=name)
if retval == YES: self._on_close( info ) else: self._on_close( info ) #------------------------------------------------------------------------------ # Stand-alone call: #------------------------------------------------------------------------------ if __name__ == "__main__": import sys logger = logging.getLogger() logger.addHandler(logging.StreamHandler(sys.stdout)) logger.setLevel(logging.DEBUG) graph = Graph(ID="G") # sg1 = Subgraph(ID="SG1") # graph.subgraphs.append(sg1) # sg2 = Subgraph(ID="SG2") # sg1.subgraphs.append(sg2) # # n1 = Node(ID="N1") # sg2.nodes = [n1] graph.add_node("node1") graph.add_node("node2") view_model = GraphViewModel(model=graph) view_model.configure_traits() # EOF -------------------------------------------------------------------------