Skip to content

Commit

Permalink
added compound test
Browse files Browse the repository at this point in the history
  • Loading branch information
hbmartin committed Jul 2, 2024
1 parent 8124058 commit 15c6b85
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Convert graphviz (dot) files into draw.io (mxGraph) format.
- [ ] Add tests for all new features
- [ ] Reformat for most recent black style
- [ ] Publish release docs to GH pages
- [ ] Remove this section before release!

## Getting Started

Expand Down Expand Up @@ -105,6 +106,8 @@ python -m graphviz2drawio test/directed/hello.gv.txt
- [ ] Migrate to uv/hatch for packaging and dep mgmt
- [ ] Bezier curve support
- [ ] Port layout
- [ ] Subgraph support
- [ ] Fix text alignment inside of shape
- [ ] Implementation for other outstanding TODOs

## License
Expand Down
2 changes: 1 addition & 1 deletion graphviz2drawio/graphviz2drawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def convert(graph_to_convert, layout_prog="dot"):
[n.enrich_from_graph(graph_nodes[n.gid]) for n in nodes.values()]

# Put clusters first, so that nodes are drawn in front
mx_graph = MxGraph(nodes | clusters, edges)
mx_graph = MxGraph(clusters | nodes, edges)
return mx_graph.value()


Expand Down
18 changes: 18 additions & 0 deletions test/directed/compound.gv.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
digraph G {
compound=true;
subgraph cluster0 {
a -> b;
a -> c;
b -> d;
c -> d;
}
subgraph cluster1 {
e -> g;
e -> f;
}
b -> f [lhead=cluster1];
d -> e;
c -> g [ltail=cluster0,lhead=cluster1];
c -> e [ltail=cluster0];
d -> h;
}
25 changes: 25 additions & 0 deletions test/directed/subgraph.gv.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
digraph Layer1 {
graph [fontcolor="#2D3436" fontname="Sans-Serif" fontsize=15 label=Layer1 nodesep=0.60 pad=2.0 rankdir=LR ranksep=0.75 splines=ortho]
node [fixedsize=true fontcolor="#2D3436" fontname="Sans-Serif" fontsize=13 height=1.4 imagescale=true labelloc=b shape=box style=rounded width=1.4]
edge [color="#7B8894"]
c1f7153c9e32421d836368051a837462 [label=dns height=1.9 image="/home/anna/PycharmProjects/diagram/venv/lib/python3.7/site-packages/resources/aws/network/route-53.png" shape=none]
"4adc5fcb62f74cfc91e0361a9d9df8e2" [label=lb height=1.9 image="/home/anna/PycharmProjects/diagram/venv/lib/python3.7/site-packages/resources/aws/network/elastic-load-balancing.png" shape=none]
a275ead10c404ea899628a2b9e96718d [label=memcached height=1.9 image="/home/anna/PycharmProjects/diagram/venv/lib/python3.7/site-packages/resources/aws/database/elasticache.png" shape=none]
"4298ae03bc26401ca91f226395f3c0ca" [label=userdb height=1.9 image="/home/anna/PycharmProjects/diagram/venv/lib/python3.7/site-packages/resources/aws/database/rds.png" shape=none]
subgraph cluster_Services {
graph [bgcolor="#E5F5FD" fontname="Sans-Serif" fontsize=12 label=Services labeljust=l pencolor="#AEB6BE" rankdir=LR shape=box style=rounded]
f54e1bfa37524a19b5a15a2af2423647 [label=web1 height=1.9 image="/home/anna/PycharmProjects/diagram/venv/lib/python3.7/site-packages/resources/aws/compute/elastic-container-service.png" shape=none]
"82b031cab3a2430a99d322923fd72bb1" [label=web2 height=1.9 image="/home/anna/PycharmProjects/diagram/venv/lib/python3.7/site-packages/resources/aws/compute/elastic-container-service.png" shape=none]
"5fe8e3fd159b4072b59496ead0c7dc39" [label=web3 height=1.9 image="/home/anna/PycharmProjects/diagram/venv/lib/python3.7/site-packages/resources/aws/compute/elastic-container-service.png" shape=none]
}
c1f7153c9e32421d836368051a837462 -> "4adc5fcb62f74cfc91e0361a9d9df8e2" [dir=forward fontcolor="#2D3436" fontname="Sans-Serif" fontsize=13]
"4adc5fcb62f74cfc91e0361a9d9df8e2" -> f54e1bfa37524a19b5a15a2af2423647 [dir=forward fontcolor="#2D3436" fontname="Sans-Serif" fontsize=13]
"4adc5fcb62f74cfc91e0361a9d9df8e2" -> "82b031cab3a2430a99d322923fd72bb1" [dir=forward fontcolor="#2D3436" fontname="Sans-Serif" fontsize=13]
"4adc5fcb62f74cfc91e0361a9d9df8e2" -> "5fe8e3fd159b4072b59496ead0c7dc39" [dir=forward fontcolor="#2D3436" fontname="Sans-Serif" fontsize=13]
f54e1bfa37524a19b5a15a2af2423647 -> "4298ae03bc26401ca91f226395f3c0ca" [dir=forward fontcolor="#2D3436" fontname="Sans-Serif" fontsize=13]
"82b031cab3a2430a99d322923fd72bb1" -> "4298ae03bc26401ca91f226395f3c0ca" [dir=forward fontcolor="#2D3436" fontname="Sans-Serif" fontsize=13]
"5fe8e3fd159b4072b59496ead0c7dc39" -> "4298ae03bc26401ca91f226395f3c0ca" [dir=forward fontcolor="#2D3436" fontname="Sans-Serif" fontsize=13]
f54e1bfa37524a19b5a15a2af2423647 -> a275ead10c404ea899628a2b9e96718d [dir=forward fontcolor="#2D3436" fontname="Sans-Serif" fontsize=13]
"82b031cab3a2430a99d322923fd72bb1" -> a275ead10c404ea899628a2b9e96718d [dir=forward fontcolor="#2D3436" fontname="Sans-Serif" fontsize=13]
"5fe8e3fd159b4072b59496ead0c7dc39" -> a275ead10c404ea899628a2b9e96718d [dir=forward fontcolor="#2D3436" fontname="Sans-Serif" fontsize=13]
}
28 changes: 25 additions & 3 deletions test/test_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,20 @@ def test_hello():
check_edge(edge, hello, world)
check_edge_dir(edge, dx=0, dy=1)


def test_hello_rect():
file = "./directed/hello_rect.gv.txt"
file = "test/directed/hello_rect.gv.txt"
xml = graphviz2drawio.convert(file)
print(xml)

root = ET.fromstring(xml)
elements = check_xml_top(root)

hello = elements[3]
hello = elements[2]
check_value(hello, "Hello")
assert "ellipse" not in hello.attrib["style"]

world = elements[4]
world = elements[3]
check_value(world, "World")
assert "ellipse" not in world.attrib["style"]

Expand Down Expand Up @@ -143,6 +144,27 @@ def test_datastruct():
assert elements[-1].attrib["source"] == "node12"
assert elements[-1].attrib["target"] == "node2"


# TODO: https://github.com/hbmartin/graphviz2drawio/issues/33
# def test_subgraph():
# file = "test/directed/subgraph.gv.txt"
# xml = graphviz2drawio.convert(file)
# print(xml)
#
# root = ET.fromstring(xml)
# elements = check_xml_top(root)


def test_compound():
file = "test/directed/compound.gv.txt"
xml = graphviz2drawio.convert(file)
print(xml)

root = ET.fromstring(xml)
elements = check_xml_top(root)
assert elements[-1].attrib["target"] == "node2"


# def test_runAll():
# for f in os.listdir('undirected'):
# xml = graphviz2drawio.convert(f)
Expand Down

0 comments on commit 15c6b85

Please sign in to comment.