Merge pull request #9055 from pradyunsg/modify-assertion-in-topological-sort

This commit is contained in:
Pradyun Gedam 2020-10-27 19:33:33 +05:30 committed by GitHub
commit f5ac343481
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View File

@ -180,7 +180,10 @@ class Resolver(BaseResolver):
assert self._result is not None, "must call resolve() first"
graph = self._result.graph
weights = get_topological_weights(graph)
weights = get_topological_weights(
graph,
expected_node_count=len(self._result.mapping) + 1,
)
sorted_items = sorted(
req_set.requirements.items(),
@ -190,8 +193,8 @@ class Resolver(BaseResolver):
return [ireq for _, ireq in sorted_items]
def get_topological_weights(graph):
# type: (Graph) -> Dict[Optional[str], int]
def get_topological_weights(graph, expected_node_count):
# type: (Graph, int) -> Dict[Optional[str], int]
"""Assign weights to each node based on how "deep" they are.
This implementation may change at any point in the future without prior
@ -231,7 +234,7 @@ def get_topological_weights(graph):
# Sanity checks
assert weights[None] == 0
assert len(weights) == len(graph)
assert len(weights) == expected_node_count
return weights

View File

@ -232,5 +232,5 @@ def test_new_resolver_get_installation_order(resolver, edges, ordered_reqs):
def test_new_resolver_topological_weights(name, edges, expected_weights):
graph = _make_graph(edges)
weights = get_topological_weights(graph)
weights = get_topological_weights(graph, len(expected_weights))
assert weights == expected_weights