Skip to content

Commit d61ff4c

Browse files
committed
Migrate tests to use pathlib.Path
The pip-specific Path implementation has been removed, and all its usages replaced by pathlib.Path. The tmpdir and tmpdir_factory fixtures are also removed, and all usages are replaced by tmp_path and tmp_path_factory, which use pathlib.Path. As anyone might expect, the bulk of the work is simply adding str() everywhere.
1 parent e58a8a5 commit d61ff4c

File tree

78 files changed

+1876
-1916
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+1876
-1916
lines changed

tests/conftest.py

+87-98
Large diffs are not rendered by default.

tests/functional/test_broken_stdout.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import os
1+
import pathlib
22
import subprocess
33
from typing import List, Tuple
44

5-
from tests.lib.path import Path
6-
75
_BROKEN_STDOUT_RETURN_CODE = 120
86

97

@@ -47,13 +45,16 @@ def test_broken_stdout_pipe(deprecated_python: bool) -> None:
4745
assert returncode == _BROKEN_STDOUT_RETURN_CODE
4846

4947

50-
def test_broken_stdout_pipe__log_option(deprecated_python: bool, tmpdir: Path) -> None:
48+
def test_broken_stdout_pipe__log_option(
49+
deprecated_python: bool,
50+
tmp_path: pathlib.Path,
51+
) -> None:
5152
"""
5253
Test a broken pipe to stdout when --log is passed.
5354
"""
54-
log_path = os.path.join(str(tmpdir), "log.txt")
55+
log_path = tmp_path.joinpath("log.txt")
5556
stderr, returncode = setup_broken_stdout_test(
56-
["pip", "--log", log_path, "list"],
57+
["pip", "--log", str(log_path), "list"],
5758
deprecated_python=deprecated_python,
5859
)
5960

tests/functional/test_build_env.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ def run_with_build_env(
6969
" ",
7070
)
7171
)
72-
args = ["python", build_env_script]
72+
args = ["python", str(build_env_script)]
7373
if test_script_contents is not None:
7474
test_script = script.scratch_path / "test.py"
7575
test_script.write_text(dedent(test_script_contents))
76-
args.append(test_script)
76+
args.append(str(test_script))
7777
return script.run(*args)
7878

7979

@@ -89,7 +89,7 @@ def test_build_env_allow_empty_requirements_install() -> None:
8989
def test_build_env_allow_only_one_install(script: PipTestEnvironment) -> None:
9090
create_basic_wheel_for_package(script, "foo", "1.0")
9191
create_basic_wheel_for_package(script, "bar", "1.0")
92-
finder = make_test_finder(find_links=[script.scratch_path])
92+
finder = make_test_finder(find_links=[str(script.scratch_path)])
9393
build_env = BuildEnvironment()
9494
for prefix in ("normal", "overlay"):
9595
build_env.install_requirements(
@@ -112,7 +112,7 @@ def test_build_env_requirements_check(script: PipTestEnvironment) -> None:
112112
create_basic_wheel_for_package(script, "bar", "3.0")
113113
create_basic_wheel_for_package(script, "other", "0.5")
114114

115-
script.pip_install_local("-f", script.scratch_path, "foo", "bar", "other")
115+
script.pip_install_local("-f", str(script.scratch_path), "foo", "bar", "other")
116116

117117
run_with_build_env(
118118
script,
@@ -211,19 +211,19 @@ def test_build_env_isolation(script: PipTestEnvironment) -> None:
211211
pkg_whl = create_basic_wheel_for_package(script, "pkg", "1.0")
212212

213213
# Install it to site packages.
214-
script.pip_install_local(pkg_whl)
214+
script.pip_install_local(str(pkg_whl))
215215

216216
# And a copy in the user site.
217-
script.pip_install_local("--ignore-installed", "--user", pkg_whl)
217+
script.pip_install_local("--ignore-installed", "--user", str(pkg_whl))
218218

219219
# And to another directory available through a .pth file.
220220
target = script.scratch_path / "pth_install"
221-
script.pip_install_local("-t", target, pkg_whl)
222-
(script.site_packages_path / "build_requires.pth").write_text(str(target) + "\n")
221+
script.pip_install_local("-t", str(target), str(pkg_whl))
222+
(script.site_packages_path / "build_requires.pth").write_text(f"{target}\n")
223223

224224
# And finally to yet another directory available through PYTHONPATH.
225225
target = script.scratch_path / "pypath_install"
226-
script.pip_install_local("-t", target, pkg_whl)
226+
script.pip_install_local("-t", str(target), str(pkg_whl))
227227
script.environ["PYTHONPATH"] = target
228228

229229
run_with_build_env(

tests/functional/test_check.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_basic_check_missing_dependency(script: PipTestEnvironment) -> None:
3030
install_requires=["missing==0.1"],
3131
)
3232
# Let's install pkga without its dependency
33-
res = script.pip("install", "--no-index", pkga_path, "--no-deps")
33+
res = script.pip("install", "--no-index", str(pkga_path), "--no-deps")
3434
assert "Successfully installed pkga-1.0" in res.stdout, str(res)
3535

3636
result = script.pip("check", expect_error=True)
@@ -49,7 +49,7 @@ def test_basic_check_broken_dependency(script: PipTestEnvironment) -> None:
4949
install_requires=["broken>=1.0"],
5050
)
5151
# Let's install pkga without its dependency
52-
res = script.pip("install", "--no-index", pkga_path, "--no-deps")
52+
res = script.pip("install", "--no-index", str(pkga_path), "--no-deps")
5353
assert "Successfully installed pkga-1.0" in res.stdout, str(res)
5454

5555
# Setup broken==0.1
@@ -62,7 +62,7 @@ def test_basic_check_broken_dependency(script: PipTestEnvironment) -> None:
6262
res = script.pip(
6363
"install",
6464
"--no-index",
65-
broken_path,
65+
str(broken_path),
6666
"--no-warn-conflicts",
6767
)
6868
assert "Successfully installed broken-0.1" in res.stdout, str(res)
@@ -84,7 +84,7 @@ def test_basic_check_broken_dependency_and_missing_dependency(
8484
install_requires=["broken>=1.0"],
8585
)
8686
# Let's install pkga without its dependency
87-
res = script.pip("install", "--no-index", pkga_path, "--no-deps")
87+
res = script.pip("install", "--no-index", str(pkga_path), "--no-deps")
8888
assert "Successfully installed pkga-1.0" in res.stdout, str(res)
8989

9090
# Setup broken==0.1
@@ -95,7 +95,7 @@ def test_basic_check_broken_dependency_and_missing_dependency(
9595
install_requires=["missing"],
9696
)
9797
# Let's install broken==0.1
98-
res = script.pip("install", "--no-index", broken_path, "--no-deps")
98+
res = script.pip("install", "--no-index", str(broken_path), "--no-deps")
9999
assert "Successfully installed broken-0.1" in res.stdout, str(res)
100100

101101
result = script.pip("check", expect_error=True)
@@ -118,7 +118,7 @@ def test_check_complicated_name_missing(script: PipTestEnvironment) -> None:
118118
)
119119

120120
# Without dependency
121-
result = script.pip("install", "--no-index", package_a_path, "--no-deps")
121+
result = script.pip("install", "--no-index", str(package_a_path), "--no-deps")
122122
assert "Successfully installed package-A-1.0" in result.stdout, str(result)
123123

124124
result = script.pip("check", expect_error=True)
@@ -141,13 +141,13 @@ def test_check_complicated_name_broken(script: PipTestEnvironment) -> None:
141141
)
142142

143143
# With broken dependency
144-
result = script.pip("install", "--no-index", package_a_path, "--no-deps")
144+
result = script.pip("install", "--no-index", str(package_a_path), "--no-deps")
145145
assert "Successfully installed package-A-1.0" in result.stdout, str(result)
146146

147147
result = script.pip(
148148
"install",
149149
"--no-index",
150-
dependency_b_path_incompatible,
150+
str(dependency_b_path_incompatible),
151151
"--no-deps",
152152
)
153153
assert "Successfully installed dependency-b-0.1" in result.stdout
@@ -174,13 +174,13 @@ def test_check_complicated_name_clean(script: PipTestEnvironment) -> None:
174174
version="1.0",
175175
)
176176

177-
result = script.pip("install", "--no-index", package_a_path, "--no-deps")
177+
result = script.pip("install", "--no-index", str(package_a_path), "--no-deps")
178178
assert "Successfully installed package-A-1.0" in result.stdout, str(result)
179179

180180
result = script.pip(
181181
"install",
182182
"--no-index",
183-
dependency_b_path,
183+
str(dependency_b_path),
184184
"--no-deps",
185185
)
186186
assert "Successfully installed dependency-b-1.0" in result.stdout
@@ -202,7 +202,7 @@ def test_check_considers_conditional_reqs(script: PipTestEnvironment) -> None:
202202
],
203203
)
204204

205-
result = script.pip("install", "--no-index", package_a_path, "--no-deps")
205+
result = script.pip("install", "--no-index", str(package_a_path), "--no-deps")
206206
assert "Successfully installed package-A-1.0" in result.stdout, str(result)
207207

208208
result = script.pip("check", expect_error=True)
@@ -222,7 +222,7 @@ def test_check_development_versions_are_also_considered(
222222
install_requires=["depend>=1.0"],
223223
)
224224
# Let's install pkga without its dependency
225-
res = script.pip("install", "--no-index", pkga_path, "--no-deps")
225+
res = script.pip("install", "--no-index", str(pkga_path), "--no-deps")
226226
assert "Successfully installed pkga-1.0" in res.stdout, str(res)
227227

228228
# Setup depend==1.1.0.dev0
@@ -235,7 +235,7 @@ def test_check_development_versions_are_also_considered(
235235
res = script.pip(
236236
"install",
237237
"--no-index",
238-
depend_path,
238+
str(depend_path),
239239
"--no-warn-conflicts",
240240
)
241241
assert "Successfully installed depend-1.1.0.dev0" in res.stdout, str(res)

tests/functional/test_completion.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import os
2+
import pathlib
23
import sys
3-
from typing import TYPE_CHECKING, Optional, Tuple
4+
from typing import TYPE_CHECKING, Tuple, Union
45

56
import pytest
67

78
from tests.conftest import ScriptFactory
89
from tests.lib import PipTestEnvironment, TestData, TestPipResult
9-
from tests.lib.path import Path
1010

1111
if TYPE_CHECKING:
1212
from typing import Protocol
@@ -83,15 +83,15 @@
8383

8484
@pytest.fixture(scope="session")
8585
def script_with_launchers(
86-
tmpdir_factory: pytest.TempdirFactory,
86+
tmp_path_factory: pytest.TempPathFactory,
8787
script_factory: ScriptFactory,
88-
common_wheels: Path,
89-
pip_src: Path,
88+
common_wheels: pathlib.Path,
89+
pip_src: pathlib.Path,
9090
) -> PipTestEnvironment:
91-
tmpdir = Path(str(tmpdir_factory.mktemp("script_with_launchers")))
91+
tmpdir = tmp_path_factory.mktemp("script_with_launchers")
9292
script = script_factory(tmpdir.joinpath("workspace"))
9393
# Re-install pip so we get the launchers.
94-
script.pip_install_local("-f", common_wheels, pip_src)
94+
script.pip_install_local("-f", str(common_wheels), str(pip_src))
9595
return script
9696

9797

@@ -112,15 +112,15 @@ def test_completion_for_supported_shells(
112112

113113
@pytest.fixture(scope="session")
114114
def autocomplete_script(
115-
tmpdir_factory: pytest.TempdirFactory, script_factory: ScriptFactory
115+
tmp_path_factory: pytest.TempPathFactory, script_factory: ScriptFactory
116116
) -> PipTestEnvironment:
117-
tmpdir = Path(str(tmpdir_factory.mktemp("autocomplete_script")))
117+
tmpdir = tmp_path_factory.mktemp("autocomplete_script")
118118
return script_factory(tmpdir.joinpath("workspace"))
119119

120120

121121
class DoAutocomplete(Protocol):
122122
def __call__(
123-
self, words: str, cword: str, cwd: Optional[str] = None
123+
self, words: str, cword: str, cwd: Union[pathlib.Path, str, None] = None
124124
) -> Tuple[TestPipResult, PipTestEnvironment]:
125125
...
126126

@@ -133,7 +133,7 @@ def autocomplete(
133133
autocomplete_script.environ["PIP_AUTO_COMPLETE"] = "1"
134134

135135
def do_autocomplete(
136-
words: str, cword: str, cwd: Optional[str] = None
136+
words: str, cword: str, cwd: Union[pathlib.Path, str, None] = None
137137
) -> Tuple[TestPipResult, PipTestEnvironment]:
138138
autocomplete_script.environ["COMP_WORDS"] = words
139139
autocomplete_script.environ["COMP_CWORD"] = cword

tests/functional/test_config_settings.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import json
2+
import pathlib
23
from typing import Tuple
34
from zipfile import ZipFile
45

56
from tests.lib import PipTestEnvironment
6-
from tests.lib.path import Path
77

88
PYPROJECT_TOML = """\
99
[build-system]
@@ -85,7 +85,7 @@ def build_wheel(
8585
'''
8686

8787

88-
def make_project(path: Path) -> Tuple[str, str, Path]:
88+
def make_project(path: pathlib.Path) -> Tuple[str, str, pathlib.Path]:
8989
name = "foo"
9090
version = "1.0"
9191
project_dir = path / name
@@ -102,7 +102,7 @@ def test_backend_sees_config(script: PipTestEnvironment) -> None:
102102
"wheel",
103103
"--config-settings",
104104
"FOO=Hello",
105-
project_dir,
105+
str(project_dir),
106106
)
107107
wheel_file_name = f"{name}-{version}-py3-none-any.whl"
108108
wheel_file_path = script.cwd / wheel_file_name
@@ -118,7 +118,7 @@ def test_install_sees_config(script: PipTestEnvironment) -> None:
118118
"install",
119119
"--config-settings",
120120
"FOO=Hello",
121-
project_dir,
121+
str(project_dir),
122122
)
123123
config = script.site_packages_path / "config.json"
124124
with open(config, "rb") as f:
@@ -132,7 +132,7 @@ def test_install_editable_sees_config(script: PipTestEnvironment) -> None:
132132
"--config-settings",
133133
"FOO=Hello",
134134
"--editable",
135-
project_dir,
135+
str(project_dir),
136136
)
137137
config = script.site_packages_path / "config.json"
138138
with open(config, "rb") as f:

0 commit comments

Comments
 (0)