Commit 99f106c5 by David Hotham Committed by GitHub

some unit test typechecking (#7802)

parent 3855bc58
......@@ -160,6 +160,11 @@ enable_error_code = [
"redundant-expr",
"truthy-bool",
]
exclude = [
"tests/fixtures",
"tests/masonry/builders/fixtures",
"tests/utils/fixtures"
]
# use of importlib-metadata backport at python3.7 makes it impossible to
# satisfy mypy without some ignores: but we get a different set of ignores at
......@@ -178,6 +183,10 @@ warn_unused_ignores = false
[[tool.mypy.overrides]]
module = [
'cachecontrol.*',
'cachy.*',
'deepdiff.*',
'httpretty.*',
'keyring.*',
'lockfile.*',
'pexpect.*',
'requests_toolbelt.*',
......
......@@ -5,6 +5,7 @@ import re
from pathlib import Path
from typing import TYPE_CHECKING
from typing import Any
import pytest
......@@ -19,7 +20,7 @@ if TYPE_CHECKING:
from collections.abc import Iterator
def get_options_based_on_normalizer(normalizer: Callable) -> str:
def get_options_based_on_normalizer(normalizer: Callable[[str], Any]) -> str:
flattened_config = flatten_dict(obj=Config.default_config, delimiter=".")
for k in flattened_config:
......@@ -30,13 +31,13 @@ def get_options_based_on_normalizer(normalizer: Callable) -> str:
@pytest.mark.parametrize(
("name", "value"), [("installer.parallel", True), ("virtualenvs.create", True)]
)
def test_config_get_default_value(config: Config, name: str, value: bool):
def test_config_get_default_value(config: Config, name: str, value: bool) -> None:
assert config.get(name) is value
def test_config_get_processes_depended_on_values(
config: Config, config_cache_dir: Path
):
) -> None:
assert str(config_cache_dir / "virtualenvs") == config.get("virtualenvs.path")
......@@ -62,7 +63,7 @@ def test_config_get_from_environment_variable(
env_var: str,
env_value: str,
value: bool,
):
) -> None:
os.environ[env_var] = env_value
assert config.get(name) is value
......@@ -73,6 +74,6 @@ def test_config_get_from_environment_variable(
)
def test_config_expands_tilde_for_virtualenvs_path(
config: Config, path_config: str, expected: Path
):
) -> None:
config.merge({"virtualenvs": {"path": path_config}})
assert config.virtualenvs_path == expected
......@@ -20,7 +20,7 @@ def tester(command_tester_factory: CommandTesterFactory) -> CommandTester:
def test_cache_list(
tester: CommandTester, mock_caches: None, repository_one: str, repository_two: str
):
) -> None:
tester.execute()
expected = f"""\
......@@ -31,7 +31,7 @@ def test_cache_list(
assert tester.io.fetch_output() == expected
def test_cache_list_empty(tester: CommandTester, repository_cache_dir: Path):
def test_cache_list_empty(tester: CommandTester, repository_cache_dir: Path) -> None:
tester.execute()
expected = """\
......
......@@ -33,7 +33,7 @@ def __add_packages(repo: TestRepository) -> None:
repo.add_package(get_package("cleo", "0.6.5"))
def test_debug_resolve_gives_resolution_results(tester: CommandTester):
def test_debug_resolve_gives_resolution_results(tester: CommandTester) -> None:
tester.execute("cachy")
expected = """\
......@@ -48,7 +48,9 @@ cachy 0.2.0
assert tester.io.fetch_output() == expected
def test_debug_resolve_tree_option_gives_the_dependency_tree(tester: CommandTester):
def test_debug_resolve_tree_option_gives_the_dependency_tree(
tester: CommandTester,
) -> None:
tester.execute("cachy --tree")
expected = """\
......@@ -63,7 +65,7 @@ cachy 0.2.0
assert tester.io.fetch_output() == expected
def test_debug_resolve_git_dependency(tester: CommandTester):
def test_debug_resolve_git_dependency(tester: CommandTester) -> None:
tester.execute("git+https://github.com/demo/demo.git")
expected = """\
......
......@@ -36,7 +36,7 @@ def test_none_activated(
venvs_in_cache_dirs: list[str],
mocker: MockerFixture,
env: MockEnv,
):
) -> None:
mocker.patch("poetry.utils.env.EnvManager.get", return_value=env)
tester.execute()
expected = "\n".join(venvs_in_cache_dirs)
......@@ -48,13 +48,15 @@ def test_activated(
venvs_in_cache_dirs: list[str],
venv_cache: Path,
venv_activate_37: None,
):
) -> None:
tester.execute()
expected = "\n".join(venvs_in_cache_dirs).replace("py3.7", "py3.7 (Activated)")
assert tester.io.fetch_output().strip() == expected
def test_in_project_venv(tester: CommandTester, venvs_in_project_dir: list[str]):
def test_in_project_venv(
tester: CommandTester, venvs_in_project_dir: list[str]
) -> None:
tester.execute()
expected = ".venv (Activated)\n"
assert tester.io.fetch_output() == expected
......@@ -62,7 +64,7 @@ def test_in_project_venv(tester: CommandTester, venvs_in_project_dir: list[str])
def test_in_project_venv_no_explicit_config(
tester: CommandTester, venvs_in_project_dir_none: list[str]
):
) -> None:
tester.execute()
expected = ".venv (Activated)\n"
assert tester.io.fetch_output() == expected
......@@ -70,7 +72,7 @@ def test_in_project_venv_no_explicit_config(
def test_in_project_venv_is_false(
tester: CommandTester, venvs_in_project_dir_false: list[str]
):
) -> None:
tester.execute()
expected = ""
assert tester.io.fetch_output() == expected
......@@ -29,7 +29,7 @@ def test_remove_by_python_version(
venvs_in_cache_dirs: list[str],
venv_name: str,
venv_cache: Path,
):
) -> None:
check_output = mocker.patch(
"subprocess.check_output",
side_effect=check_output_wrapper(Version.parse("3.6.6")),
......@@ -49,7 +49,7 @@ def test_remove_by_name(
venvs_in_cache_dirs: list[str],
venv_name: str,
venv_cache: Path,
):
) -> None:
expected = ""
for name in venvs_in_cache_dirs:
......@@ -67,7 +67,7 @@ def test_remove_all(
venvs_in_cache_dirs: list[str],
venv_name: str,
venv_cache: Path,
):
) -> None:
expected = {""}
tester.execute("--all")
for name in venvs_in_cache_dirs:
......@@ -81,7 +81,7 @@ def test_remove_all_and_version(
venvs_in_cache_dirs: list[str],
venv_name: str,
venv_cache: Path,
):
) -> None:
expected = {""}
tester.execute(f"--all {venvs_in_cache_dirs[0]}")
for name in venvs_in_cache_dirs:
......@@ -95,7 +95,7 @@ def test_remove_multiple(
venvs_in_cache_dirs: list[str],
venv_name: str,
venv_cache: Path,
):
) -> None:
expected = {""}
removed_envs = venvs_in_cache_dirs[0:2]
remaining_envs = venvs_in_cache_dirs[2:]
......
......@@ -38,7 +38,7 @@ def assert_plugin_add_result(
def test_add_no_constraint(
tester: CommandTester,
repo: TestRepository,
):
) -> None:
repo.add_package(Package("poetry-plugin", "0.1.0"))
tester.execute("poetry-plugin")
......@@ -61,7 +61,7 @@ Writing lock file
def test_add_with_constraint(
tester: CommandTester,
repo: TestRepository,
):
) -> None:
repo.add_package(Package("poetry-plugin", "0.1.0"))
repo.add_package(Package("poetry-plugin", "0.2.0"))
......@@ -84,7 +84,7 @@ Writing lock file
def test_add_with_git_constraint(
tester: CommandTester,
repo: TestRepository,
):
) -> None:
repo.add_package(Package("pendulum", "2.0.5"))
tester.execute("git+https://github.com/demo/poetry-plugin.git")
......@@ -109,7 +109,7 @@ Writing lock file
def test_add_with_git_constraint_with_extras(
tester: CommandTester,
repo: TestRepository,
):
) -> None:
repo.add_package(Package("pendulum", "2.0.5"))
repo.add_package(Package("tomlkit", "0.7.0"))
......@@ -153,7 +153,7 @@ def test_add_with_git_constraint_with_subdirectory(
rev: str | None,
tester: CommandTester,
repo: TestRepository,
):
) -> None:
repo.add_package(Package("pendulum", "2.0.5"))
tester.execute(url)
......@@ -189,7 +189,7 @@ def test_add_existing_plugin_warns_about_no_operation(
tester: CommandTester,
repo: TestRepository,
installed: TestRepository,
):
) -> None:
pyproject = SelfCommand.get_default_system_pyproject_file()
with open(pyproject, "w", encoding="utf-8", newline="") as f:
f.write(
......@@ -230,7 +230,7 @@ def test_add_existing_plugin_updates_if_requested(
tester: CommandTester,
repo: TestRepository,
installed: TestRepository,
):
) -> None:
pyproject = SelfCommand.get_default_system_pyproject_file()
with open(pyproject, "w", encoding="utf-8", newline="") as f:
f.write(
......@@ -276,7 +276,7 @@ def test_adding_a_plugin_can_update_poetry_dependencies_if_needed(
tester: CommandTester,
repo: TestRepository,
installed: TestRepository,
):
) -> None:
poetry_package = Package("poetry", "1.2.0")
poetry_package.add_dependency(Factory.create_dependency("tomlkit", "^0.7.0"))
......
......@@ -66,7 +66,7 @@ def install_plugin(installed: Repository) -> None:
installed.add_package(plugin)
def test_remove_installed_package(tester: CommandTester):
def test_remove_installed_package(tester: CommandTester) -> None:
tester.execute("poetry-plugin")
expected = """\
......@@ -87,7 +87,7 @@ Writing lock file
assert not dependencies
def test_remove_installed_package_dry_run(tester: CommandTester):
def test_remove_installed_package_dry_run(tester: CommandTester) -> None:
tester.execute("poetry-plugin --dry-run")
expected = f"""\
......
......@@ -153,7 +153,7 @@ def mock_metadata_entry_points(
def test_show_displays_installed_plugins(
app: PoetryTestApplication,
tester: CommandTester,
):
) -> None:
tester.execute("")
expected = """
......@@ -179,7 +179,7 @@ def test_show_displays_installed_plugins(
def test_show_displays_installed_plugins_with_multiple_plugins(
app: PoetryTestApplication,
tester: CommandTester,
):
) -> None:
tester.execute("")
expected = """
......@@ -205,7 +205,7 @@ def test_show_displays_installed_plugins_with_multiple_plugins(
def test_show_displays_installed_plugins_with_dependencies(
app: PoetryTestApplication,
tester: CommandTester,
):
) -> None:
tester.execute("")
expected = """
......
......@@ -16,7 +16,7 @@ def tester(command_tester_factory: CommandTesterFactory) -> CommandTester:
return command_tester_factory("about")
def test_about(tester: CommandTester):
def test_about(tester: CommandTester) -> None:
from poetry.utils._compat import metadata
tester.execute()
......
......@@ -34,7 +34,7 @@ def tester(command_tester_factory: CommandTesterFactory) -> CommandTester:
def test_show_config_with_local_config_file_empty(
tester: CommandTester, mocker: MockerFixture
):
) -> None:
mocker.patch(
"poetry.factory.Factory.create_poetry",
side_effect=PyProjectException("[tool.poetry] section not found"),
......@@ -46,7 +46,7 @@ def test_show_config_with_local_config_file_empty(
def test_list_displays_default_value_if_not_set(
tester: CommandTester, config: Config, config_cache_dir: Path
):
) -> None:
tester.execute("--list")
cache_dir = json.dumps(str(config_cache_dir))
......@@ -74,7 +74,7 @@ virtualenvs.prompt = "{{project_name}}-py{{python_version}}"
def test_list_displays_set_get_setting(
tester: CommandTester, config: Config, config_cache_dir: Path
):
) -> None:
tester.execute("virtualenvs.create false")
tester.execute("--list")
......@@ -103,7 +103,7 @@ virtualenvs.prompt = "{{project_name}}-py{{python_version}}"
assert tester.io.fetch_output() == expected
def test_display_single_setting(tester: CommandTester, config: Config):
def test_display_single_setting(tester: CommandTester, config: Config) -> None:
tester.execute("virtualenvs.create")
expected = """true
......@@ -114,7 +114,7 @@ def test_display_single_setting(tester: CommandTester, config: Config):
def test_display_single_local_setting(
command_tester_factory: CommandTesterFactory, fixture_dir: FixtureDirGetter
):
) -> None:
tester = command_tester_factory(
"config", poetry=Factory().create_poetry(fixture_dir("with_local_config"))
)
......@@ -128,7 +128,7 @@ def test_display_single_local_setting(
def test_list_displays_set_get_local_setting(
tester: CommandTester, config: Config, config_cache_dir: Path
):
) -> None:
tester.execute("virtualenvs.create false --local")
tester.execute("--list")
......@@ -163,7 +163,7 @@ def test_list_must_not_display_sources_from_pyproject_toml(
command_tester_factory: CommandTesterFactory,
config: Config,
config_cache_dir: Path,
):
) -> None:
source = fixture_dir("with_non_default_source_implicit")
pyproject_content = (source / "pyproject.toml").read_text(encoding="utf-8")
poetry = project_factory("foo", pyproject_content=pyproject_content)
......@@ -195,7 +195,9 @@ virtualenvs.prompt = "{{project_name}}-py{{python_version}}"
assert tester.io.fetch_output() == expected
def test_set_pypi_token(tester: CommandTester, auth_config_source: DictConfigSource):
def test_set_pypi_token(
tester: CommandTester, auth_config_source: DictConfigSource
) -> None:
tester.execute("pypi-token.pypi mytoken")
tester.execute("--list")
......@@ -206,7 +208,7 @@ def test_set_client_cert(
tester: CommandTester,
auth_config_source: DictConfigSource,
mocker: MockerFixture,
):
) -> None:
mocker.spy(ConfigSource, "__init__")
tester.execute("certificates.foo.client-cert path/to/cert.pem")
......@@ -231,7 +233,7 @@ def test_set_cert(
mocker: MockerFixture,
value: str,
result: str | bool,
):
) -> None:
mocker.spy(ConfigSource, "__init__")
tester.execute(f"certificates.foo.cert {value}")
......@@ -241,7 +243,7 @@ def test_set_cert(
def test_config_installer_parallel(
tester: CommandTester, command_tester_factory: CommandTesterFactory
):
) -> None:
tester.execute("--local installer.parallel")
assert tester.io.fetch_output().strip() == "true"
......
......@@ -95,7 +95,7 @@ python = "~2.7 || ^3.6"
def test_basic_interactive(
tester: CommandTester, init_basic_inputs: str, init_basic_toml: str
):
) -> None:
tester.execute(inputs=init_basic_inputs)
assert init_basic_toml in tester.io.fetch_output()
......@@ -106,7 +106,7 @@ def test_noninteractive(
poetry: Poetry,
repo: TestRepository,
tmp_path: Path,
):
) -> None:
command = app.find("init")
command._pool = poetry.pool
......@@ -128,7 +128,9 @@ def test_noninteractive(
assert 'pytest = "^3.6.0"' in toml_content
def test_interactive_with_dependencies(tester: CommandTester, repo: TestRepository):
def test_interactive_with_dependencies(
tester: CommandTester, repo: TestRepository
) -> None:
repo.add_package(get_package("django-pendulum", "0.1.6-pre4"))
repo.add_package(get_package("pendulum", "2.0.0"))
repo.add_package(get_package("pytest", "3.6.0"))
......@@ -183,7 +185,7 @@ pytest = "^3.6.0"
# Regression test for https://github.com/python-poetry/poetry/issues/2355
def test_interactive_with_dependencies_and_no_selection(
tester: CommandTester, repo: TestRepository
):
) -> None:
repo.add_package(get_package("django-pendulum", "0.1.6-pre4"))
repo.add_package(get_package("pendulum", "2.0.0"))
repo.add_package(get_package("pytest", "3.6.0"))
......@@ -224,7 +226,7 @@ python = "~2.7 || ^3.6"
assert expected in tester.io.fetch_output()
def test_empty_license(tester: CommandTester):
def test_empty_license(tester: CommandTester) -> None:
inputs = [
"my-package", # Package name
"1.2.3", # Version
......@@ -254,7 +256,9 @@ python = "^{python}"
assert expected in tester.io.fetch_output()
def test_interactive_with_git_dependencies(tester: CommandTester, repo: TestRepository):
def test_interactive_with_git_dependencies(
tester: CommandTester, repo: TestRepository
) -> None:
repo.add_package(get_package("pendulum", "2.0.0"))
repo.add_package(get_package("pytest", "3.6.0"))
......@@ -332,7 +336,7 @@ def test_generate_choice_list(
tester: CommandTester,
package_name: str,
_generate_choice_list_packages: list[Package],
):
) -> None:
init_command = tester.command
packages = _generate_choice_list_packages
......@@ -345,7 +349,7 @@ def test_generate_choice_list(
def test_interactive_with_git_dependencies_with_reference(
tester: CommandTester, repo: TestRepository
):
) -> None:
repo.add_package(get_package("pendulum", "2.0.0"))
repo.add_package(get_package("pytest", "3.6.0"))
......@@ -391,7 +395,7 @@ pytest = "^3.6.0"
def test_interactive_with_git_dependencies_and_other_name(
tester: CommandTester, repo: TestRepository
):
) -> None:
repo.add_package(get_package("pendulum", "2.0.0"))
repo.add_package(get_package("pytest", "3.6.0"))
......@@ -440,7 +444,7 @@ def test_interactive_with_directory_dependency(
repo: TestRepository,
source_dir: Path,
fixture_dir: FixtureDirGetter,
):
) -> None:
repo.add_package(get_package("pendulum", "2.0.0"))
repo.add_package(get_package("pytest", "3.6.0"))
......@@ -491,7 +495,7 @@ def test_interactive_with_directory_dependency_and_other_name(
repo: TestRepository,
source_dir: Path,
fixture_dir: FixtureDirGetter,
):
) -> None:
repo.add_package(get_package("pendulum", "2.0.0"))
repo.add_package(get_package("pytest", "3.6.0"))
......@@ -543,7 +547,7 @@ def test_interactive_with_file_dependency(
repo: TestRepository,
source_dir: Path,
fixture_dir: FixtureDirGetter,
):
) -> None:
repo.add_package(get_package("pendulum", "2.0.0"))
repo.add_package(get_package("pytest", "3.6.0"))
......@@ -592,7 +596,7 @@ pytest = "^3.6.0"
def test_interactive_with_wrong_dependency_inputs(
tester: CommandTester, repo: TestRepository
):
) -> None:
inputs = [
"my-package", # Package name
"1.2.3", # Version
......@@ -636,7 +640,7 @@ pytest = "3.6.0"
assert expected in tester.io.fetch_output()
def test_python_option(tester: CommandTester):
def test_python_option(tester: CommandTester) -> None:
inputs = [
"my-package", # Package name
"1.2.3", # Version
......@@ -666,7 +670,7 @@ python = "~2.7 || ^3.6"
assert expected in tester.io.fetch_output()
def test_predefined_dependency(tester: CommandTester, repo: TestRepository):
def test_predefined_dependency(tester: CommandTester, repo: TestRepository) -> None:
repo.add_package(get_package("pendulum", "2.0.0"))
inputs = [
......@@ -702,7 +706,7 @@ pendulum = "^2.0.0"
def test_predefined_and_interactive_dependencies(
tester: CommandTester, repo: TestRepository
):
) -> None:
repo.add_package(get_package("pendulum", "2.0.0"))
repo.add_package(get_package("pyramid", "1.10"))
......@@ -743,7 +747,7 @@ python = "~2.7 || ^3.6"
assert 'pyramid = "^1.10"' in output
def test_predefined_dev_dependency(tester: CommandTester, repo: TestRepository):
def test_predefined_dev_dependency(tester: CommandTester, repo: TestRepository) -> None:
repo.add_package(get_package("pytest", "3.6.0"))
inputs = [
......@@ -782,7 +786,7 @@ pytest = "^3.6.0"
def test_predefined_and_interactive_dev_dependencies(
tester: CommandTester, repo: TestRepository
):
) -> None:
repo.add_package(get_package("pytest", "3.6.0"))
repo.add_package(get_package("pytest-requests", "0.2.0"))
......@@ -828,7 +832,7 @@ pytest-requests = "^0.2.0"
assert 'pytest = "^3.6.0"' in output
def test_predefined_all_options(tester: CommandTester, repo: TestRepository):
def test_predefined_all_options(tester: CommandTester, repo: TestRepository) -> None:
repo.add_package(get_package("pendulum", "2.0.0"))
repo.add_package(get_package("pytest", "3.6.0"))
......@@ -875,7 +879,7 @@ pytest = "^3.6.0"
assert expected in output
def test_add_package_with_extras_and_whitespace(tester: CommandTester):
def test_add_package_with_extras_and_whitespace(tester: CommandTester) -> None:
result = tester.command._parse_requirements(["databases[postgresql, sqlite]"])
assert result[0]["name"] == "databases"
......@@ -889,7 +893,7 @@ def test_init_existing_pyproject_simple(
source_dir: Path,
init_basic_inputs: str,
init_basic_toml: str,
):
) -> None:
pyproject_file = source_dir / "pyproject.toml"
existing_section = """
[tool.black]
......@@ -907,7 +911,7 @@ def test_init_existing_pyproject_consistent_linesep(
init_basic_inputs: str,
init_basic_toml: str,
linesep: str,
):
) -> None:
pyproject_file = source_dir / "pyproject.toml"
existing_section = """
[tool.black]
......@@ -929,7 +933,7 @@ def test_init_non_interactive_existing_pyproject_add_dependency(
source_dir: Path,
init_basic_inputs: str,
repo: TestRepository,
):
) -> None:
pyproject_file = source_dir / "pyproject.toml"
existing_section = """
[tool.black]
......@@ -967,7 +971,7 @@ foo = "^1.19.2"
def test_init_existing_pyproject_with_build_system_fails(
tester: CommandTester, source_dir: Path, init_basic_inputs: str
):
) -> None:
pyproject_file = source_dir / "pyproject.toml"
existing_section = """
[build-system]
......@@ -997,14 +1001,14 @@ build-backend = "setuptools.build_meta"
" foo 2.0 ",
],
)
def test__validate_package_valid(name: str | None):
def test_validate_package_valid(name: str | None) -> None:
assert InitCommand._validate_package(name) == name
@pytest.mark.parametrize(
"name", ["foo bar 2.0", " foo bar 2.0 ", "foo bar foobar 2.0"]
)
def test__validate_package_invalid(name: str):
def test_validate_package_invalid(name: str) -> None:
with pytest.raises(ValueError):
assert InitCommand._validate_package(name)
......@@ -1023,7 +1027,7 @@ def test_package_include(
tester: CommandTester,
package_name: str,
include: str | None,
):
) -> None:
tester.execute(
inputs="\n".join(
(
......@@ -1074,7 +1078,7 @@ def test_respect_prefer_active_on_init(
mocker: MockerFixture,
tester: CommandTester,
source_dir: Path,
):
) -> None:
from poetry.utils.env import GET_PYTHON_VERSION_ONELINER
orig_check_output = subprocess.check_output
......
......@@ -119,7 +119,7 @@ def test_group_options_are_passed_to_the_installer(
with_root: bool,
tester: CommandTester,
mocker: MockerFixture,
):
) -> None:
"""
Group options are passed properly to the installer.
"""
......@@ -155,7 +155,7 @@ def test_group_options_are_passed_to_the_installer(
def test_sync_option_is_passed_to_the_installer(
tester: CommandTester, mocker: MockerFixture
):
) -> None:
"""
The --sync option is passed properly to the installer.
"""
......@@ -169,7 +169,7 @@ def test_sync_option_is_passed_to_the_installer(
@pytest.mark.parametrize("compile", [False, True])
def test_compile_option_is_passed_to_the_installer(
tester: CommandTester, mocker: MockerFixture, compile: bool
):
) -> None:
"""
The --compile option is passed properly to the installer.
"""
......@@ -187,7 +187,7 @@ def test_compile_option_is_passed_to_the_installer(
@pytest.mark.parametrize("skip_directory_cli_value", [True, False])
def test_no_directory_is_passed_to_installer(
tester: CommandTester, mocker: MockerFixture, skip_directory_cli_value: bool
):
) -> None:
"""
The --no-directory option is passed to the installer.
"""
......@@ -204,7 +204,7 @@ def test_no_directory_is_passed_to_installer(
def test_no_all_extras_doesnt_populate_installer(
tester: CommandTester, mocker: MockerFixture
):
) -> None:
"""
Not passing --all-extras means the installer doesn't see any extras.
"""
......@@ -215,7 +215,9 @@ def test_no_all_extras_doesnt_populate_installer(
assert not tester.command.installer._extras
def test_all_extras_populates_installer(tester: CommandTester, mocker: MockerFixture):
def test_all_extras_populates_installer(
tester: CommandTester, mocker: MockerFixture
) -> None:
"""
The --all-extras option results in extras passed to the installer.
"""
......@@ -229,7 +231,7 @@ def test_all_extras_populates_installer(tester: CommandTester, mocker: MockerFix
def test_extras_are_parsed_and_populate_installer(
tester: CommandTester,
mocker: MockerFixture,
):
) -> None:
mocker.patch.object(tester.command.installer, "run", return_value=0)
tester.execute('--extras "first second third"')
......@@ -237,7 +239,9 @@ def test_extras_are_parsed_and_populate_installer(
assert tester.command.installer._extras == ["first", "second", "third"]
def test_extras_conflicts_all_extras(tester: CommandTester, mocker: MockerFixture):
def test_extras_conflicts_all_extras(
tester: CommandTester, mocker: MockerFixture
) -> None:
"""
The --extras doesn't make sense with --all-extras.
"""
......@@ -266,7 +270,7 @@ def test_only_root_conflicts_with_without_only(
options: str,
tester: CommandTester,
mocker: MockerFixture,
):
) -> None:
mocker.patch.object(tester.command.installer, "run", return_value=0)
tester.execute(f"{options} --only-root")
......@@ -300,7 +304,7 @@ def test_invalid_groups_with_without_only(
options: dict[str, str],
valid_groups: set[str],
should_raise: bool,
):
) -> None:
mocker.patch.object(tester.command.installer, "run", return_value=0)
cmd_args = " ".join(f"{flag} {groups}" for (flag, groups) in options.items())
......@@ -324,7 +328,7 @@ def test_invalid_groups_with_without_only(
def test_remove_untracked_outputs_deprecation_warning(
tester: CommandTester,
mocker: MockerFixture,
):
) -> None:
mocker.patch.object(tester.command.installer, "run", return_value=0)
tester.execute("--remove-untracked")
......@@ -337,7 +341,9 @@ def test_remove_untracked_outputs_deprecation_warning(
)
def test_dry_run_populates_installer(tester: CommandTester, mocker: MockerFixture):
def test_dry_run_populates_installer(
tester: CommandTester, mocker: MockerFixture
) -> None:
"""
The --dry-run option results in extras passed to the installer.
"""
......@@ -349,7 +355,7 @@ def test_dry_run_populates_installer(tester: CommandTester, mocker: MockerFixtur
assert tester.command.installer._dry_run is True
def test_dry_run_does_not_build(tester: CommandTester, mocker: MockerFixture):
def test_dry_run_does_not_build(tester: CommandTester, mocker: MockerFixture) -> None:
mocker.patch.object(tester.command.installer, "run", return_value=0)
mocked_editable_builder = mocker.patch(
"poetry.masonry.builders.editable.EditableBuilder"
......@@ -360,7 +366,7 @@ def test_dry_run_does_not_build(tester: CommandTester, mocker: MockerFixture):
assert mocked_editable_builder.return_value.build.call_count == 0
def test_install_logs_output(tester: CommandTester, mocker: MockerFixture):
def test_install_logs_output(tester: CommandTester, mocker: MockerFixture) -> None:
mocker.patch.object(tester.command.installer, "run", return_value=0)
mocker.patch("poetry.masonry.builders.editable.EditableBuilder")
......@@ -373,7 +379,9 @@ def test_install_logs_output(tester: CommandTester, mocker: MockerFixture):
)
def test_install_logs_output_decorated(tester: CommandTester, mocker: MockerFixture):
def test_install_logs_output_decorated(
tester: CommandTester, mocker: MockerFixture
) -> None:
mocker.patch.object(tester.command.installer, "run", return_value=0)
mocker.patch("poetry.masonry.builders.editable.EditableBuilder")
......@@ -402,7 +410,7 @@ def test_install_path_dependency_does_not_exist(
fixture_dir: FixtureDirGetter,
project: str,
options: str,
):
) -> None:
poetry = _project_factory(project, project_factory, fixture_dir)
poetry.locker.locked(True)
tester = command_tester_factory("install", poetry=poetry)
......
......@@ -93,7 +93,7 @@ def test_lock_check_outdated(
command_tester_factory: CommandTesterFactory,
poetry_with_outdated_lockfile: Poetry,
http: type[httpretty.httpretty],
):
) -> None:
http.disable()
locker = Locker(
......@@ -119,7 +119,7 @@ def test_lock_check_up_to_date(
command_tester_factory: CommandTesterFactory,
poetry_with_up_to_date_lockfile: Poetry,
http: type[httpretty.httpretty],
):
) -> None:
http.disable()
locker = Locker(
......@@ -141,7 +141,7 @@ def test_lock_no_update(
command_tester_factory: CommandTesterFactory,
poetry_with_old_lockfile: Poetry,
repo: TestRepository,
):
) -> None:
repo.add_package(get_package("sampleproject", "1.3.1"))
repo.add_package(get_package("sampleproject", "2.0.0"))
......@@ -178,7 +178,7 @@ def test_lock_no_update_path_dependencies(
command_tester_factory: CommandTesterFactory,
poetry_with_nested_path_deps_old_lockfile: Poetry,
repo: TestRepository,
):
) -> None:
"""
The lock file contains a variant of the directory dependency "quix" that does
not depend on "sampleproject". Although the version of "quix" has not been changed,
......@@ -214,7 +214,7 @@ def test_lock_path_dependency_does_not_exist(
fixture_dir: FixtureDirGetter,
project: str,
update: bool,
):
) -> None:
poetry = _project_factory(project, project_factory, fixture_dir)
locker = Locker(
lock=poetry.pyproject.file.path.parent / "poetry.lock",
......@@ -242,7 +242,7 @@ def test_lock_path_dependency_deleted_from_pyproject(
fixture_dir: FixtureDirGetter,
project: str,
update: bool,
):
) -> None:
poetry = _project_factory(project, project_factory, fixture_dir)
locker = Locker(
lock=poetry.pyproject.file.path.parent / "poetry.lock",
......
......@@ -156,7 +156,7 @@ def test_command_new(
include_from: str | None,
tester: CommandTester,
tmp_path: Path,
):
) -> None:
path = tmp_path / directory
options.append(str(path))
tester.execute(" ".join(options))
......@@ -166,7 +166,7 @@ def test_command_new(
@pytest.mark.parametrize(("fmt",), [(None,), ("md",), ("rst",), ("adoc",), ("creole",)])
def test_command_new_with_readme(
fmt: str | None, tester: CommandTester, tmp_path: Path
):
) -> None:
package = "package"
path = tmp_path / package
options = [path.as_posix()]
......@@ -194,7 +194,7 @@ def test_respect_prefer_active_on_new(
mocker: MockerFixture,
tester: CommandTester,
tmp_path: Path,
):
) -> None:
from poetry.utils.env import GET_PYTHON_VERSION_ONELINER
orig_check_output = subprocess.check_output
......
......@@ -23,7 +23,7 @@ def test_publish_returns_non_zero_code_for_upload_errors(
app: PoetryTestApplication,
app_tester: ApplicationTester,
http: type[httpretty.httpretty],
):
) -> None:
http.register_uri(
http.POST, "https://upload.pypi.org/legacy/", status=400, body="Bad Request"
)
......@@ -48,7 +48,7 @@ def test_publish_returns_non_zero_code_for_connection_errors(
app: PoetryTestApplication,
app_tester: ApplicationTester,
http: type[httpretty.httpretty],
):
) -> None:
def request_callback(*_: Any, **__: Any) -> None:
raise requests.ConnectionError()
......@@ -65,7 +65,9 @@ def test_publish_returns_non_zero_code_for_connection_errors(
assert expected in app_tester.io.fetch_error()
def test_publish_with_cert(app_tester: ApplicationTester, mocker: MockerFixture):
def test_publish_with_cert(
app_tester: ApplicationTester, mocker: MockerFixture
) -> None:
publisher_publish = mocker.patch("poetry.publishing.Publisher.publish")
app_tester.execute("publish --cert path/to/ca.pem")
......@@ -75,7 +77,9 @@ def test_publish_with_cert(app_tester: ApplicationTester, mocker: MockerFixture)
] == publisher_publish.call_args
def test_publish_with_client_cert(app_tester: ApplicationTester, mocker: MockerFixture):
def test_publish_with_client_cert(
app_tester: ApplicationTester, mocker: MockerFixture
) -> None:
publisher_publish = mocker.patch("poetry.publishing.Publisher.publish")
app_tester.execute("publish --client-cert path/to/client.pem")
......@@ -94,7 +98,7 @@ def test_publish_with_client_cert(app_tester: ApplicationTester, mocker: MockerF
)
def test_publish_dry_run_skip_existing(
app_tester: ApplicationTester, http: type[httpretty.httpretty], options: str
):
) -> None:
http.register_uri(
http.POST, "https://upload.pypi.org/legacy/", status=409, body="Conflict"
)
......@@ -113,7 +117,7 @@ def test_publish_dry_run_skip_existing(
def test_skip_existing_output(
app_tester: ApplicationTester, http: type[httpretty.httpretty]
):
) -> None:
http.register_uri(
http.POST, "https://upload.pypi.org/legacy/", status=409, body="Conflict"
)
......
......@@ -48,7 +48,7 @@ def test_remove_without_specific_group_removes_from_all_groups(
repo: TestRepository,
command_tester_factory: CommandTesterFactory,
installed: Repository,
):
) -> None:
"""
Removing without specifying a group removes packages from all groups.
"""
......@@ -105,7 +105,7 @@ def test_remove_without_specific_group_removes_from_specific_groups(
repo: TestRepository,
command_tester_factory: CommandTesterFactory,
installed: Repository,
):
) -> None:
"""
Removing with a specific group given removes packages only from this group.
"""
......@@ -162,7 +162,7 @@ def test_remove_does_not_live_empty_groups(
repo: TestRepository,
command_tester_factory: CommandTesterFactory,
installed: Repository,
):
) -> None:
"""
Empty groups are automatically discarded after package removal.
"""
......@@ -208,7 +208,7 @@ def test_remove_canonicalized_named_removes_dependency_correctly(
repo: TestRepository,
command_tester_factory: CommandTesterFactory,
installed: Repository,
):
) -> None:
"""
Removing a dependency using a canonicalized named removes the dependency.
"""
......@@ -267,7 +267,7 @@ def test_remove_command_should_not_write_changes_upon_installer_errors(
repo: TestRepository,
command_tester_factory: CommandTesterFactory,
mocker: MockerFixture,
):
) -> None:
repo.add_package(Package("foo", "2.0.0"))
command_tester_factory("add").execute("foo")
......@@ -285,7 +285,7 @@ def test_remove_with_dry_run_keep_files_intact(
poetry_with_up_to_date_lockfile: Poetry,
repo: TestRepository,
command_tester_factory: CommandTesterFactory,
):
) -> None:
tester = command_tester_factory("remove", poetry=poetry_with_up_to_date_lockfile)
original_pyproject_content = poetry_with_up_to_date_lockfile.file.read()
......
......@@ -45,14 +45,14 @@ def poetry_with_scripts(
)
def test_run_passes_all_args(app_tester: ApplicationTester, env: MockEnv):
def test_run_passes_all_args(app_tester: ApplicationTester, env: MockEnv) -> None:
app_tester.execute("run python -V")
assert [["python", "-V"]] == env.executed
def test_run_keeps_options_passed_before_command(
app_tester: ApplicationTester, env: MockEnv
):
) -> None:
app_tester.execute("-V --no-ansi run python", decorated=True)
assert not app_tester.io.is_decorated()
......@@ -64,7 +64,7 @@ def test_run_keeps_options_passed_before_command(
def test_run_has_helpful_error_when_command_not_found(
app_tester: ApplicationTester, env: MockEnv, capfd: pytest.CaptureFixture[str]
):
) -> None:
nonexistent_command = "nonexistent-command"
env._execute = True
app_tester.execute(f"run {nonexistent_command}")
......@@ -94,7 +94,7 @@ def test_run_has_helpful_error_when_command_not_found(
def test_run_console_scripts_of_editable_dependencies_on_windows(
tmp_venv: VirtualEnv,
command_tester_factory: CommandTesterFactory,
):
) -> None:
"""
On Windows, Poetry installs console scripts of editable dependencies by creating
in the environment's `Scripts/` directory both:
......
......@@ -20,7 +20,7 @@ def tester(command_tester_factory: CommandTesterFactory) -> CommandTester:
return command_tester_factory("shell")
def test_shell(tester: CommandTester, mocker: MockerFixture):
def test_shell(tester: CommandTester, mocker: MockerFixture) -> None:
shell_activate = mocker.patch("poetry.utils.shell.Shell.activate")
tester.execute()
......@@ -32,7 +32,7 @@ def test_shell(tester: CommandTester, mocker: MockerFixture):
assert tester.status_code == 0
def test_shell_already_active(tester: CommandTester, mocker: MockerFixture):
def test_shell_already_active(tester: CommandTester, mocker: MockerFixture) -> None:
os.environ["POETRY_ACTIVE"] = "1"
shell_activate = mocker.patch("poetry.utils.shell.Shell.activate")
......@@ -71,7 +71,7 @@ def test__is_venv_activated(
real_prefix: str | None,
prefix: str,
expected: bool,
):
) -> None:
mocker.patch.object(tester.command.env, "_path", Path("foobar"))
mocker.patch("sys.prefix", prefix)
......
......@@ -40,7 +40,7 @@ def test_update_with_dry_run_keep_files_intact(
poetry_with_up_to_date_lockfile: Poetry,
repo: TestRepository,
command_tester_factory: CommandTesterFactory,
):
) -> None:
tester = command_tester_factory("update", poetry=poetry_with_up_to_date_lockfile)
original_pyproject_content = poetry_with_up_to_date_lockfile.file.read()
......
......@@ -51,31 +51,31 @@ def tester(command_tester_factory: CommandTesterFactory) -> CommandTester:
)
def test_increment_version(
version: str, rule: str, expected: str, command: VersionCommand
):
) -> None:
assert command.increment_version(version, rule).text == expected
def test_version_show(tester: CommandTester):
def test_version_show(tester: CommandTester) -> None:
tester.execute()
assert tester.io.fetch_output() == "simple-project 1.2.3\n"
def test_short_version_show(tester: CommandTester):
def test_short_version_show(tester: CommandTester) -> None:
tester.execute("--short")
assert tester.io.fetch_output() == "1.2.3\n"
def test_version_update(tester: CommandTester):
def test_version_update(tester: CommandTester) -> None:
tester.execute("2.0.0")
assert tester.io.fetch_output() == "Bumping version from 1.2.3 to 2.0.0\n"
def test_short_version_update(tester: CommandTester):
def test_short_version_update(tester: CommandTester) -> None:
tester.execute("--short 2.0.0")
assert tester.io.fetch_output() == "2.0.0\n"
def test_dry_run(tester: CommandTester):
def test_dry_run(tester: CommandTester) -> None:
old_pyproject = tester.command.poetry.file.path.read_text()
tester.execute("--dry-run major")
......
......@@ -39,7 +39,7 @@ def with_add_command_plugin(mocker: MockerFixture) -> None:
mock_metadata_entry_points(mocker, AddCommandPlugin)
def test_application_with_plugins(with_add_command_plugin: None):
def test_application_with_plugins(with_add_command_plugin: None) -> None:
app = Application()
tester = ApplicationTester(app)
......@@ -49,7 +49,7 @@ def test_application_with_plugins(with_add_command_plugin: None):
assert tester.status_code == 0
def test_application_with_plugins_disabled(with_add_command_plugin: None):
def test_application_with_plugins_disabled(with_add_command_plugin: None) -> None:
app = Application()
tester = ApplicationTester(app)
......@@ -59,7 +59,7 @@ def test_application_with_plugins_disabled(with_add_command_plugin: None):
assert tester.status_code == 0
def test_application_execute_plugin_command(with_add_command_plugin: None):
def test_application_execute_plugin_command(with_add_command_plugin: None) -> None:
app = Application()
tester = ApplicationTester(app)
......@@ -71,7 +71,7 @@ def test_application_execute_plugin_command(with_add_command_plugin: None):
def test_application_execute_plugin_command_with_plugins_disabled(
with_add_command_plugin: None,
):
) -> None:
app = Application()
tester = ApplicationTester(app)
......@@ -83,7 +83,7 @@ def test_application_execute_plugin_command_with_plugins_disabled(
@pytest.mark.parametrize("disable_cache", [True, False])
def test_application_verify_source_cache_flag(disable_cache: bool):
def test_application_verify_source_cache_flag(disable_cache: bool) -> None:
app = Application()
tester = ApplicationTester(app)
......
......@@ -68,7 +68,7 @@ def test_prepare_directory(
config_cache_dir: Path,
artifact_cache: ArtifactCache,
fixture_dir: FixtureDirGetter,
):
) -> None:
chef = Chef(
artifact_cache, EnvManager.get_system_env(), Factory.create_pool(config)
)
......@@ -107,7 +107,7 @@ def test_prepare_directory_editable(
config_cache_dir: Path,
artifact_cache: ArtifactCache,
fixture_dir: FixtureDirGetter,
):
) -> None:
chef = Chef(
artifact_cache, EnvManager.get_system_env(), Factory.create_pool(config)
)
......
......@@ -203,7 +203,7 @@ def test_execute_executes_a_batch_of_operations(
env: MockEnv,
copy_wheel: Callable[[], Path],
fixture_dir: FixtureDirGetter,
):
) -> None:
wheel_install = mocker.patch.object(WheelInstaller, "install")
config.merge({"cache-dir": str(tmp_path)})
......@@ -314,7 +314,7 @@ def test_execute_prints_warning_for_yanked_package(
env: MockEnv,
operations: list[Operation],
has_warning: bool,
):
) -> None:
config.merge({"cache-dir": str(tmp_path)})
executor = Executor(env, pool, config, io)
......@@ -345,7 +345,7 @@ def test_execute_prints_warning_for_invalid_wheels(
tmp_path: Path,
mock_file_downloads: None,
env: MockEnv,
):
) -> None:
config.merge({"cache-dir": str(tmp_path)})
executor = Executor(env, pool, config, io)
......@@ -404,7 +404,7 @@ def test_execute_shows_skipped_operations_if_verbose(
io: BufferedIO,
config_cache_dir: Path,
env: MockEnv,
):
) -> None:
config.merge({"cache-dir": config_cache_dir.as_posix()})
executor = Executor(env, pool, config, io)
......@@ -432,7 +432,7 @@ def test_execute_should_show_errors(
mocker: MockerFixture,
io: BufferedIO,
env: MockEnv,
):
) -> None:
executor = Executor(env, pool, config, io)
executor.verbose()
......@@ -460,7 +460,7 @@ def test_execute_works_with_ansi_output(
tmp_path: Path,
mock_file_downloads: None,
env: MockEnv,
):
) -> None:
config.merge({"cache-dir": str(tmp_path)})
executor = Executor(env, pool, config, io_decorated)
......@@ -497,7 +497,7 @@ def test_execute_works_with_no_ansi_output(
tmp_path: Path,
mock_file_downloads: None,
env: MockEnv,
):
) -> None:
config.merge({"cache-dir": str(tmp_path)})
executor = Executor(env, pool, config, io_not_decorated)
......@@ -525,7 +525,7 @@ def test_execute_should_show_operation_as_cancelled_on_subprocess_keyboard_inter
mocker: MockerFixture,
io: BufferedIO,
env: MockEnv,
):
) -> None:
executor = Executor(env, pool, config, io)
executor.verbose()
......@@ -550,7 +550,7 @@ def test_execute_should_gracefully_handle_io_error(
mocker: MockerFixture,
io: BufferedIO,
env: MockEnv,
):
) -> None:
executor = Executor(env, pool, config, io)
executor.verbose()
......@@ -584,7 +584,7 @@ def test_executor_should_delete_incomplete_downloads(
mock_file_downloads: None,
env: MockEnv,
fixture_dir: FixtureDirGetter,
):
) -> None:
fixture = fixture_dir("distributions") / "demo-0.1.0-py2.py3-none-any.whl"
destination_fixture = tmp_path / "tomlkit-0.5.3-py2.py3-none-any.whl"
shutil.copyfile(str(fixture), str(destination_fixture))
......@@ -613,7 +613,7 @@ def test_executor_should_delete_incomplete_downloads(
def verify_installed_distribution(
venv: VirtualEnv, package: Package, url_reference: dict[str, Any] | None = None
):
) -> None:
distributions = list(venv.site_packages.distributions(name=package.name))
assert len(distributions) == 1
......@@ -660,7 +660,7 @@ def test_executor_should_not_write_pep610_url_references_for_cached_package(
pool: RepositoryPool,
config: Config,
io: BufferedIO,
):
) -> None:
link_cached = fixture_dir("distributions") / "demo-0.1.0-py2.py3-none-any.whl"
package.files = [
{
......@@ -685,7 +685,7 @@ def test_executor_should_write_pep610_url_references_for_wheel_files(
config: Config,
io: BufferedIO,
fixture_dir: FixtureDirGetter,
):
) -> None:
url = (fixture_dir("distributions") / "demo-0.1.0-py2.py3-none-any.whl").resolve()
package = Package("demo", "0.1.0", source_type="file", source_url=url.as_posix())
# Set package.files so the executor will attempt to hash the package
......@@ -718,7 +718,7 @@ def test_executor_should_write_pep610_url_references_for_non_wheel_files(
config: Config,
io: BufferedIO,
fixture_dir: FixtureDirGetter,
):
) -> None:
url = (fixture_dir("distributions") / "demo-0.1.0.tar.gz").resolve()
package = Package("demo", "0.1.0", source_type="file", source_url=url.as_posix())
# Set package.files so the executor will attempt to hash the package
......@@ -754,7 +754,7 @@ def test_executor_should_write_pep610_url_references_for_directories(
wheel: Path,
fixture_dir: FixtureDirGetter,
mocker: MockerFixture,
):
) -> None:
url = (fixture_dir("git") / "github.com" / "demo" / "demo").resolve()
package = Package(
"demo", "0.1.2", source_type="directory", source_url=url.as_posix()
......@@ -782,7 +782,7 @@ def test_executor_should_write_pep610_url_references_for_editable_directories(
wheel: Path,
fixture_dir: FixtureDirGetter,
mocker: MockerFixture,
):
) -> None:
url = (fixture_dir("git") / "github.com" / "demo" / "demo").resolve()
package = Package(
"demo",
......@@ -815,7 +815,7 @@ def test_executor_should_write_pep610_url_references_for_wheel_urls(
mocker: MockerFixture,
fixture_dir: FixtureDirGetter,
is_artifact_cached: bool,
):
) -> None:
if is_artifact_cached:
link_cached = fixture_dir("distributions") / "demo-0.1.0-py2.py3-none-any.whl"
mocker.patch(
......@@ -887,7 +887,7 @@ def test_executor_should_write_pep610_url_references_for_non_wheel_urls(
is_wheel_cached: bool,
expect_artifact_building: bool,
expect_artifact_download: bool,
):
) -> None:
built_wheel = fixture_dir("distributions") / "demo-0.1.0-py2.py3-none-any.whl"
mock_prepare = mocker.patch(
"poetry.installation.chef.Chef._prepare",
......@@ -899,7 +899,9 @@ def test_executor_should_write_pep610_url_references_for_non_wheel_urls(
cached_sdist = fixture_dir("distributions") / "demo-0.1.0.tar.gz"
cached_wheel = fixture_dir("distributions") / "demo-0.1.0-py2.py3-none-any.whl"
def mock_get_cached_archive_for_link_func(_: Link, *, strict: bool, **__: Any):
def mock_get_cached_archive_for_link_func(
_: Link, *, strict: bool, **__: Any
) -> None:
if is_wheel_cached and not strict:
return cached_wheel
if is_sdist_cached:
......@@ -966,7 +968,7 @@ def test_executor_should_write_pep610_url_references_for_git(
mocker: MockerFixture,
fixture_dir: FixtureDirGetter,
is_artifact_cached: bool,
):
) -> None:
if is_artifact_cached:
link_cached = fixture_dir("distributions") / "demo-0.1.2-py2.py3-none-any.whl"
mocker.patch(
......@@ -1029,7 +1031,7 @@ def test_executor_should_write_pep610_url_references_for_editable_git(
wheel: Path,
mocker: MockerFixture,
fixture_dir: FixtureDirGetter,
):
) -> None:
source_resolved_reference = "123456"
source_url = "https://github.com/demo/demo.git"
......@@ -1106,7 +1108,7 @@ def test_executor_should_write_pep610_url_references_for_git_with_subdirectories
io: BufferedIO,
mock_file_downloads: None,
wheel: Path,
):
) -> None:
package = Package(
"demo",
"0.1.2",
......@@ -1159,7 +1161,7 @@ def test_executor_should_be_initialized_with_correct_workers(
cpu_count: int | None,
side_effect: Exception | None,
expected_workers: int,
):
) -> None:
config.merge({"installer": {"max-workers": max_workers}})
mocker.patch("os.cpu_count", return_value=cpu_count, side_effect=side_effect)
......@@ -1178,7 +1180,7 @@ def test_executor_fallback_on_poetry_create_error_without_wheel_installer(
mock_file_downloads: None,
env: MockEnv,
fixture_dir: FixtureDirGetter,
):
) -> None:
mock_pip_install = mocker.patch("poetry.installation.executor.pip_install")
mock_sdist_builder = mocker.patch("poetry.core.masonry.builders.sdist.SdistBuilder")
mock_editable_builder = mocker.patch(
......
......@@ -112,7 +112,7 @@ def remote_default_branch(remote_default_ref: bytes) -> str:
# Regression test for https://github.com/python-poetry/poetry/issues/6722
def test_use_system_git_client_from_environment_variables():
def test_use_system_git_client_from_environment_variables() -> None:
os.environ["POETRY_EXPERIMENTAL_SYSTEM_GIT_CLIENT"] = "true"
assert Git.is_using_legacy_client()
......@@ -132,7 +132,7 @@ def test_git_clone_default_branch_head(
remote_refs: FetchPackResult,
remote_default_ref: bytes,
mocker: MockerFixture,
):
) -> None:
spy = mocker.spy(Git, "_clone")
spy_legacy = mocker.spy(Git, "_clone_legacy")
......@@ -143,7 +143,7 @@ def test_git_clone_default_branch_head(
spy.assert_called()
def test_git_clone_fails_for_non_existent_branch(source_url: str):
def test_git_clone_fails_for_non_existent_branch(source_url: str) -> None:
branch = uuid.uuid4().hex
with pytest.raises(PoetryConsoleError) as e:
......@@ -152,7 +152,7 @@ def test_git_clone_fails_for_non_existent_branch(source_url: str):
assert f"Failed to clone {source_url} at '{branch}'" in str(e.value)
def test_git_clone_fails_for_non_existent_revision(source_url: str):
def test_git_clone_fails_for_non_existent_revision(source_url: str) -> None:
revision = sha1(uuid.uuid4().bytes).hexdigest()
with pytest.raises(PoetryConsoleError) as e:
......
from __future__ import annotations
from pathlib import Path
from typing import TYPE_CHECKING
import pytest
......@@ -17,6 +18,7 @@ from tests.helpers import mock_metadata_entry_points
if TYPE_CHECKING:
from cleo.io.io import IO
from pytest_mock import MockerFixture
from tests.conftest import Config
......@@ -29,9 +31,9 @@ class ManagerFactory(Protocol):
class MyPlugin(Plugin):
def activate(self, poetry: Poetry, io: BufferedIO) -> None:
def activate(self, poetry: Poetry, io: IO) -> None:
io.write_line("Setting readmes")
poetry.package.readmes = ("README.md",)
poetry.package.readmes = (Path("README.md"),)
class MyCommandPlugin(ApplicationPlugin):
......@@ -39,7 +41,7 @@ class MyCommandPlugin(ApplicationPlugin):
class InvalidPlugin:
def activate(self, poetry: Poetry, io: BufferedIO) -> None:
def activate(self, poetry: Poetry, io: IO) -> None:
io.write_line("Updating version")
poetry.package.version = "9.9.9"
......@@ -59,7 +61,7 @@ def poetry(fixture_dir: FixtureDirGetter, config: Config) -> Poetry:
@pytest.fixture()
def io() -> BufferedIO:
def io() -> IO:
return BufferedIO()
......@@ -86,7 +88,7 @@ def test_load_plugins_and_activate(
manager.load_plugins()
manager.activate(poetry, io)
assert poetry.package.readmes == ("README.md",)
assert poetry.package.readmes == (Path("README.md"),)
assert io.fetch_output() == "Setting readmes\n"
......
......@@ -2,6 +2,7 @@ from __future__ import annotations
from subprocess import CalledProcessError
from typing import TYPE_CHECKING
from typing import Any
import pytest
......@@ -35,7 +36,7 @@ SOME_URL = "https://example.com/path.tar.gz"
class MockEnv(BaseMockEnv):
def run(self, bin: str, *args: str) -> None:
def run(self, bin: str, *args: str, **kwargs: Any) -> str | int:
raise EnvCommandError(CalledProcessError(1, "python", output=""))
......
......@@ -3410,7 +3410,7 @@ def test_solver_should_not_update_same_version_packages_if_installed_has_no_sour
def test_solver_should_use_the_python_constraint_from_the_environment_if_available(
solver: Solver, repo: Repository, package: ProjectPackage
):
) -> None:
set_package_python_versions(solver.provider, "~2.7 || ^3.5")
package.add_dependency(Factory.create_dependency("A", "^1.0"))
......
......@@ -51,10 +51,10 @@ INSTALLED_RESULTS = [
class MockEnv(BaseMockEnv):
@property
def paths(self) -> dict[str, Path]:
def paths(self) -> dict[str, str]:
return {
"purelib": SITE_PURELIB,
"platlib": SITE_PLATLIB,
"purelib": SITE_PURELIB.as_posix(),
"platlib": SITE_PLATLIB.as_posix(),
}
@property
......@@ -96,7 +96,7 @@ def get_package_from_repository(
return None
def test_load_successful(repository: InstalledRepository):
def test_load_successful(repository: InstalledRepository) -> None:
assert len(repository.packages) == len(INSTALLED_RESULTS)
......@@ -119,12 +119,12 @@ def test_load_successful_with_invalid_distribution(
assert str(invalid_dist_info) in message
def test_load_ensure_isolation(repository: InstalledRepository):
def test_load_ensure_isolation(repository: InstalledRepository) -> None:
package = get_package_from_repository("attrs", repository)
assert package is None
def test_load_standard_package(repository: InstalledRepository):
def test_load_standard_package(repository: InstalledRepository) -> None:
cleo = get_package_from_repository("cleo", repository)
assert cleo is not None
assert cleo.name == "cleo"
......@@ -139,7 +139,7 @@ def test_load_standard_package(repository: InstalledRepository):
assert foo.version.text == "0.1.0"
def test_load_git_package(repository: InstalledRepository):
def test_load_git_package(repository: InstalledRepository) -> None:
pendulum = get_package_from_repository("pendulum", repository)
assert pendulum is not None
assert pendulum.name == "pendulum"
......@@ -153,7 +153,7 @@ def test_load_git_package(repository: InstalledRepository):
assert pendulum.source_reference == "bb058f6b78b2d28ef5d9a5e759cfa179a1a713d6"
def test_load_git_package_pth(repository: InstalledRepository):
def test_load_git_package_pth(repository: InstalledRepository) -> None:
bender = get_package_from_repository("bender", repository)
assert bender is not None
assert bender.name == "bender"
......@@ -161,14 +161,14 @@ def test_load_git_package_pth(repository: InstalledRepository):
assert bender.source_type == "git"
def test_load_platlib_package(repository: InstalledRepository):
def test_load_platlib_package(repository: InstalledRepository) -> None:
lib64 = get_package_from_repository("lib64", repository)
assert lib64 is not None
assert lib64.name == "lib64"
assert lib64.version.text == "2.3.4"
def test_load_editable_package(repository: InstalledRepository):
def test_load_editable_package(repository: InstalledRepository) -> None:
# test editable package with text .pth file
editable = get_package_from_repository("editable", repository)
assert editable is not None
......@@ -181,7 +181,7 @@ def test_load_editable_package(repository: InstalledRepository):
)
def test_load_editable_with_import_package(repository: InstalledRepository):
def test_load_editable_with_import_package(repository: InstalledRepository) -> None:
# test editable package with executable .pth file
editable = get_package_from_repository("editable-with-import", repository)
assert editable is not None
......@@ -191,7 +191,7 @@ def test_load_editable_with_import_package(repository: InstalledRepository):
assert editable.source_url is None
def test_load_standard_package_with_pth_file(repository: InstalledRepository):
def test_load_standard_package_with_pth_file(repository: InstalledRepository) -> None:
# test standard packages with .pth file is not treated as editable
standard = get_package_from_repository("standard", repository)
assert standard is not None
......@@ -201,7 +201,7 @@ def test_load_standard_package_with_pth_file(repository: InstalledRepository):
assert standard.source_url is None
def test_load_pep_610_compliant_git_packages(repository: InstalledRepository):
def test_load_pep_610_compliant_git_packages(repository: InstalledRepository) -> None:
package = get_package_from_repository("git-pep-610", repository)
assert package is not None
......@@ -215,7 +215,7 @@ def test_load_pep_610_compliant_git_packages(repository: InstalledRepository):
def test_load_pep_610_compliant_git_packages_no_requested_version(
repository: InstalledRepository,
):
) -> None:
package = get_package_from_repository(
"git-pep-610-no-requested-version", repository
)
......@@ -234,7 +234,7 @@ def test_load_pep_610_compliant_git_packages_no_requested_version(
def test_load_pep_610_compliant_git_packages_with_subdirectory(
repository: InstalledRepository,
):
) -> None:
package = get_package_from_repository("git-pep-610-subdirectory", repository)
assert package is not None
assert package.name == "git-pep-610-subdirectory"
......@@ -246,7 +246,7 @@ def test_load_pep_610_compliant_git_packages_with_subdirectory(
assert package.source_subdirectory == "subdir"
def test_load_pep_610_compliant_url_packages(repository: InstalledRepository):
def test_load_pep_610_compliant_url_packages(repository: InstalledRepository) -> None:
package = get_package_from_repository("url-pep-610", repository)
assert package is not None
......@@ -259,7 +259,7 @@ def test_load_pep_610_compliant_url_packages(repository: InstalledRepository):
)
def test_load_pep_610_compliant_file_packages(repository: InstalledRepository):
def test_load_pep_610_compliant_file_packages(repository: InstalledRepository) -> None:
package = get_package_from_repository("file-pep-610", repository)
assert package is not None
......@@ -269,7 +269,9 @@ def test_load_pep_610_compliant_file_packages(repository: InstalledRepository):
assert package.source_url == "/path/to/distributions/file-pep-610-1.2.3.tar.gz"
def test_load_pep_610_compliant_directory_packages(repository: InstalledRepository):
def test_load_pep_610_compliant_directory_packages(
repository: InstalledRepository,
) -> None:
package = get_package_from_repository("directory-pep-610", repository)
assert package is not None
......@@ -282,7 +284,7 @@ def test_load_pep_610_compliant_directory_packages(repository: InstalledReposito
def test_load_pep_610_compliant_editable_directory_packages(
repository: InstalledRepository,
):
) -> None:
package = get_package_from_repository("editable-directory-pep-610", repository)
assert package is not None
......
......@@ -20,7 +20,7 @@ if TYPE_CHECKING:
def test_set_http_password(
config: Config, with_simple_keyring: None, dummy_keyring: DummyBackend
):
) -> None:
manager = PasswordManager(config)
assert manager.keyring.is_available()
......@@ -35,13 +35,14 @@ def test_set_http_password(
def test_get_http_auth(
config: Config, with_simple_keyring: None, dummy_keyring: DummyBackend
):
) -> None:
dummy_keyring.set_password("poetry-repository-foo", "bar", "baz")
config.auth_config_source.add_property("http-basic.foo", {"username": "bar"})
manager = PasswordManager(config)
assert manager.keyring.is_available()
auth = manager.get_http_auth("foo")
assert auth is not None
assert auth["username"] == "bar"
assert auth["password"] == "baz"
......@@ -49,7 +50,7 @@ def test_get_http_auth(
def test_delete_http_password(
config: Config, with_simple_keyring: None, dummy_keyring: DummyBackend
):
) -> None:
dummy_keyring.set_password("poetry-repository-foo", "bar", "baz")
config.auth_config_source.add_property("http-basic.foo", {"username": "bar"})
manager = PasswordManager(config)
......@@ -63,7 +64,7 @@ def test_delete_http_password(
def test_set_pypi_token(
config: Config, with_simple_keyring: None, dummy_keyring: DummyBackend
):
) -> None:
manager = PasswordManager(config)
assert manager.keyring.is_available()
......@@ -76,7 +77,7 @@ def test_set_pypi_token(
def test_get_pypi_token(
config: Config, with_simple_keyring: None, dummy_keyring: DummyBackend
):
) -> None:
dummy_keyring.set_password("poetry-repository-foo", "__token__", "baz")
manager = PasswordManager(config)
......@@ -86,7 +87,7 @@ def test_get_pypi_token(
def test_delete_pypi_token(
config: Config, with_simple_keyring: None, dummy_keyring: DummyBackend
):
) -> None:
dummy_keyring.set_password("poetry-repository-foo", "__token__", "baz")
manager = PasswordManager(config)
......@@ -98,7 +99,7 @@ def test_delete_pypi_token(
def test_set_http_password_with_unavailable_backend(
config: Config, with_fail_keyring: None
):
) -> None:
manager = PasswordManager(config)
assert not manager.keyring.is_available()
......@@ -111,7 +112,7 @@ def test_set_http_password_with_unavailable_backend(
def test_get_http_auth_with_unavailable_backend(
config: Config, with_fail_keyring: None
):
) -> None:
config.auth_config_source.add_property(
"http-basic.foo", {"username": "bar", "password": "baz"}
)
......@@ -119,6 +120,7 @@ def test_get_http_auth_with_unavailable_backend(
assert not manager.keyring.is_available()
auth = manager.get_http_auth("foo")
assert auth is not None
assert auth["username"] == "bar"
assert auth["password"] == "baz"
......@@ -126,7 +128,7 @@ def test_get_http_auth_with_unavailable_backend(
def test_delete_http_password_with_unavailable_backend(
config: Config, with_fail_keyring: None
):
) -> None:
config.auth_config_source.add_property(
"http-basic.foo", {"username": "bar", "password": "baz"}
)
......@@ -140,7 +142,7 @@ def test_delete_http_password_with_unavailable_backend(
def test_set_pypi_token_with_unavailable_backend(
config: Config, with_fail_keyring: None
):
) -> None:
manager = PasswordManager(config)
assert not manager.keyring.is_available()
......@@ -151,7 +153,7 @@ def test_set_pypi_token_with_unavailable_backend(
def test_get_pypi_token_with_unavailable_backend(
config: Config, with_fail_keyring: None
):
) -> None:
config.auth_config_source.add_property("pypi-token.foo", "baz")
manager = PasswordManager(config)
......@@ -161,7 +163,7 @@ def test_get_pypi_token_with_unavailable_backend(
def test_delete_pypi_token_with_unavailable_backend(
config: Config, with_fail_keyring: None
):
) -> None:
config.auth_config_source.add_property("pypi-token.foo", "baz")
manager = PasswordManager(config)
......@@ -173,7 +175,7 @@ def test_delete_pypi_token_with_unavailable_backend(
def test_keyring_raises_errors_on_keyring_errors(
mocker: MockerFixture, with_fail_keyring: None
):
) -> None:
mocker.patch("poetry.utils.password_manager.PoetryKeyring._check")
key_ring = PoetryKeyring("poetry")
......@@ -189,7 +191,7 @@ def test_keyring_raises_errors_on_keyring_errors(
def test_keyring_with_chainer_backend_and_fail_keyring_should_be_unavailable(
with_chained_fail_keyring: None,
):
) -> None:
key_ring = PoetryKeyring("poetry")
assert not key_ring.is_available()
......@@ -197,7 +199,7 @@ def test_keyring_with_chainer_backend_and_fail_keyring_should_be_unavailable(
def test_keyring_with_chainer_backend_and_null_keyring_should_be_unavailable(
with_chained_null_keyring: None,
):
) -> None:
key_ring = PoetryKeyring("poetry")
assert not key_ring.is_available()
......@@ -205,7 +207,7 @@ def test_keyring_with_chainer_backend_and_null_keyring_should_be_unavailable(
def test_null_keyring_should_be_unavailable(
with_null_keyring: None,
):
) -> None:
key_ring = PoetryKeyring("poetry")
assert not key_ring.is_available()
......@@ -213,7 +215,7 @@ def test_null_keyring_should_be_unavailable(
def test_fail_keyring_should_be_unavailable(
with_fail_keyring: None,
):
) -> None:
key_ring = PoetryKeyring("poetry")
assert not key_ring.is_available()
......@@ -221,13 +223,14 @@ def test_fail_keyring_should_be_unavailable(
def test_get_http_auth_from_environment_variables(
environ: None, config: Config, with_simple_keyring: None
):
) -> None:
os.environ["POETRY_HTTP_BASIC_FOO_USERNAME"] = "bar"
os.environ["POETRY_HTTP_BASIC_FOO_PASSWORD"] = "baz"
manager = PasswordManager(config)
auth = manager.get_http_auth("foo")
assert auth is not None
assert auth["username"] == "bar"
assert auth["password"] == "baz"
......@@ -238,7 +241,7 @@ def test_get_pypi_token_with_env_var_positive(
config: Config,
with_simple_keyring: None,
dummy_keyring: DummyBackend,
):
) -> None:
sample_token = "sampletoken-1234"
repo_name = "foo"
manager = PasswordManager(config)
......@@ -252,7 +255,7 @@ def test_get_pypi_token_with_env_var_positive(
def test_get_pypi_token_with_env_var_not_available(
config: Config, with_simple_keyring: None, dummy_keyring: DummyBackend
):
) -> None:
repo_name = "foo"
manager = PasswordManager(config)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment