Skip to content

Commit

Permalink
Add unit test for draw
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Li <[email protected]>
  • Loading branch information
adam2392 committed Nov 26, 2023
1 parent 1dd8779 commit f784c76
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
6 changes: 1 addition & 5 deletions pywhy_graphs/algorithms/semi_directed_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,13 @@ def all_semi_directed_paths(G, source: Node, target: Node, cutoff: int = None):
except TypeError:
raise nx.NodeNotFound("target node %s not in graph" % target)
if source in targets:
return []
return _empty_generator()
if cutoff is None:
cutoff = len(G) - 1
if cutoff < 1:
return []
if source in targets:
return _empty_generator()
if cutoff is None:
cutoff = len(G) - 1

Check warning on line 129 in pywhy_graphs/algorithms/semi_directed_paths.py

View check run for this annotation

Codecov / codecov/patch

pywhy_graphs/algorithms/semi_directed_paths.py#L129

Added line #L129 was not covered by tests
if cutoff < 1:
return _empty_generator()

return _all_semi_directed_paths_graph(G, source, targets, cutoff)

Expand Down
20 changes: 20 additions & 0 deletions pywhy_graphs/viz/tests/test_draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@
from pywhy_graphs.viz import draw, timeseries_layout


def test_draw_digraph():
"""
Ensure the generated graph is a directed graph.
The number of edges between any two nodes should always be one.
"""
# create a dummy graph x --> y <-- z and z --> x
graph = nx.DiGraph([("x", "y"), ("z", "y"), ("z", "x")])

# draw the graphs
dot = draw(graph)

# assert that the produced graph is a directed graph
assert "digraph" in dot.source

regex_pattern = "(?=(x -> y))"
matches = re.findall(regex_pattern, dot.source)
assert len(matches) == 1


def test_draw_pos_is_fully_given():
"""
Ensure the Graphviz pos="x,y!" attribute is generated by the draw function
Expand Down

0 comments on commit f784c76

Please sign in to comment.