From 638c3dfc8af1ba2b32b420eef3f58b64839871b7 Mon Sep 17 00:00:00 2001 From: Damian Shaw Date: Tue, 30 Jul 2024 17:44:07 -0400 Subject: [PATCH] Add unvisited tests --- tests/conftest.py | 3 +++ .../python/inputs/case/backjump-test-1.json | 3 +++ .../python/inputs/case/backjump-test-2.json | 3 +++ .../python/test_resolvers_python.py | 26 +++++++++++++++++-- 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 96039440..f2e23dde 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 diff --git a/tests/functional/python/inputs/case/backjump-test-1.json b/tests/functional/python/inputs/case/backjump-test-1.json index 953e0f5d..044305b5 100644 --- a/tests/functional/python/inputs/case/backjump-test-1.json +++ b/tests/functional/python/inputs/case/backjump-test-1.json @@ -11,5 +11,8 @@ "sat-stac": "0.1.1", "python-dateutil": "2.7.5", "requests": "2.31.0" + }, + "unvisited": { + "pystac": ["1.8.2"] } } diff --git a/tests/functional/python/inputs/case/backjump-test-2.json b/tests/functional/python/inputs/case/backjump-test-2.json index 7e78419a..02ba57c2 100644 --- a/tests/functional/python/inputs/case/backjump-test-2.json +++ b/tests/functional/python/inputs/case/backjump-test-2.json @@ -13,5 +13,8 @@ "sat-stac": "0.1.1", "python-dateutil": "2.7.5", "requests": "2.31.0" + }, + "unvisited": { + "pystac": ["1.8.2"] } } diff --git a/tests/functional/python/test_resolvers_python.py b/tests/functional/python/test_resolvers_python.py index 2b6de367..9da73645 100644 --- a/tests/functional/python/test_resolvers_python.py +++ b/tests/functional/python/test_resolvers_python.py @@ -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 @@ -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: @@ -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 for {name}: {', '.join(unexpected_versions)}"