Fix types in tests on Windows

This commit is contained in:
Tzu-ping Chung 2021-09-28 18:51:46 +08:00
parent 9b195bc9c9
commit ad158b03e8
5 changed files with 14 additions and 15 deletions

View File

@ -408,10 +408,9 @@ class InstallRequirement:
existing_dist
):
raise InstallationError(
"Will not install to the user site because it will "
"lack sys.path precedence to {} in {}".format(
existing_dist.project_name, existing_dist.location
)
f"Will not install to the user site because it will "
f"lack sys.path precedence to {existing_dist.raw_name} "
f"in {existing_dist.location}"
)
else:
self.should_reinstall = True

View File

@ -62,7 +62,7 @@ class TestUserCacheDir:
if sys.platform != "win32":
return
def my_get_win_folder(csidl_name):
def my_get_win_folder(csidl_name: str) -> str:
return "\u00DF\u00E4\u03B1\u20AC"
monkeypatch.setattr(platformdirs.windows, "get_win_folder", my_get_win_folder)

View File

@ -54,7 +54,7 @@ class TestLocations:
os.fstat = lambda fd: self.get_mock_fstat(fd)
if sys.platform != "win32":
pwd.getpwuid = lambda uid: self.get_mock_getpwuid(uid)
pwd.getpwuid = self.get_mock_getpwuid
def revert_patch(self) -> None:
"""revert the patches to python methods"""
@ -74,7 +74,7 @@ class TestLocations:
result.st_uid = self.st_uid
return result
def get_mock_getpwuid(self, uid: int) -> pwd.struct_passwd:
def get_mock_getpwuid(self, uid: int) -> Any:
"""returns a basic mock pwd.getpwuid call result.
Currently only the pw_name attribute has been set.
"""

View File

@ -21,7 +21,7 @@ from pip._internal.exceptions import (
PreviousBuildDirError,
)
from pip._internal.index.package_finder import PackageFinder
from pip._internal.metadata import BaseDistribution
from pip._internal.metadata.pkg_resources import Distribution
from pip._internal.network.session import PipSession
from pip._internal.operations.prepare import RequirementPreparer
from pip._internal.req import InstallRequirement, RequirementSet
@ -451,7 +451,7 @@ class TestInstallRequirement:
req = install_req_from_line("foo")
req.metadata_directory = path
dist = req.get_dist()
assert isinstance(dist, BaseDistribution)
assert isinstance(dist, Distribution)
assert dist.raw_name == dist.canonical_name == "foo"
assert dist.location == "/path/to".replace("/", os.path.sep)

View File

@ -137,12 +137,12 @@ class TestUninstallPathSet:
pass
ups = UninstallPathSet(dist=Mock())
assert ups.paths == set()
assert ups._paths == set()
ups.add(file_extant)
assert ups.paths == {file_extant}
assert ups._paths == {file_extant}
ups.add(file_nonexistent)
assert ups.paths == {file_extant}
assert ups._paths == {file_extant}
def test_add_pth(self, tmpdir: str, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(pip._internal.req.req_uninstall, "is_local", mock_is_local)
@ -184,7 +184,7 @@ class TestUninstallPathSet:
ups = UninstallPathSet(dist=Mock())
ups.add(foo_link)
assert ups.paths == {foo_link}
assert ups._paths == {foo_link}
def test_compact_shorter_path(self, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(pip._internal.req.req_uninstall, "is_local", mock_is_local)
@ -196,7 +196,7 @@ class TestUninstallPathSet:
ups = UninstallPathSet(dist=Mock())
ups.add(short_path)
ups.add(os.path.join(short_path, "longer"))
assert compact(ups.paths) == {short_path}
assert compact(ups._paths) == {short_path}
@pytest.mark.skipif("sys.platform == 'win32'")
def test_detect_symlink_dirs(
@ -218,7 +218,7 @@ class TestUninstallPathSet:
ups = UninstallPathSet(dist=Mock())
ups.add(path1)
ups.add(path2)
assert ups.paths == {path1}
assert ups._paths == {path1}
class TestStashedUninstallPathSet: