Skip to content

Commit

Permalink
Factor out test logic for graph generation
Browse files Browse the repository at this point in the history
  • Loading branch information
pradyunsg committed Apr 24, 2020
1 parent ebc0e33 commit 9ae99b6
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions tests/unit/resolution_resolvelib/test_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ def resolver(preparer, finder):
return resolver


def _make_graph(edges):
"""Build graph from edge declarations.
"""

graph = DirectedGraph()
for parent, child in edges:
parent = canonicalize_name(parent) if parent else None
child = canonicalize_name(child) if child else None
for v in (parent, child):
if v not in graph:
graph.add(v)
graph.connect(parent, child)
return graph


@pytest.mark.parametrize(
"edges, ordered_reqs",
[
Expand Down Expand Up @@ -59,15 +74,7 @@ def resolver(preparer, finder):
],
)
def test_new_resolver_get_installation_order(resolver, edges, ordered_reqs):
# Build graph from edge declarations.
graph = DirectedGraph()
for parent, child in edges:
parent = canonicalize_name(parent) if parent else None
child = canonicalize_name(child) if child else None
for v in (parent, child):
if v not in graph:
graph.add(v)
graph.connect(parent, child)
graph = _make_graph(edges)

# Mapping values and criteria are not used in test, so we stub them out.
mapping = {vertex: None for vertex in graph if vertex is not None}
Expand Down

0 comments on commit 9ae99b6

Please sign in to comment.