Skip to content

Commit ad158b0

Browse files
committed
Fix types in tests on Windows
1 parent 9b195bc commit ad158b0

File tree

5 files changed

+14
-15
lines changed

5 files changed

+14
-15
lines changed

src/pip/_internal/req/req_install.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,10 +408,9 @@ def check_if_exists(self, use_user_site: bool) -> None:
408408
existing_dist
409409
):
410410
raise InstallationError(
411-
"Will not install to the user site because it will "
412-
"lack sys.path precedence to {} in {}".format(
413-
existing_dist.project_name, existing_dist.location
414-
)
411+
f"Will not install to the user site because it will "
412+
f"lack sys.path precedence to {existing_dist.raw_name} "
413+
f"in {existing_dist.location}"
415414
)
416415
else:
417416
self.should_reinstall = True

tests/unit/test_appdirs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def test_user_cache_dir_unicode(self, monkeypatch: pytest.MonkeyPatch) -> None:
6262
if sys.platform != "win32":
6363
return
6464

65-
def my_get_win_folder(csidl_name):
65+
def my_get_win_folder(csidl_name: str) -> str:
6666
return "\u00DF\u00E4\u03B1\u20AC"
6767

6868
monkeypatch.setattr(platformdirs.windows, "get_win_folder", my_get_win_folder)

tests/unit/test_locations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def patch(self) -> None:
5454
os.fstat = lambda fd: self.get_mock_fstat(fd)
5555

5656
if sys.platform != "win32":
57-
pwd.getpwuid = lambda uid: self.get_mock_getpwuid(uid)
57+
pwd.getpwuid = self.get_mock_getpwuid
5858

5959
def revert_patch(self) -> None:
6060
"""revert the patches to python methods"""
@@ -74,7 +74,7 @@ def get_mock_fstat(self, fd: int) -> os.stat_result:
7474
result.st_uid = self.st_uid
7575
return result
7676

77-
def get_mock_getpwuid(self, uid: int) -> pwd.struct_passwd:
77+
def get_mock_getpwuid(self, uid: int) -> Any:
7878
"""returns a basic mock pwd.getpwuid call result.
7979
Currently only the pw_name attribute has been set.
8080
"""

tests/unit/test_req.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
PreviousBuildDirError,
2222
)
2323
from pip._internal.index.package_finder import PackageFinder
24-
from pip._internal.metadata import BaseDistribution
24+
from pip._internal.metadata.pkg_resources import Distribution
2525
from pip._internal.network.session import PipSession
2626
from pip._internal.operations.prepare import RequirementPreparer
2727
from pip._internal.req import InstallRequirement, RequirementSet
@@ -451,7 +451,7 @@ def test_get_dist(self, path: str) -> None:
451451
req = install_req_from_line("foo")
452452
req.metadata_directory = path
453453
dist = req.get_dist()
454-
assert isinstance(dist, BaseDistribution)
454+
assert isinstance(dist, Distribution)
455455
assert dist.raw_name == dist.canonical_name == "foo"
456456
assert dist.location == "/path/to".replace("/", os.path.sep)
457457

tests/unit/test_req_uninstall.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,12 @@ def test_add(self, tmpdir: Path, monkeypatch: pytest.MonkeyPatch) -> None:
137137
pass
138138

139139
ups = UninstallPathSet(dist=Mock())
140-
assert ups.paths == set()
140+
assert ups._paths == set()
141141
ups.add(file_extant)
142-
assert ups.paths == {file_extant}
142+
assert ups._paths == {file_extant}
143143

144144
ups.add(file_nonexistent)
145-
assert ups.paths == {file_extant}
145+
assert ups._paths == {file_extant}
146146

147147
def test_add_pth(self, tmpdir: str, monkeypatch: pytest.MonkeyPatch) -> None:
148148
monkeypatch.setattr(pip._internal.req.req_uninstall, "is_local", mock_is_local)
@@ -184,7 +184,7 @@ def test_add_symlink(self, tmpdir: Path, monkeypatch: pytest.MonkeyPatch) -> Non
184184

185185
ups = UninstallPathSet(dist=Mock())
186186
ups.add(foo_link)
187-
assert ups.paths == {foo_link}
187+
assert ups._paths == {foo_link}
188188

189189
def test_compact_shorter_path(self, monkeypatch: pytest.MonkeyPatch) -> None:
190190
monkeypatch.setattr(pip._internal.req.req_uninstall, "is_local", mock_is_local)
@@ -196,7 +196,7 @@ def test_compact_shorter_path(self, monkeypatch: pytest.MonkeyPatch) -> None:
196196
ups = UninstallPathSet(dist=Mock())
197197
ups.add(short_path)
198198
ups.add(os.path.join(short_path, "longer"))
199-
assert compact(ups.paths) == {short_path}
199+
assert compact(ups._paths) == {short_path}
200200

201201
@pytest.mark.skipif("sys.platform == 'win32'")
202202
def test_detect_symlink_dirs(
@@ -218,7 +218,7 @@ def test_detect_symlink_dirs(
218218
ups = UninstallPathSet(dist=Mock())
219219
ups.add(path1)
220220
ups.add(path2)
221-
assert ups.paths == {path1}
221+
assert ups._paths == {path1}
222222

223223

224224
class TestStashedUninstallPathSet:

0 commit comments

Comments
 (0)