|
|
|
@ -45,7 +45,7 @@ class DiagramTest(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def test_with_global_context(self):
|
|
|
|
|
self.assertIsNone(getdiagram())
|
|
|
|
|
with Diagram(name=os.path.join(self.name, 'with_global_context'), show=False):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, "with_global_context"), show=False):
|
|
|
|
|
self.assertIsNotNone(getdiagram())
|
|
|
|
|
self.assertIsNone(getdiagram())
|
|
|
|
|
|
|
|
|
@ -55,7 +55,7 @@ class DiagramTest(unittest.TestCase):
|
|
|
|
|
Node("node")
|
|
|
|
|
|
|
|
|
|
def test_node_to_node(self):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, 'node_to_node'), show=False):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, "node_to_node"), show=False):
|
|
|
|
|
node1 = Node("node1")
|
|
|
|
|
node2 = Node("node2")
|
|
|
|
|
self.assertEqual(node1 - node2, node2)
|
|
|
|
@ -63,7 +63,7 @@ class DiagramTest(unittest.TestCase):
|
|
|
|
|
self.assertEqual(node1 << node2, node2)
|
|
|
|
|
|
|
|
|
|
def test_node_to_nodes(self):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, 'node_to_nodes'), show=False):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, "node_to_nodes"), show=False):
|
|
|
|
|
node1 = Node("node1")
|
|
|
|
|
nodes = [Node("node2"), Node("node3")]
|
|
|
|
|
self.assertEqual(node1 - nodes, nodes)
|
|
|
|
@ -71,7 +71,7 @@ class DiagramTest(unittest.TestCase):
|
|
|
|
|
self.assertEqual(node1 << nodes, nodes)
|
|
|
|
|
|
|
|
|
|
def test_nodes_to_node(self):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, 'nodes_to_node'), show=False):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, "nodes_to_node"), show=False):
|
|
|
|
|
node1 = Node("node1")
|
|
|
|
|
nodes = [Node("node2"), Node("node3")]
|
|
|
|
|
self.assertEqual(nodes - node1, node1)
|
|
|
|
@ -107,24 +107,24 @@ class ClusterTest(unittest.TestCase):
|
|
|
|
|
def test_validate_direction(self):
|
|
|
|
|
# Normal directions.
|
|
|
|
|
for dir in ("TB", "BT", "LR", "RL"):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, 'validate_direction'), show=False):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, "validate_direction"), show=False):
|
|
|
|
|
Cluster(direction=dir)
|
|
|
|
|
|
|
|
|
|
# Invalid directions.
|
|
|
|
|
for dir in ("BR", "TL", "Unknown"):
|
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, 'validate_direction'), show=False):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, "validate_direction"), show=False):
|
|
|
|
|
Cluster(direction=dir)
|
|
|
|
|
|
|
|
|
|
def test_with_global_context(self):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, 'with_global_context'), show=False):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, "with_global_context"), show=False):
|
|
|
|
|
self.assertIsNone(getcluster())
|
|
|
|
|
with Cluster():
|
|
|
|
|
self.assertIsNotNone(getcluster())
|
|
|
|
|
self.assertIsNone(getcluster())
|
|
|
|
|
|
|
|
|
|
def test_with_nested_cluster(self):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, 'with_nested_cluster'), show=False):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, "with_nested_cluster"), show=False):
|
|
|
|
|
self.assertIsNone(getcluster())
|
|
|
|
|
with Cluster() as c1:
|
|
|
|
|
self.assertEqual(c1, getcluster())
|
|
|
|
@ -139,7 +139,7 @@ class ClusterTest(unittest.TestCase):
|
|
|
|
|
Node("node")
|
|
|
|
|
|
|
|
|
|
def test_node_to_node(self):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, 'node_to_node'), show=False):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, "node_to_node"), show=False):
|
|
|
|
|
with Cluster():
|
|
|
|
|
node1 = Node("node1")
|
|
|
|
|
node2 = Node("node2")
|
|
|
|
@ -148,7 +148,7 @@ class ClusterTest(unittest.TestCase):
|
|
|
|
|
self.assertEqual(node1 << node2, node2)
|
|
|
|
|
|
|
|
|
|
def test_node_to_nodes(self):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, 'node_to_nodes'), show=False):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, "node_to_nodes"), show=False):
|
|
|
|
|
with Cluster():
|
|
|
|
|
node1 = Node("node1")
|
|
|
|
|
nodes = [Node("node2"), Node("node3")]
|
|
|
|
@ -157,7 +157,7 @@ class ClusterTest(unittest.TestCase):
|
|
|
|
|
self.assertEqual(node1 << nodes, nodes)
|
|
|
|
|
|
|
|
|
|
def test_nodes_to_node(self):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, 'nodes_to_node'), show=False):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, "nodes_to_node"), show=False):
|
|
|
|
|
with Cluster():
|
|
|
|
|
node1 = Node("node1")
|
|
|
|
|
nodes = [Node("node2"), Node("node3")]
|
|
|
|
@ -180,88 +180,91 @@ class EdgeTest(unittest.TestCase):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def test_node_to_node(self):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, 'node_to_node'), show=False):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, "node_to_node"), show=False):
|
|
|
|
|
node1 = Node("node1")
|
|
|
|
|
node2 = Node("node2")
|
|
|
|
|
self.assertEqual(node1 - Edge(color='red') - node2, node2)
|
|
|
|
|
self.assertEqual(node1 - Edge(color="red") - node2, node2)
|
|
|
|
|
|
|
|
|
|
def test_node_to_nodes(self):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, 'node_to_nodes'), show=False):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, "node_to_nodes"), show=False):
|
|
|
|
|
with Cluster():
|
|
|
|
|
node1 = Node("node1")
|
|
|
|
|
nodes = [Node("node2"), Node("node3")]
|
|
|
|
|
self.assertEqual(node1 - Edge(color='red') - nodes, nodes)
|
|
|
|
|
self.assertEqual(node1 - Edge(color="red") - nodes, nodes)
|
|
|
|
|
|
|
|
|
|
def test_nodes_to_node(self):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, 'nodes_to_node'), show=False):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, "nodes_to_node"), show=False):
|
|
|
|
|
with Cluster():
|
|
|
|
|
node1 = Node("node1")
|
|
|
|
|
nodes = [Node("node2"), Node("node3")]
|
|
|
|
|
self.assertEqual(nodes - Edge(color='red') - node1, node1)
|
|
|
|
|
self.assertEqual(nodes - Edge(color="red") - node1, node1)
|
|
|
|
|
|
|
|
|
|
def test_nodes_to_node_with_additional_attributes(self):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, 'nodes_to_node_with_additional_attributes'), show=False):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, "nodes_to_node_with_additional_attributes"), show=False):
|
|
|
|
|
with Cluster():
|
|
|
|
|
node1 = Node("node1")
|
|
|
|
|
nodes = [Node("node2"), Node("node3")]
|
|
|
|
|
self.assertEqual(nodes - Edge(color='red') - Edge(color='green') - node1, node1)
|
|
|
|
|
self.assertEqual(nodes - Edge(color="red") - Edge(color="green") - node1, node1)
|
|
|
|
|
|
|
|
|
|
def test_node_to_node_with_attributes(self):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, 'node_to_node_with_attributes'), show=False):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, "node_to_node_with_attributes"), show=False):
|
|
|
|
|
with Cluster():
|
|
|
|
|
node1 = Node("node1")
|
|
|
|
|
node2 = Node("node2")
|
|
|
|
|
self.assertEqual(node1 << Edge(color='red', label='1.1') << node2, node2)
|
|
|
|
|
self.assertEqual(node1 >> Edge(color='green', label='1.2') >> node2, node2)
|
|
|
|
|
self.assertEqual(node1 << Edge(color='blue', label='1.3') >> node2, node2)
|
|
|
|
|
self.assertEqual(node1 << Edge(color="red", label="1.1") << node2, node2)
|
|
|
|
|
self.assertEqual(node1 >> Edge(color="green", label="1.2") >> node2, node2)
|
|
|
|
|
self.assertEqual(node1 << Edge(color="blue", label="1.3") >> node2, node2)
|
|
|
|
|
|
|
|
|
|
def test_node_to_node_with_additional_attributes(self):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, 'node_to_node_with_additional_attributes'), show=False):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, "node_to_node_with_additional_attributes"), show=False):
|
|
|
|
|
with Cluster():
|
|
|
|
|
node1 = Node("node1")
|
|
|
|
|
node2 = Node("node2")
|
|
|
|
|
self.assertEqual(node1 << Edge(color='red', label='2.1') << Edge(color='blue') << node2, node2)
|
|
|
|
|
self.assertEqual(node1 >> Edge(color='green', label='2.2') >> Edge(color='red') >> node2, node2)
|
|
|
|
|
self.assertEqual(node1 << Edge(color='blue', label='2.3') >> Edge(color='black') >> node2, node2)
|
|
|
|
|
self.assertEqual(node1 << Edge(color="red", label="2.1") << Edge(color="blue") << node2, node2)
|
|
|
|
|
self.assertEqual(node1 >> Edge(color="green", label="2.2") >> Edge(color="red") >> node2, node2)
|
|
|
|
|
self.assertEqual(node1 << Edge(color="blue", label="2.3") >> Edge(color="black") >> node2, node2)
|
|
|
|
|
|
|
|
|
|
def test_nodes_to_node_with_attributes_loop(self):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, 'nodes_to_node_with_attributes_loop'), show=False):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, "nodes_to_node_with_attributes_loop"), show=False):
|
|
|
|
|
with Cluster():
|
|
|
|
|
node = Node("node")
|
|
|
|
|
self.assertEqual(node >> Edge(color='red', label='3.1') >> node, node)
|
|
|
|
|
self.assertEqual(node << Edge(color='green', label='3.2') << node, node)
|
|
|
|
|
self.assertEqual(node >> Edge(color='blue', label='3.3') << node, node)
|
|
|
|
|
self.assertEqual(node << Edge(color='pink', label='3.4') >> node, node)
|
|
|
|
|
self.assertEqual(node >> Edge(color="red", label="3.1") >> node, node)
|
|
|
|
|
self.assertEqual(node << Edge(color="green", label="3.2") << node, node)
|
|
|
|
|
self.assertEqual(node >> Edge(color="blue", label="3.3") << node, node)
|
|
|
|
|
self.assertEqual(node << Edge(color="pink", label="3.4") >> node, node)
|
|
|
|
|
|
|
|
|
|
def test_nodes_to_node_with_attributes_bothdirectional(self):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, 'nodes_to_node_with_attributes_bothdirectional'), show=False) as diagram:
|
|
|
|
|
with Diagram(
|
|
|
|
|
name=os.path.join(self.name, "nodes_to_node_with_attributes_bothdirectional"), show=False
|
|
|
|
|
) as diagram:
|
|
|
|
|
with Cluster():
|
|
|
|
|
node1 = Node("node1")
|
|
|
|
|
nodes = [Node("node2"), Node("node3")]
|
|
|
|
|
self.assertEqual(nodes << Edge(color='green', label='4') >> node1, node1)
|
|
|
|
|
self.assertEqual(nodes << Edge(color="green", label="4") >> node1, node1)
|
|
|
|
|
|
|
|
|
|
def test_nodes_to_node_with_attributes_bidirectional(self):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, 'nodes_to_node_with_attributes_bidirectional'), show=False):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, "nodes_to_node_with_attributes_bidirectional"), show=False):
|
|
|
|
|
with Cluster():
|
|
|
|
|
node1 = Node("node1")
|
|
|
|
|
nodes = [Node("node2"), Node("node3")]
|
|
|
|
|
self.assertEqual(nodes << Edge(color='blue', label='5') >> node1, node1)
|
|
|
|
|
self.assertEqual(nodes << Edge(color="blue", label="5") >> node1, node1)
|
|
|
|
|
|
|
|
|
|
def test_nodes_to_node_with_attributes_onedirectional(self):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, 'nodes_to_node_with_attributes_onedirectional'), show=False):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, "nodes_to_node_with_attributes_onedirectional"), show=False):
|
|
|
|
|
with Cluster():
|
|
|
|
|
node1 = Node("node1")
|
|
|
|
|
nodes = [Node("node2"), Node("node3")]
|
|
|
|
|
self.assertEqual(nodes >> Edge(color='red', label='6.1') >> node1, node1)
|
|
|
|
|
self.assertEqual(nodes << Edge(color='green', label='6.2') << node1, node1)
|
|
|
|
|
self.assertEqual(nodes >> Edge(color="red", label="6.1") >> node1, node1)
|
|
|
|
|
self.assertEqual(nodes << Edge(color="green", label="6.2") << node1, node1)
|
|
|
|
|
|
|
|
|
|
def test_nodes_to_node_with_additional_attributes_directional(self):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, 'nodes_to_node_with_additional_attributes_directional'), show=False):
|
|
|
|
|
with Diagram(name=os.path.join(self.name, "nodes_to_node_with_additional_attributes_directional"), show=False):
|
|
|
|
|
with Cluster():
|
|
|
|
|
node1 = Node("node1")
|
|
|
|
|
nodes = [Node("node2"), Node("node3")]
|
|
|
|
|
self.assertEqual(nodes
|
|
|
|
|
>> Edge(color='red', label='6.1') >> Edge(color='blue', label='6.2') >> node1, node1)
|
|
|
|
|
self.assertEqual(nodes
|
|
|
|
|
<< Edge(color='green', label='6.3') << Edge(color='pink', label='6.4') << node1, node1)
|
|
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
nodes >> Edge(color="red", label="6.1") >> Edge(color="blue", label="6.2") >> node1, node1
|
|
|
|
|
)
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
nodes << Edge(color="green", label="6.3") << Edge(color="pink", label="6.4") << node1, node1
|
|
|
|
|
)
|
|
|
|
|