Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_resolver(provider, base_reporter):
resolver = Resolver(provider, base_reporter)
if provider.expected_conflicts:
with pytest.raises(ResolutionImpossible) as ctx:
result = resolver.resolve(provider.root_requirements)
print(_format_resolution(result)) # Provide some debugging hints.
assert _format_conflicts(ctx.value) == provider.expected_conflicts
else:
result = resolver.resolve(provider.root_requirements)
assert _format_resolution(result) == provider.expected_resolution
def get_preference(self, *_):
return 0
def get_dependencies(self, _):
return []
def find_matches(self, r):
assert r is requirement
return [candidate]
def is_satisfied_by(self, r, c):
assert r is requirement
assert c is candidate
return False
resolver = Resolver(Provider(), BaseReporter())
with pytest.raises(InconsistentCandidate) as ctx:
resolver.resolve([requirement])
assert str(ctx.value) == "Provided candidate 'bar' does not satisfy 'foo'"
assert ctx.value.candidate is candidate
assert list(ctx.value.criterion.iter_requirement()) == [requirement]
def _clean_identifier(s):
# I'm not entirely sure how identifiers in the spec work. The only fixture
# this matters (AFAICT) is swapping_changes_transitive_dependency, which
# has a '\u0001' that seems to intend to be dropped?
return "".join(c for c in s if c in string.printable)
def _iter_resolved(dependencies):
for entry in dependencies:
yield (entry["name"], packaging.version.parse(entry["version"]))
for sub in _iter_resolved(entry["dependencies"]):
yield sub
class CocoaPodsInputProvider(AbstractProvider):
def __init__(self, filename):
case_data = _safe_json_load(filename)
index_name = os.path.join(
INPUTS_DIR, "index", case_data.get("index", "awesome") + ".json",
)
self.index = _safe_json_load(index_name)
self.root_requirements = [
Requirement(_clean_identifier(key), _parse_specifier_set(spec))
for key, spec in case_data["requested"].items()
]
self.pinned_versions = {
entry["name"]: packaging.version.parse(entry["version"])
for entry in case_data["base"]
}
def test_candidate_inconsistent_error():
requirement = "foo"
candidate = "bar"
class Provider(AbstractProvider):
def identify(self, d):
assert d is requirement or d is candidate
return d
def get_preference(self, *_):
return 0
def get_dependencies(self, _):
return []
def find_matches(self, r):
assert r is requirement
return [candidate]
def is_satisfied_by(self, r, c):
assert r is requirement
def test_resolver(provider, base_reporter):
resolver = Resolver(provider, base_reporter)
if provider.expected_conflicts:
with pytest.raises(ResolutionImpossible) as ctx:
result = resolver.resolve(provider.root_requirements)
print(_format_resolution(result)) # Provide some debugging hints.
assert _format_conflicts(ctx.value) == provider.expected_conflicts
else:
result = resolver.resolve(provider.root_requirements)
assert _format_resolution(result) == provider.expected_resolution
def _eval_marker(marker, extras=(None,)):
if not marker:
return True
if not isinstance(marker, packaging.markers.Marker):
marker = packaging.markers.Marker(marker)
return any(marker.evaluate({"extra": extra}) for extra in extras)
def _iter_resolved(data):
for k, v in data.items():
if not isinstance(v, dict):
v = {"version": v}
yield k, v
class PythonInputProvider(AbstractProvider):
def __init__(self, filename):
with open(filename) as f:
case_data = json.load(f)
index_name = os.path.normpath(
os.path.join(
filename, "..", "..", "index", case_data["index"] + ".json"
),
)
with open(index_name) as f:
self.index = json.load(f)
self.root_requirements = [
packaging.requirements.Requirement(r)
for r in case_data["requested"]
]
0,
-parsed_version[1],
parsed_version[2],
-len(parsed_version[3][:1]),
parsed_version[3],
)
return (
-parsed_version[0],
parsed_version[1],
parsed_version[2],
-len(parsed_version[3][:1]),
parsed_version[3],
)
class SwiftInputProvider(AbstractProvider):
def __init__(self, filename):
with open(filename) as f:
input_data = json.load(f)
self.containers = {
container["identifier"]: container
for container in input_data["containers"]
}
self.root_requirements = [
Requirement(self.containers[constraint["identifier"]], constraint)
for constraint in input_data["constraints"]
]
self.expectation = input_data["result"]
def identify(self, requirement_or_candidate):
return requirement_or_candidate.container["identifier"]
def test_resolver(provider, reporter):
resolver = Resolver(provider, reporter)
result = resolver.resolve(provider.root_requirements)
assert _format_resolution(result) == provider.expected_resolution
def test_resolver(provider, base_reporter):
resolver = Resolver(provider, base_reporter)
result = resolver.resolve(provider.root_requirements)
display = {
identifier: candidate.version
for identifier, candidate in result.mapping.items()
}
assert display == provider.expectation
def get_dependencies(self, _):
return []
def find_matches(self, r):
assert r is requirement
return [candidate]
def is_satisfied_by(self, r, c):
assert r is requirement
assert c is candidate
return False
resolver = Resolver(Provider(), BaseReporter())
with pytest.raises(InconsistentCandidate) as ctx:
resolver.resolve([requirement])
assert str(ctx.value) == "Provided candidate 'bar' does not satisfy 'foo'"
assert ctx.value.candidate is candidate
assert list(ctx.value.criterion.iter_requirement()) == [requirement]