Skip to content

Commit c71cf88

Browse files
committed
Complete type annotations of tests/functional/ directory
1 parent 12dad05 commit c71cf88

Some content is hidden

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

55 files changed

+1995
-982
lines changed

news/7cecf5ba-92a1-49a9-85f0-07a4dd8aca46.trivial.rst

Whitespace-only changes.

setup.cfg

-4
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ follow_imports = skip
5151
[mypy-pip._vendor.requests.*]
5252
follow_imports = skip
5353

54-
# TODO: The following option should be removed at some point in the future.
55-
[mypy-tests.functional.*]
56-
allow_untyped_defs = True
57-
5854
[tool:pytest]
5955
addopts = --ignore src/pip/_vendor --ignore tests/tests_cache -r aR --color=yes
6056
xfail_strict = True

tests/conftest.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@
3636
from .lib.compat import nullcontext
3737

3838
if TYPE_CHECKING:
39+
from typing import Protocol
40+
3941
from wsgi import WSGIApplication
42+
else:
43+
# TODO: Protocol was introduced in Python 3.8. Remove this branch when
44+
# dropping support for Python 3.7.
45+
Protocol = object
4046

4147

4248
def pytest_addoption(parser: Parser) -> None:
@@ -442,10 +448,17 @@ def with_wheel(virtualenv: VirtualEnvironment, wheel_install: Path) -> None:
442448
install_egg_link(virtualenv, "wheel", wheel_install)
443449

444450

451+
class ScriptFactory(Protocol):
452+
def __call__(
453+
self, tmpdir: Path, virtualenv: Optional[VirtualEnvironment] = None
454+
) -> PipTestEnvironment:
455+
...
456+
457+
445458
@pytest.fixture(scope="session")
446459
def script_factory(
447460
virtualenv_factory: Callable[[Path], VirtualEnvironment], deprecated_python: bool
448-
) -> Callable[[Path, Optional[VirtualEnvironment]], PipTestEnvironment]:
461+
) -> ScriptFactory:
449462
def factory(
450463
tmpdir: Path, virtualenv: Optional[VirtualEnvironment] = None
451464
) -> PipTestEnvironment:
@@ -533,8 +546,11 @@ def deprecated_python() -> bool:
533546
return sys.version_info[:2] in []
534547

535548

549+
CertFactory = Callable[[], str]
550+
551+
536552
@pytest.fixture(scope="session")
537-
def cert_factory(tmpdir_factory: pytest.TempdirFactory) -> Callable[[], str]:
553+
def cert_factory(tmpdir_factory: pytest.TempdirFactory) -> CertFactory:
538554
def factory() -> str:
539555
"""Returns path to cert/key file."""
540556
output_path = Path(str(tmpdir_factory.mktemp("certs"))) / "cert.pem"

tests/functional/test_broken_stdout.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
import os
22
import subprocess
3+
from typing import List, Tuple
4+
5+
from tests.lib.path import Path
36

47
_BROKEN_STDOUT_RETURN_CODE = 120
58

69

7-
def setup_broken_stdout_test(args, deprecated_python):
10+
def setup_broken_stdout_test(
11+
args: List[str], deprecated_python: bool
12+
) -> Tuple[str, int]:
813
proc = subprocess.Popen(
914
args,
1015
stdout=subprocess.PIPE,
1116
stderr=subprocess.PIPE,
1217
)
1318
# Call close() on stdout to cause a broken pipe.
19+
assert proc.stdout is not None
1420
proc.stdout.close()
1521
returncode = proc.wait()
22+
assert proc.stderr is not None
1623
stderr = proc.stderr.read().decode("utf-8")
1724

1825
expected_msg = "ERROR: Pipe to stdout was broken"
@@ -24,7 +31,7 @@ def setup_broken_stdout_test(args, deprecated_python):
2431
return stderr, returncode
2532

2633

27-
def test_broken_stdout_pipe(deprecated_python):
34+
def test_broken_stdout_pipe(deprecated_python: bool) -> None:
2835
"""
2936
Test a broken pipe to stdout.
3037
"""
@@ -40,7 +47,7 @@ def test_broken_stdout_pipe(deprecated_python):
4047
assert returncode == _BROKEN_STDOUT_RETURN_CODE
4148

4249

43-
def test_broken_stdout_pipe__log_option(deprecated_python, tmpdir):
50+
def test_broken_stdout_pipe__log_option(deprecated_python: bool, tmpdir: Path) -> None:
4451
"""
4552
Test a broken pipe to stdout when --log is passed.
4653
"""
@@ -57,7 +64,7 @@ def test_broken_stdout_pipe__log_option(deprecated_python, tmpdir):
5764
assert returncode == _BROKEN_STDOUT_RETURN_CODE
5865

5966

60-
def test_broken_stdout_pipe__verbose(deprecated_python):
67+
def test_broken_stdout_pipe__verbose(deprecated_python: bool) -> None:
6168
"""
6269
Test a broken pipe to stdout with verbose logging enabled.
6370
"""

tests/functional/test_build_env.py

+22-9
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
from textwrap import dedent
2+
from typing import Optional
23

34
import pytest
45

56
from pip._internal.build_env import BuildEnvironment
6-
from tests.lib import create_basic_wheel_for_package, make_test_finder
7+
from tests.lib import (
8+
PipTestEnvironment,
9+
TestPipResult,
10+
create_basic_wheel_for_package,
11+
make_test_finder,
12+
)
713

814

9-
def indent(text, prefix):
15+
def indent(text: str, prefix: str) -> str:
1016
return "\n".join((prefix if line else "") + line for line in text.split("\n"))
1117

1218

13-
def run_with_build_env(script, setup_script_contents, test_script_contents=None):
19+
def run_with_build_env(
20+
script: PipTestEnvironment,
21+
setup_script_contents: str,
22+
test_script_contents: Optional[str] = None,
23+
) -> TestPipResult:
1424
build_env_script = script.scratch_path / "build_env.py"
1525
build_env_script.write_text(
1626
dedent(
@@ -66,13 +76,16 @@ def run_with_build_env(script, setup_script_contents, test_script_contents=None)
6676
return script.run(*args)
6777

6878

69-
def test_build_env_allow_empty_requirements_install():
79+
def test_build_env_allow_empty_requirements_install() -> None:
80+
finder = make_test_finder()
7081
build_env = BuildEnvironment()
7182
for prefix in ("normal", "overlay"):
72-
build_env.install_requirements(None, [], prefix, None)
83+
build_env.install_requirements(
84+
finder, [], prefix, "Installing build dependencies"
85+
)
7386

7487

75-
def test_build_env_allow_only_one_install(script):
88+
def test_build_env_allow_only_one_install(script: PipTestEnvironment) -> None:
7689
create_basic_wheel_for_package(script, "foo", "1.0")
7790
create_basic_wheel_for_package(script, "bar", "1.0")
7891
finder = make_test_finder(find_links=[script.scratch_path])
@@ -91,7 +104,7 @@ def test_build_env_allow_only_one_install(script):
91104
)
92105

93106

94-
def test_build_env_requirements_check(script):
107+
def test_build_env_requirements_check(script: PipTestEnvironment) -> None:
95108

96109
create_basic_wheel_for_package(script, "foo", "2.0")
97110
create_basic_wheel_for_package(script, "bar", "1.0")
@@ -152,7 +165,7 @@ def test_build_env_requirements_check(script):
152165
)
153166

154167

155-
def test_build_env_overlay_prefix_has_priority(script):
168+
def test_build_env_overlay_prefix_has_priority(script: PipTestEnvironment) -> None:
156169
create_basic_wheel_for_package(script, "pkg", "2.0")
157170
create_basic_wheel_for_package(script, "pkg", "4.3")
158171
result = run_with_build_env(
@@ -171,7 +184,7 @@ def test_build_env_overlay_prefix_has_priority(script):
171184

172185

173186
@pytest.mark.incompatible_with_test_venv
174-
def test_build_env_isolation(script):
187+
def test_build_env_isolation(script: PipTestEnvironment) -> None:
175188

176189
# Create dummy `pkg` wheel.
177190
pkg_whl = create_basic_wheel_for_package(script, "pkg", "1.0")

0 commit comments

Comments
 (0)