Skip to content

Commit

Permalink
Merge pull request #158 from notatallshaw/add-unvisited-tests
Browse files Browse the repository at this point in the history
Add unvisited tests to ensure backjumping
  • Loading branch information
pradyunsg authored Jul 31, 2024
2 parents 58c5d90 + 44e43f3 commit e4de27e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
3 changes: 3 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
class TestReporter(BaseReporter):
def __init__(self):
self._indent = 0
self.visited = []

def rejecting_candidate(self, criterion, candidate):
self._indent -= 1
self.visited.append(candidate)
print(" " * self._indent, "Reject ", candidate, sep="")

def pinning(self, candidate):
print(" " * self._indent, "Pin ", candidate, sep="")
self.visited.append(candidate)
self._indent += 1


Expand Down
3 changes: 3 additions & 0 deletions tests/functional/python/inputs/case/backjump-test-1.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@
"sat-stac": "0.1.1",
"python-dateutil": "2.7.5",
"requests": "2.31.0"
},
"unvisited": {
"pystac": ["1.8.2"]
}
}
3 changes: 3 additions & 0 deletions tests/functional/python/inputs/case/backjump-test-2.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
"sat-stac": "0.1.1",
"python-dateutil": "2.7.5",
"requests": "2.31.0"
},
"unvisited": {
"pystac": ["1.8.2"]
}
}
26 changes: 24 additions & 2 deletions tests/functional/python/test_resolvers_python.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from __future__ import print_function

import collections
import json
import operator
import os
from collections import defaultdict

import packaging.markers
import packaging.requirements
Expand Down Expand Up @@ -64,6 +63,11 @@ def __init__(self, filename):
else:
self.expected_confliction = None

if "unvisited" in case_data:
self.expected_unvisited = case_data["unvisited"]
else:
self.expected_unvisited = None

def identify(self, requirement_or_candidate):
name = packaging.utils.canonicalize_name(requirement_or_candidate.name)
if requirement_or_candidate.extras:
Expand Down Expand Up @@ -174,3 +178,21 @@ def test_resolver(provider, reporter):
else:
resolution = resolver.resolve(provider.root_requirements)
assert _format_resolution(resolution) == provider.expected_resolution

if provider.expected_unvisited:
visited_versions = defaultdict(set)
for visited_candidate in reporter.visited:
visited_versions[visited_candidate.name].add(
str(visited_candidate.version)
)

for name, versions in provider.expected_unvisited.items():
if name not in visited_versions:
continue

unexpected_versions = set(versions).intersection(
visited_versions[name]
)
assert (
not unexpected_versions
), f"Unexpcted versions visited {name}: {', '.join(unexpected_versions)}"

0 comments on commit e4de27e

Please sign in to comment.