Skip to content

Commit

Permalink
Adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nour-Mws committed Aug 8, 2023
1 parent ffeec61 commit 008a769
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 35 deletions.
55 changes: 24 additions & 31 deletions tests/test_install_deps.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
"""Verify behavior of TemporaryPipInstallResolver."""
import logging

import pytest

from fawltydeps.packages import (
IdentityMapping,
Package,
TemporaryPipInstallResolver,
resolve_dependencies,
setup_resolvers,
)
from fawltydeps.types import UnresolvedDependenciesError


def test_resolve_dependencies_install_deps__via_local_cache(local_pypi):
Expand All @@ -23,42 +25,33 @@ def test_resolve_dependencies_install_deps__via_local_cache(local_pypi):
}


def test_resolve_dependencies_install_deps__handle_pip_install_failure(
def test_resolve_dependencies_install_deps__raises_unresolved_error_on_pip_install_failure(
caplog, local_pypi
):
# TemporaryPipInstallResolver will handle the inevitable pip install error
# and return to resolve_dependencies() with the missing package unresolved.
# For now, IdentityMapping "saves the day" and supplies a Package object.
# Soon, this should result in an unresolved package error instead.
# This tests the case where TemporaryPipInstallResolver encounters the
# inevitable pip install error and returns to resolve_dependencies()
# with the missing package unresolved.
# Since either install_deps or IdentityMapping are the final resolvers,
# this should raise an `UnresolvedDependenciesError`.
caplog.set_level(logging.WARNING)
actual = resolve_dependencies(
["does_not_exist"], setup_resolvers(install_deps=True)
)
assert actual == {
"does_not_exist": Package(
"does_not_exist", {"does_not_exist"}, IdentityMapping
),
}

with pytest.raises(UnresolvedDependenciesError):
resolve_dependencies(["does_not_exist"], setup_resolvers(install_deps=True))

assert all(word in caplog.text for word in ["pip", "install", "does_not_exist"])


def test_resolve_dependencies_install_deps__pip_install_some_packages(
def test_resolve_dependencies_install_deps_on_mixed_packages__raises_unresolved_error(
caplog, local_pypi
):
debug_info = "Provided by temporary `pip install`"
caplog.set_level(logging.WARNING)
actual = resolve_dependencies(
["click", "does_not_exist", "leftpadx"], setup_resolvers(install_deps=True)
caplog.set_level(logging.DEBUG)
deps = {"click", "does_not_exist", "leftpadx"}
# Attempting to pip install "does_not_exist"
# will result in an `UnresolvedDependenciesError`.
with pytest.raises(UnresolvedDependenciesError):
resolve_dependencies(deps, setup_resolvers(install_deps=True))
# Attempted to install deps with TemporaryPipInstall
assert (
f"Trying to resolve {deps!r} with <fawltydeps.packages.TemporaryPipInstallResolver"
in caplog.text
)
# pip install is able to install "leftpadx", but "package_does_not_exist"
# falls through to IdentityMapping.
assert actual == {
"click": Package("click", {"click"}, TemporaryPipInstallResolver, debug_info),
"does_not_exist": Package(
"does_not_exist", {"does_not_exist"}, IdentityMapping
),
"leftpadx": Package(
"leftpadx", {"leftpad"}, TemporaryPipInstallResolver, debug_info
),
}
assert all(word in caplog.text for word in ["pip", "install", "does_not_exist"])
5 changes: 1 addition & 4 deletions tests/test_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,8 @@ def test_resolve_dependencies__informs_once_when_id_mapping_is_used(
assert caplog.record_tuples == expect_log


@pytest.mark.skip(
"This test waits for making IdentityMappig optional or not used as a fallback"
)
def test_resolve_dependencies__unresolved_dependencies__UnresolvedDependenciesError_raised():
dep_names = ["foo", "bar"]

with pytest.raises(UnresolvedDependenciesError):
resolve_dependencies(dep_names, setup_resolvers())
resolve_dependencies(dep_names, setup_resolvers(install_deps=True))

0 comments on commit 008a769

Please sign in to comment.