diff --git a/pyproject.toml b/pyproject.toml index 7f87ec3c2ff..63e65101815 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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.*', diff --git a/tests/config/test_config.py b/tests/config/test_config.py index 0d4f3ba7a2b..0194e7799d5 100644 --- a/tests/config/test_config.py +++ b/tests/config/test_config.py @@ -5,6 +5,7 @@ from pathlib import Path from typing import TYPE_CHECKING +from typing import Any import pytest @@ -19,7 +20,7 @@ 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 diff --git a/tests/console/commands/cache/test_list.py b/tests/console/commands/cache/test_list.py index 22db34cb0de..2def8564831 100644 --- a/tests/console/commands/cache/test_list.py +++ b/tests/console/commands/cache/test_list.py @@ -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 = """\ diff --git a/tests/console/commands/debug/test_resolve.py b/tests/console/commands/debug/test_resolve.py index ddb45d4d1c8..1d733e3612f 100644 --- a/tests/console/commands/debug/test_resolve.py +++ b/tests/console/commands/debug/test_resolve.py @@ -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 @@ def test_debug_resolve_gives_resolution_results(tester: CommandTester): 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 @@ def test_debug_resolve_tree_option_gives_the_dependency_tree(tester: CommandTest 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 = """\ diff --git a/tests/console/commands/env/test_list.py b/tests/console/commands/env/test_list.py index 687493faabb..b617d3e39c2 100644 --- a/tests/console/commands/env/test_list.py +++ b/tests/console/commands/env/test_list.py @@ -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 diff --git a/tests/console/commands/env/test_remove.py b/tests/console/commands/env/test_remove.py index 428d4f13dfd..9586be90ea1 100644 --- a/tests/console/commands/env/test_remove.py +++ b/tests/console/commands/env/test_remove.py @@ -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:] diff --git a/tests/console/commands/self/test_add_plugins.py b/tests/console/commands/self/test_add_plugins.py index e7bd3c1707f..981a3fe8db8 100644 --- a/tests/console/commands/self/test_add_plugins.py +++ b/tests/console/commands/self/test_add_plugins.py @@ -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 @@ def test_add_no_constraint( 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 @@ def test_add_with_constraint( 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 @@ def test_add_with_git_constraint( 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")) diff --git a/tests/console/commands/self/test_remove_plugins.py b/tests/console/commands/self/test_remove_plugins.py index 17f24df5708..9d1dfbaeae3 100644 --- a/tests/console/commands/self/test_remove_plugins.py +++ b/tests/console/commands/self/test_remove_plugins.py @@ -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 @@ def test_remove_installed_package(tester: CommandTester): 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"""\ diff --git a/tests/console/commands/self/test_show_plugins.py b/tests/console/commands/self/test_show_plugins.py index c2a93bc632a..410473f9133 100644 --- a/tests/console/commands/self/test_show_plugins.py +++ b/tests/console/commands/self/test_show_plugins.py @@ -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 = """ diff --git a/tests/console/commands/test_about.py b/tests/console/commands/test_about.py index 8f6902c35b3..4368acfd094 100644 --- a/tests/console/commands/test_about.py +++ b/tests/console/commands/test_about.py @@ -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() diff --git a/tests/console/commands/test_add.py b/tests/console/commands/test_add.py index 706aa637edc..8daf01ea9d9 100644 --- a/tests/console/commands/test_add.py +++ b/tests/console/commands/test_add.py @@ -74,7 +74,7 @@ def old_tester(tester: CommandTester) -> CommandTester: def test_add_no_constraint( app: PoetryTestApplication, repo: TestRepository, tester: CommandTester -): +) -> None: repo.add_package(get_package("cachy", "0.1.0")) repo.add_package(get_package("cachy", "0.2.0")) @@ -104,7 +104,7 @@ def test_add_no_constraint( def test_add_replace_by_constraint( app: PoetryTestApplication, repo: TestRepository, tester: CommandTester -): +) -> None: repo.add_package(get_package("cachy", "0.1.0")) repo.add_package(get_package("cachy", "0.2.0")) @@ -151,7 +151,7 @@ def test_add_replace_by_constraint( def test_add_no_constraint_editable_error( app: PoetryTestApplication, repo: TestRepository, tester: CommandTester -): +) -> None: content = app.poetry.file.read()["tool"]["poetry"] repo.add_package(get_package("cachy", "0.2.0")) @@ -172,7 +172,7 @@ def test_add_no_constraint_editable_error( def test_add_equal_constraint( app: PoetryTestApplication, repo: TestRepository, tester: CommandTester -): +) -> None: repo.add_package(get_package("cachy", "0.1.0")) repo.add_package(get_package("cachy", "0.2.0")) @@ -196,7 +196,7 @@ def test_add_equal_constraint( def test_add_greater_constraint( app: PoetryTestApplication, repo: TestRepository, tester: CommandTester -): +) -> None: repo.add_package(get_package("cachy", "0.1.0")) repo.add_package(get_package("cachy", "0.2.0")) @@ -224,7 +224,7 @@ def test_add_constraint_with_extras( repo: TestRepository, tester: CommandTester, extra_name: str, -): +) -> None: cachy1 = get_package("cachy", "0.1.0") cachy1.extras = {"msgpack": [get_dependency("msgpack-python")]} msgpack_dep = get_dependency("msgpack-python", ">=0.5 <0.6", optional=True) @@ -255,7 +255,7 @@ def test_add_constraint_with_extras( def test_add_constraint_dependencies( app: PoetryTestApplication, repo: TestRepository, tester: CommandTester -): +) -> None: cachy2 = get_package("cachy", "0.2.0") msgpack_dep = get_dependency("msgpack-python", ">=0.5 <0.6") cachy2.add_dependency(msgpack_dep) @@ -288,7 +288,7 @@ def test_add_git_constraint( repo: TestRepository, tester: CommandTester, tmp_venv: VirtualEnv, -): +) -> None: tester.command.set_env(tmp_venv) repo.add_package(get_package("pendulum", "1.4.4")) @@ -325,7 +325,7 @@ def test_add_git_constraint_with_poetry( repo: TestRepository, tester: CommandTester, tmp_venv: VirtualEnv, -): +) -> None: tester.command.set_env(tmp_venv) repo.add_package(get_package("pendulum", "1.4.4")) @@ -356,7 +356,7 @@ def test_add_git_constraint_with_extras( tester: CommandTester, tmp_venv: VirtualEnv, extra_name: str, -): +) -> None: tester.command.set_env(tmp_venv) repo.add_package(get_package("pendulum", "1.4.4")) @@ -409,7 +409,7 @@ def test_add_git_constraint_with_subdirectory( repo: TestRepository, tester: CommandTester, env: MockEnv, -): +) -> None: tester.execute(url) expected = """\ @@ -446,7 +446,7 @@ def test_add_git_ssh_constraint( repo: TestRepository, tester: CommandTester, tmp_venv: VirtualEnv, -): +) -> None: tester.command.set_env(tmp_venv) repo.add_package(get_package("pendulum", "1.4.4")) @@ -495,7 +495,7 @@ def test_add_directory_constraint( app: PoetryTestApplication, repo: TestRepository, tester: CommandTester, -): +) -> None: repo.add_package(get_package("pendulum", "1.4.4")) repo.add_package(get_package("cleo", "0.6.5")) @@ -537,7 +537,7 @@ def test_add_directory_with_poetry( app: PoetryTestApplication, repo: TestRepository, tester: CommandTester, -): +) -> None: repo.add_package(get_package("pendulum", "1.4.4")) path = "../git/github.com/demo/pyproject-demo" @@ -569,7 +569,7 @@ def test_add_file_constraint_wheel( repo: TestRepository, tester: CommandTester, poetry: Poetry, -): +) -> None: repo.add_package(get_package("pendulum", "1.4.4")) path = "../distributions/demo-0.1.0-py2.py3-none-any.whl" @@ -605,7 +605,7 @@ def test_add_file_constraint_sdist( app: PoetryTestApplication, repo: TestRepository, tester: CommandTester, -): +) -> None: repo.add_package(get_package("pendulum", "1.4.4")) path = "../distributions/demo-0.1.0.tar.gz" @@ -639,7 +639,7 @@ def test_add_constraint_with_extras_option( repo: TestRepository, tester: CommandTester, extra_name: str, -): +) -> None: cachy2 = get_package("cachy", "0.2.0") cachy2.extras = {"msgpack": [get_dependency("msgpack-python")]} msgpack_dep = get_dependency("msgpack-python", ">=0.5 <0.6", optional=True) @@ -681,7 +681,7 @@ def test_add_url_constraint_wheel( repo: TestRepository, tester: CommandTester, mocker: MockerFixture, -): +) -> None: p = mocker.patch("pathlib.Path.cwd") p.return_value = Path(__file__) / ".." @@ -723,7 +723,7 @@ def test_add_url_constraint_wheel_with_extras( tester: CommandTester, extra_name: str, mocker: MockerFixture, -): +) -> None: repo.add_package(get_package("pendulum", "1.4.4")) repo.add_package(get_package("cleo", "0.6.5")) repo.add_package(get_package("tomlkit", "0.5.5")) @@ -767,7 +767,7 @@ def test_add_url_constraint_wheel_with_extras( def test_add_constraint_with_python( app: PoetryTestApplication, repo: TestRepository, tester: CommandTester -): +) -> None: cachy2 = get_package("cachy", "0.2.0") repo.add_package(get_package("cachy", "0.1.0")) @@ -801,7 +801,7 @@ def test_add_constraint_with_platform( repo: TestRepository, tester: CommandTester, env: MockEnv, -): +) -> None: platform = sys.platform env._platform = platform env._marker_env = None @@ -842,7 +842,7 @@ def test_add_constraint_with_source( poetry: Poetry, tester: CommandTester, mocker: MockerFixture, -): +) -> None: repo = LegacyRepository(name="my-index", url="https://my-index.fake") repo.add_package(get_package("cachy", "0.2.0")) mocker.patch.object( @@ -890,7 +890,7 @@ def test_add_constraint_with_source( def test_add_constraint_with_source_that_does_not_exist( app: PoetryTestApplication, tester: CommandTester -): +) -> None: with pytest.raises(IndexError) as e: tester.execute("foo --source i-dont-exist") @@ -902,7 +902,7 @@ def test_add_constraint_not_found_with_source( poetry: Poetry, mocker: MockerFixture, tester: CommandTester, -): +) -> None: repo = LegacyRepository(name="my-index", url="https://my-index.fake") mocker.patch.object(repo, "find_packages", return_value=[]) @@ -919,7 +919,7 @@ def test_add_constraint_not_found_with_source( def test_add_to_section_that_does_not_exist_yet( app: PoetryTestApplication, repo: TestRepository, tester: CommandTester -): +) -> None: repo.add_package(get_package("cachy", "0.1.0")) repo.add_package(get_package("cachy", "0.2.0")) @@ -962,7 +962,7 @@ def test_add_to_section_that_does_not_exist_yet( def test_add_to_dev_section_deprecated( app: PoetryTestApplication, repo: TestRepository, tester: CommandTester -): +) -> None: repo.add_package(get_package("cachy", "0.1.0")) repo.add_package(get_package("cachy", "0.2.0")) @@ -997,7 +997,7 @@ def test_add_to_dev_section_deprecated( def test_add_should_not_select_prereleases( app: PoetryTestApplication, repo: TestRepository, tester: CommandTester -): +) -> None: repo.add_package(get_package("pyyaml", "3.13")) repo.add_package(get_package("pyyaml", "4.2b2")) @@ -1027,7 +1027,7 @@ def test_add_should_not_select_prereleases( def test_add_should_skip_when_adding_existing_package_with_no_constraint( app: PoetryTestApplication, repo: TestRepository, tester: CommandTester -): +) -> None: content = app.poetry.file.read() content["tool"]["poetry"]["dependencies"]["foo"] = "^1.0" app.poetry.file.write(content) @@ -1051,7 +1051,7 @@ def test_add_should_skip_when_adding_existing_package_with_no_constraint( def test_add_should_skip_when_adding_canonicalized_existing_package_with_no_constraint( app: PoetryTestApplication, repo: TestRepository, tester: CommandTester -): +) -> None: content = app.poetry.file.read() content["tool"]["poetry"]["dependencies"]["foo-bar"] = "^1.0" app.poetry.file.write(content) @@ -1077,7 +1077,7 @@ def test_add_latest_should_not_create_duplicate_keys( project_factory: ProjectFactory, repo: TestRepository, command_tester_factory: CommandTesterFactory, -): +) -> None: pyproject_content = """\ [tool.poetry] name = "simple-project" @@ -1113,7 +1113,7 @@ def test_add_latest_should_not_create_duplicate_keys( def test_add_should_work_when_adding_existing_package_with_latest_constraint( app: PoetryTestApplication, repo: TestRepository, tester: CommandTester -): +) -> None: content = app.poetry.file.read() content["tool"]["poetry"]["dependencies"]["foo"] = "^1.0" app.poetry.file.write(content) @@ -1145,7 +1145,7 @@ def test_add_should_work_when_adding_existing_package_with_latest_constraint( def test_add_chooses_prerelease_if_only_prereleases_are_available( app: PoetryTestApplication, repo: TestRepository, tester: CommandTester -): +) -> None: repo.add_package(get_package("foo", "1.2.3b0")) repo.add_package(get_package("foo", "1.2.3b1")) @@ -1168,7 +1168,7 @@ def test_add_chooses_prerelease_if_only_prereleases_are_available( def test_add_prefers_stable_releases( app: PoetryTestApplication, repo: TestRepository, tester: CommandTester -): +) -> None: repo.add_package(get_package("foo", "1.2.3")) repo.add_package(get_package("foo", "1.2.4b1")) @@ -1192,7 +1192,7 @@ def test_add_prefers_stable_releases( def test_add_with_lock( app: PoetryTestApplication, repo: TestRepository, tester: CommandTester -): +) -> None: content_hash = app.poetry.locker._get_content_hash() repo.add_package(get_package("cachy", "0.2.0")) @@ -1216,7 +1216,7 @@ def test_add_no_constraint_old_installer( repo: TestRepository, installer: NoopInstaller, old_tester: CommandTester, -): +) -> None: repo.add_package(get_package("cachy", "0.1.0")) repo.add_package(get_package("cachy", "0.2.0")) @@ -1250,7 +1250,7 @@ def test_add_equal_constraint_old_installer( repo: TestRepository, installer: NoopInstaller, old_tester: CommandTester, -): +) -> None: repo.add_package(get_package("cachy", "0.1.0")) repo.add_package(get_package("cachy", "0.2.0")) @@ -1278,7 +1278,7 @@ def test_add_greater_constraint_old_installer( repo: TestRepository, installer: NoopInstaller, old_tester: CommandTester, -): +) -> None: repo.add_package(get_package("cachy", "0.1.0")) repo.add_package(get_package("cachy", "0.2.0")) @@ -1308,7 +1308,7 @@ def test_add_constraint_with_extras_old_installer( installer: NoopInstaller, old_tester: CommandTester, extra_name: str, -): +) -> None: cachy1 = get_package("cachy", "0.1.0") cachy1.extras = {"msgpack": [get_dependency("msgpack-python")]} msgpack_dep = get_dependency("msgpack-python", ">=0.5 <0.6", optional=True) @@ -1343,7 +1343,7 @@ def test_add_constraint_dependencies_old_installer( repo: TestRepository, installer: NoopInstaller, old_tester: CommandTester, -): +) -> None: cachy2 = get_package("cachy", "0.2.0") msgpack_dep = get_dependency("msgpack-python", ">=0.5 <0.6") cachy2.add_dependency(msgpack_dep) @@ -1377,7 +1377,7 @@ def test_add_git_constraint_old_installer( repo: TestRepository, installer: NoopInstaller, old_tester: CommandTester, -): +) -> None: repo.add_package(get_package("pendulum", "1.4.4")) repo.add_package(get_package("cleo", "0.6.5")) @@ -1413,7 +1413,7 @@ def test_add_git_constraint_with_poetry_old_installer( repo: TestRepository, installer: NoopInstaller, old_tester: CommandTester, -): +) -> None: repo.add_package(get_package("pendulum", "1.4.4")) old_tester.execute("git+/~https://github.com/demo/pyproject-demo.git") @@ -1443,7 +1443,7 @@ def test_add_git_constraint_with_extras_old_installer( installer: NoopInstaller, old_tester: CommandTester, extra_name: str, -): +) -> None: repo.add_package(get_package("pendulum", "1.4.4")) repo.add_package(get_package("cleo", "0.6.5")) repo.add_package(get_package("tomlkit", "0.5.5")) @@ -1483,7 +1483,7 @@ def test_add_git_ssh_constraint_old_installer( repo: TestRepository, installer: NoopInstaller, old_tester: CommandTester, -): +) -> None: repo.add_package(get_package("pendulum", "1.4.4")) repo.add_package(get_package("cleo", "0.6.5")) @@ -1524,7 +1524,7 @@ def test_add_directory_constraint_old_installer( repo: TestRepository, installer: NoopInstaller, old_tester: CommandTester, -): +) -> None: repo.add_package(get_package("pendulum", "1.4.4")) repo.add_package(get_package("cleo", "0.6.5")) @@ -1563,7 +1563,7 @@ def test_add_directory_with_poetry_old_installer( repo: TestRepository, installer: NoopInstaller, old_tester: CommandTester, -): +) -> None: repo.add_package(get_package("pendulum", "1.4.4")) path = "../git/github.com/demo/pyproject-demo" @@ -1596,7 +1596,7 @@ def test_add_file_constraint_wheel_old_installer( repo: TestRepository, installer: NoopInstaller, old_tester: CommandTester, -): +) -> None: repo.add_package(get_package("pendulum", "1.4.4")) path = "../distributions/demo-0.1.0-py2.py3-none-any.whl" @@ -1634,7 +1634,7 @@ def test_add_file_constraint_sdist_old_installer( repo: TestRepository, installer: NoopInstaller, old_tester: CommandTester, -): +) -> None: repo.add_package(get_package("pendulum", "1.4.4")) path = "../distributions/demo-0.1.0.tar.gz" @@ -1670,7 +1670,7 @@ def test_add_constraint_with_extras_option_old_installer( installer: NoopInstaller, old_tester: CommandTester, extra_name: str, -): +) -> None: cachy2 = get_package("cachy", "0.2.0") cachy2.extras = {"msgpack": [get_dependency("msgpack-python")]} msgpack_dep = get_dependency("msgpack-python", ">=0.5 <0.6", optional=True) @@ -1714,7 +1714,7 @@ def test_add_url_constraint_wheel_old_installer( installer: NoopInstaller, mocker: MockerFixture, old_tester: CommandTester, -): +) -> None: p = mocker.patch("pathlib.Path.cwd") p.return_value = Path(__file__) / ".." @@ -1757,7 +1757,7 @@ def test_add_url_constraint_wheel_with_extras_old_installer( installer: NoopInstaller, old_tester: CommandTester, extra_name: str, -): +) -> None: repo.add_package(get_package("pendulum", "1.4.4")) repo.add_package(get_package("cleo", "0.6.5")) repo.add_package(get_package("tomlkit", "0.5.5")) @@ -1803,7 +1803,7 @@ def test_add_constraint_with_python_old_installer( repo: TestRepository, installer: NoopInstaller, old_tester: CommandTester, -): +) -> None: cachy2 = get_package("cachy", "0.2.0") repo.add_package(get_package("cachy", "0.1.0")) @@ -1839,7 +1839,7 @@ def test_add_constraint_with_platform_old_installer( installer: NoopInstaller, env: MockEnv, old_tester: CommandTester, -): +) -> None: platform = sys.platform env._platform = platform env._marker_env = None @@ -1882,7 +1882,7 @@ def test_add_constraint_with_source_old_installer( installer: NoopInstaller, old_tester: CommandTester, mocker: MockerFixture, -): +) -> None: repo = LegacyRepository(name="my-index", url="https://my-index.fake") repo.add_package(get_package("cachy", "0.2.0")) mocker.patch.object( @@ -1931,7 +1931,7 @@ def test_add_constraint_with_source_old_installer( def test_add_constraint_with_source_that_does_not_exist_old_installer( app: PoetryTestApplication, old_tester: CommandTester -): +) -> None: with pytest.raises(IndexError) as e: old_tester.execute("foo --source i-dont-exist") @@ -1943,7 +1943,7 @@ def test_add_constraint_not_found_with_source_old_installer( poetry: Poetry, mocker: MockerFixture, old_tester: CommandTester, -): +) -> None: repo = LegacyRepository(name="my-index", url="https://my-index.fake") mocker.patch.object(repo, "find_packages", return_value=[]) @@ -1963,7 +1963,7 @@ def test_add_to_section_that_does_no_exist_yet_old_installer( repo: TestRepository, installer: NoopInstaller, old_tester: CommandTester, -): +) -> None: repo.add_package(get_package("cachy", "0.1.0")) repo.add_package(get_package("cachy", "0.2.0")) @@ -1997,7 +1997,7 @@ def test_add_should_not_select_prereleases_old_installer( repo: TestRepository, installer: NoopInstaller, old_tester: CommandTester, -): +) -> None: repo.add_package(get_package("pyyaml", "3.13")) repo.add_package(get_package("pyyaml", "4.2b2")) @@ -2031,7 +2031,7 @@ def test_add_should_skip_when_adding_existing_package_with_no_constraint_old_ins repo: TestRepository, installer: NoopInstaller, old_tester: CommandTester, -): +) -> None: content = app.poetry.file.read() content["tool"]["poetry"]["dependencies"]["foo"] = "^1.0" app.poetry.file.write(content) @@ -2059,7 +2059,7 @@ def test_add_should_work_when_adding_existing_package_with_latest_constraint_old repo: TestRepository, installer: NoopInstaller, old_tester: CommandTester, -): +) -> None: content = app.poetry.file.read() content["tool"]["poetry"]["dependencies"]["foo"] = "^1.0" app.poetry.file.write(content) @@ -2094,7 +2094,7 @@ def test_add_chooses_prerelease_if_only_prereleases_are_available_old_installer( repo: TestRepository, installer: NoopInstaller, old_tester: CommandTester, -): +) -> None: repo.add_package(get_package("foo", "1.2.3b0")) repo.add_package(get_package("foo", "1.2.3b1")) @@ -2120,7 +2120,7 @@ def test_add_preferes_stable_releases_old_installer( repo: TestRepository, installer: NoopInstaller, old_tester: CommandTester, -): +) -> None: repo.add_package(get_package("foo", "1.2.3")) repo.add_package(get_package("foo", "1.2.4b1")) @@ -2147,7 +2147,7 @@ def test_add_with_lock_old_installer( repo: TestRepository, installer: NoopInstaller, old_tester: CommandTester, -): +) -> None: repo.add_package(get_package("cachy", "0.2.0")) old_tester.execute("cachy --lock") @@ -2169,7 +2169,7 @@ def test_add_keyboard_interrupt_restore_content( repo: TestRepository, command_tester_factory: CommandTesterFactory, mocker: MockerFixture, -): +) -> None: tester = command_tester_factory("add", poetry=poetry_with_up_to_date_lockfile) mocker.patch( @@ -2202,7 +2202,7 @@ def test_add_with_dry_run_keep_files_intact( poetry_with_up_to_date_lockfile: Poetry, repo: TestRepository, command_tester_factory: CommandTesterFactory, -): +) -> None: tester = command_tester_factory("add", poetry=poetry_with_up_to_date_lockfile) original_pyproject_content = poetry_with_up_to_date_lockfile.file.read() @@ -2224,7 +2224,7 @@ def test_add_should_not_change_lock_file_when_dependency_installation_fail( repo: TestRepository, command_tester_factory: CommandTesterFactory, mocker: MockerFixture, -): +) -> None: tester = command_tester_factory("add", poetry=poetry_with_up_to_date_lockfile) repo.add_package(get_package("docker", "4.3.1")) diff --git a/tests/console/commands/test_config.py b/tests/console/commands/test_config.py index 975132f4bc0..063200edbf8 100644 --- a/tests/console/commands/test_config.py +++ b/tests/console/commands/test_config.py @@ -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 @@ def test_list_displays_default_value_if_not_set( 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 @@ def test_list_displays_set_get_setting( 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 @@ def test_list_must_not_display_sources_from_pyproject_toml( 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" diff --git a/tests/console/commands/test_init.py b/tests/console/commands/test_init.py index e3da0a989a6..b4bed706b99 100644 --- a/tests/console/commands/test_init.py +++ b/tests/console/commands/test_init.py @@ -95,7 +95,7 @@ def init_basic_toml() -> str: 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 @@ def test_interactive_with_dependencies(tester: CommandTester, repo: TestReposito # 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 @@ def test_interactive_with_dependencies_and_no_selection( 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 @@ def test_empty_license(tester: CommandTester): 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 @@ def test_interactive_with_git_dependencies_with_reference( 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 @@ def test_interactive_with_file_dependency( 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 @@ def test_interactive_with_wrong_dependency_inputs( 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 @@ def test_python_option(tester: CommandTester): 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 @@ def test_predefined_dependency(tester: CommandTester, repo: TestRepository): 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 @@ def test_predefined_and_interactive_dependencies( 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 @@ def test_predefined_dev_dependency(tester: CommandTester, repo: TestRepository): 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 @@ def test_predefined_and_interactive_dev_dependencies( 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 @@ def test_predefined_all_options(tester: CommandTester, repo: TestRepository): 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 @@ def test_init_non_interactive_existing_pyproject_add_dependency( 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 @@ def test_init_existing_pyproject_with_build_system_fails( " 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 diff --git a/tests/console/commands/test_install.py b/tests/console/commands/test_install.py index a1e9379de49..6f4f407dd63 100644 --- a/tests/console/commands/test_install.py +++ b/tests/console/commands/test_install.py @@ -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) diff --git a/tests/console/commands/test_lock.py b/tests/console/commands/test_lock.py index 506f82a1776..7a910caccf7 100644 --- a/tests/console/commands/test_lock.py +++ b/tests/console/commands/test_lock.py @@ -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", diff --git a/tests/console/commands/test_new.py b/tests/console/commands/test_new.py index 2b2cc9d83f2..7dd76f7cea7 100644 --- a/tests/console/commands/test_new.py +++ b/tests/console/commands/test_new.py @@ -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 diff --git a/tests/console/commands/test_publish.py b/tests/console/commands/test_publish.py index f4241a1a870..5f230c01ff3 100644 --- a/tests/console/commands/test_publish.py +++ b/tests/console/commands/test_publish.py @@ -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 request_callback(*_: Any, **__: Any) -> None: 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" ) diff --git a/tests/console/commands/test_remove.py b/tests/console/commands/test_remove.py index 0a2fa1b6c00..68c16edf065 100644 --- a/tests/console/commands/test_remove.py +++ b/tests/console/commands/test_remove.py @@ -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() diff --git a/tests/console/commands/test_run.py b/tests/console/commands/test_run.py index 7442ac10f37..53c5dbbb3d3 100644 --- a/tests/console/commands/test_run.py +++ b/tests/console/commands/test_run.py @@ -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: diff --git a/tests/console/commands/test_shell.py b/tests/console/commands/test_shell.py index abdaec46789..a8d0b8407db 100644 --- a/tests/console/commands/test_shell.py +++ b/tests/console/commands/test_shell.py @@ -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) diff --git a/tests/console/commands/test_update.py b/tests/console/commands/test_update.py index dd3306cf2ba..cb0f0052ac1 100644 --- a/tests/console/commands/test_update.py +++ b/tests/console/commands/test_update.py @@ -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() diff --git a/tests/console/commands/test_version.py b/tests/console/commands/test_version.py index d578b7fd918..33d5cb3824f 100644 --- a/tests/console/commands/test_version.py +++ b/tests/console/commands/test_version.py @@ -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") diff --git a/tests/console/test_application.py b/tests/console/test_application.py index 9ed2e2aeb54..7bca231d04a 100644 --- a/tests/console/test_application.py +++ b/tests/console/test_application.py @@ -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) diff --git a/tests/installation/test_chef.py b/tests/installation/test_chef.py index c03dfd07c4d..ca00ba01e73 100644 --- a/tests/installation/test_chef.py +++ b/tests/installation/test_chef.py @@ -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) ) diff --git a/tests/installation/test_executor.py b/tests/installation/test_executor.py index c8a529b40a7..18d5cd1b60c 100644 --- a/tests/installation/test_executor.py +++ b/tests/installation/test_executor.py @@ -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( diff --git a/tests/installation/test_installer.py b/tests/installation/test_installer.py index 4d6e975b45a..39e07fb5b06 100644 --- a/tests/installation/test_installer.py +++ b/tests/installation/test_installer.py @@ -76,12 +76,14 @@ def updates(self) -> list[DependencyPackage]: def removals(self) -> list[DependencyPackage]: return self._uninstalls - def _do_execute_operation(self, operation: Operation) -> None: - super()._do_execute_operation(operation) + def _do_execute_operation(self, operation: Operation) -> int: + ret_val = super()._do_execute_operation(operation) if not operation.skipped: getattr(self, f"_{operation.job_type}s").append(operation.package) + return ret_val + def _execute_install(self, operation: Operation) -> int: return 0 @@ -109,7 +111,7 @@ def __init__(self, lock_path: Path) -> None: self._content_hash = self._get_content_hash() @property - def written_data(self) -> dict | None: + def written_data(self) -> dict[str, Any] | None: return self._written_data def set_lock_path(self, lock: Path) -> Locker: @@ -122,7 +124,7 @@ def locked(self, is_locked: bool = True) -> Locker: return self - def mock_lock_data(self, data: dict) -> None: + def mock_lock_data(self, data: dict[str, Any]) -> None: self._lock_data = data def is_locked(self) -> bool: @@ -134,7 +136,7 @@ def is_fresh(self) -> bool: def _get_content_hash(self) -> str: return "123456789" - def _write_lock_data(self, data: dict) -> None: + def _write_lock_data(self, data: dict[str, Any]) -> None: for package in data["package"]: python_versions = str(package["python-versions"]) package["python-versions"] = python_versions @@ -201,13 +203,14 @@ def installer( return installer -def fixture(name: str) -> dict: +def fixture(name: str) -> dict[str, Any]: file = TOMLFile(Path(__file__).parent / "fixtures" / f"{name}.test") + content: dict[str, Any] = file.read() - return json.loads(json.dumps(file.read())) + return content -def test_run_no_dependencies(installer: Installer, locker: Locker): +def test_run_no_dependencies(installer: Installer, locker: Locker) -> None: result = installer.run() assert result == 0 @@ -217,7 +220,7 @@ def test_run_no_dependencies(installer: Installer, locker: Locker): def test_run_with_dependencies( installer: Installer, locker: Locker, repo: Repository, package: ProjectPackage -): +) -> None: package_a = get_package("A", "1.0") package_b = get_package("B", "1.1") repo.add_package(package_a) @@ -239,7 +242,7 @@ def test_run_update_after_removing_dependencies( repo: Repository, package: ProjectPackage, installed: CustomInstalledRepository, -): +) -> None: locker.locked(True) locker.mock_lock_data( { @@ -403,7 +406,7 @@ def test_run_install_with_dependency_groups( repo: Repository, package: ProjectPackage, installed: CustomInstalledRepository, -): +) -> None: _configure_run_install_dev( locker, repo, @@ -431,7 +434,7 @@ def test_run_install_does_not_remove_locked_packages_if_installed_but_not_requir repo: Repository, package: ProjectPackage, installed: CustomInstalledRepository, -): +) -> None: package_a = get_package("a", "1.0") package_b = get_package("b", "1.1") package_c = get_package("c", "1.2") @@ -502,7 +505,7 @@ def test_run_install_removes_locked_packages_if_installed_and_synchronization_is repo: Repository, package: ProjectPackage, installed: CustomInstalledRepository, -): +) -> None: package_a = get_package("a", "1.0") package_b = get_package("b", "1.1") package_c = get_package("c", "1.2") @@ -573,7 +576,7 @@ def test_run_install_removes_no_longer_locked_packages_if_installed( repo: Repository, package: ProjectPackage, installed: CustomInstalledRepository, -): +) -> None: package_a = get_package("a", "1.0") package_b = get_package("b", "1.1") package_c = get_package("c", "1.2") @@ -655,7 +658,7 @@ def test_run_install_with_synchronization( repo: Repository, package: ProjectPackage, installed: CustomInstalledRepository, -): +) -> None: package_a = get_package("a", "1.0") package_b = get_package("b", "1.1") package_c = get_package("c", "1.2") @@ -728,7 +731,7 @@ def test_run_install_with_synchronization( def test_run_whitelist_add( installer: Installer, locker: Locker, repo: Repository, package: ProjectPackage -): +) -> None: locker.locked(True) locker.mock_lock_data( { @@ -777,7 +780,7 @@ def test_run_whitelist_remove( repo: Repository, package: ProjectPackage, installed: CustomInstalledRepository, -): +) -> None: locker.locked(True) locker.mock_lock_data( { @@ -832,7 +835,7 @@ def test_run_whitelist_remove( def test_add_with_sub_dependencies( installer: Installer, locker: Locker, repo: Repository, package: ProjectPackage -): +) -> None: package_a = get_package("A", "1.0") package_b = get_package("B", "1.1") package_c = get_package("C", "1.2") @@ -857,7 +860,7 @@ def test_add_with_sub_dependencies( def test_run_with_python_versions( installer: Installer, locker: Locker, repo: Repository, package: ProjectPackage -): +) -> None: package.python_versions = "~2.7 || ^3.4" package_a = get_package("A", "1.0") @@ -885,7 +888,7 @@ def test_run_with_python_versions( def test_run_with_optional_and_python_restricted_dependencies( installer: Installer, locker: Locker, repo: Repository, package: ProjectPackage -): +) -> None: package.python_versions = "~2.7 || ^3.4" package_a = get_package("A", "1.0") @@ -932,7 +935,7 @@ def test_run_with_optional_and_platform_restricted_dependencies( repo: Repository, package: ProjectPackage, mocker: MockerFixture, -): +) -> None: mocker.patch("sys.platform", "darwin") package_a = get_package("A", "1.0") @@ -975,7 +978,7 @@ def test_run_with_optional_and_platform_restricted_dependencies( def test_run_with_dependencies_extras( installer: Installer, locker: Locker, repo: Repository, package: ProjectPackage -): +) -> None: package_a = get_package("A", "1.0") package_b = get_package("B", "1.0") package_c = get_package("C", "1.0") @@ -1003,7 +1006,7 @@ def test_run_with_dependencies_extras( def test_run_with_dependencies_nested_extras( installer: Installer, locker: Locker, repo: Repository, package: ProjectPackage -): +) -> None: package_a = get_package("A", "1.0") package_b = get_package("B", "1.0") package_c = get_package("C", "1.0") @@ -1035,7 +1038,7 @@ def test_run_with_dependencies_nested_extras( def test_run_does_not_install_extras_if_not_requested( installer: Installer, locker: Locker, repo: Repository, package: ProjectPackage -): +) -> None: package.extras["foo"] = [get_dependency("D")] package_a = get_package("A", "1.0") package_b = get_package("B", "1.0") @@ -1067,7 +1070,7 @@ def test_run_does_not_install_extras_if_not_requested( def test_run_installs_extras_if_requested( installer: Installer, locker: Locker, repo: Repository, package: ProjectPackage -): +) -> None: package.extras["foo"] = [get_dependency("D")] package_a = get_package("A", "1.0") package_b = get_package("B", "1.0") @@ -1100,7 +1103,7 @@ def test_run_installs_extras_if_requested( def test_run_installs_extras_with_deps_if_requested( installer: Installer, locker: Locker, repo: Repository, package: ProjectPackage -): +) -> None: package.extras["foo"] = [get_dependency("C")] package_a = get_package("A", "1.0") package_b = get_package("B", "1.0") @@ -1135,7 +1138,7 @@ def test_run_installs_extras_with_deps_if_requested( def test_run_installs_extras_with_deps_if_requested_locked( installer: Installer, locker: Locker, repo: Repository, package: ProjectPackage -): +) -> None: locker.locked(True) locker.mock_lock_data(fixture("extras-with-dependencies")) package.extras["foo"] = [get_dependency("C")] @@ -1170,7 +1173,7 @@ def test_installer_with_pypi_repository( installed: CustomInstalledRepository, config: Config, env: NullEnv, -): +) -> None: pool = RepositoryPool() pool.add_repository(MockRepository()) @@ -1194,7 +1197,7 @@ def test_run_installs_with_local_file( repo: Repository, package: ProjectPackage, fixture_dir: FixtureDirGetter, -): +) -> None: root_dir = Path(__file__).parent.parent.parent package.root_dir = root_dir locker.set_lock_path(root_dir) @@ -1222,7 +1225,7 @@ def test_run_installs_wheel_with_no_requires_dist( repo: Repository, package: ProjectPackage, fixture_dir: FixtureDirGetter, -): +) -> None: root_dir = Path(__file__).parent.parent.parent package.root_dir = root_dir locker.set_lock_path(root_dir) @@ -1252,7 +1255,7 @@ def test_run_installs_with_local_poetry_directory_and_extras( package: ProjectPackage, tmpdir: Path, fixture_dir: FixtureDirGetter, -): +) -> None: root_dir = Path(__file__).parent.parent.parent package.root_dir = root_dir locker.set_lock_path(root_dir) @@ -1284,7 +1287,7 @@ def test_run_installs_with_local_poetry_directory_and_skip_directory_flag( package: ProjectPackage, fixture_dir: FixtureDirGetter, skip_directory: bool, -): +) -> None: """When we set Installer.skip_directory(True) no path dependencies should be installed (including transitive dependencies). """ @@ -1333,7 +1336,7 @@ def test_run_installs_with_local_poetry_file_transitive( package: ProjectPackage, tmpdir: str, fixture_dir: FixtureDirGetter, -): +) -> None: root_dir = fixture_dir("directory") package.root_dir = root_dir locker.set_lock_path(root_dir) @@ -1368,7 +1371,7 @@ def test_run_installs_with_local_setuptools_directory( package: ProjectPackage, tmpdir: Path, fixture_dir: FixtureDirGetter, -): +) -> None: root_dir = Path(__file__).parent.parent.parent package.root_dir = root_dir locker.set_lock_path(root_dir) @@ -1395,7 +1398,7 @@ def test_run_installs_with_local_setuptools_directory( def test_run_with_prereleases( installer: Installer, locker: Locker, repo: Repository, package: ProjectPackage -): +) -> None: locker.locked(True) locker.mock_lock_data( { @@ -1487,7 +1490,7 @@ def test_run_changes_category_if_needed( def test_run_update_all_with_lock( installer: Installer, locker: Locker, repo: Repository, package: ProjectPackage -): +) -> None: locker.locked(True) locker.mock_lock_data( { @@ -1527,7 +1530,7 @@ def test_run_update_all_with_lock( def test_run_update_with_locked_extras( installer: Installer, locker: Locker, repo: Repository, package: ProjectPackage -): +) -> None: locker.locked(True) locker.mock_lock_data( { @@ -1601,7 +1604,7 @@ def test_run_update_with_locked_extras( def test_run_install_duplicate_dependencies_different_constraints( installer: Installer, locker: Locker, repo: Repository, package: ProjectPackage -): +) -> None: package.add_dependency(Factory.create_dependency("A", "*")) package_a = get_package("A", "1.0") @@ -1645,7 +1648,7 @@ def test_run_install_duplicate_dependencies_different_constraints( def test_run_install_duplicate_dependencies_different_constraints_with_lock( installer: Installer, locker: Locker, repo: Repository, package: ProjectPackage -): +) -> None: locker.locked(True) locker.mock_lock_data( { @@ -1757,7 +1760,7 @@ def test_run_update_uninstalls_after_removal_transient_dependency( repo: Repository, package: ProjectPackage, installed: CustomInstalledRepository, -): +) -> None: locker.locked(True) locker.mock_lock_data( { @@ -1820,7 +1823,7 @@ def test_run_install_duplicate_dependencies_different_constraints_with_lock_upda repo: Repository, package: ProjectPackage, installed: CustomInstalledRepository, -): +) -> None: locker.locked(True) locker.mock_lock_data( { @@ -1933,7 +1936,7 @@ def test_installer_test_solver_finds_compatible_package_for_dependency_python_no repo: Repository, package: ProjectPackage, installed: CustomInstalledRepository, -): +) -> None: package.python_versions = "~2.7 || ^3.4" package.add_dependency( Factory.create_dependency("A", {"version": "^1.0", "python": "^3.5"}) @@ -1965,7 +1968,7 @@ def test_installer_required_extras_should_not_be_removed_when_updating_single_de env: NullEnv, pool: RepositoryPool, config: Config, -): +) -> None: package.add_dependency(Factory.create_dependency("A", {"version": "^1.0"})) package_a = get_package("A", "1.0.0") @@ -2031,7 +2034,7 @@ def test_installer_required_extras_should_not_be_removed_when_updating_single_de env: NullEnv, mocker: MockerFixture, config: Config, -): +) -> None: mocker.patch("sys.platform", "darwin") pool = RepositoryPool() @@ -2093,7 +2096,7 @@ def test_installer_required_extras_should_be_installed( installed: CustomInstalledRepository, env: NullEnv, config: Config, -): +) -> None: pool = RepositoryPool() pool.add_repository(MockRepository()) @@ -2145,7 +2148,7 @@ def test_installer_required_extras_should_be_installed( def test_update_multiple_times_with_split_dependencies_is_idempotent( installer: Installer, locker: Locker, repo: Repository, package: ProjectPackage -): +) -> None: locker.locked(True) locker.mock_lock_data( { @@ -2231,7 +2234,7 @@ def test_installer_can_install_dependencies_from_forced_source( installed: CustomInstalledRepository, env: NullEnv, config: Config, -): +) -> None: package.python_versions = "^3.7" package.add_dependency( Factory.create_dependency("tomlkit", {"version": "^0.5", "source": "legacy"}) @@ -2262,7 +2265,7 @@ def test_installer_can_install_dependencies_from_forced_source( def test_run_installs_with_url_file( installer: Installer, locker: Locker, repo: Repository, package: ProjectPackage -): +) -> None: url = "https://python-poetry.org/distributions/demo-0.1.0-py2.py3-none-any.whl" package.add_dependency(Factory.create_dependency("demo", {"url": url})) @@ -2330,7 +2333,7 @@ def test_run_installs_with_same_version_url_files( def test_installer_uses_prereleases_if_they_are_compatible( installer: Installer, locker: Locker, package: ProjectPackage, repo: Repository -): +) -> None: package.python_versions = "~2.7 || ^3.4" package.add_dependency( Factory.create_dependency( @@ -2366,7 +2369,7 @@ def test_installer_can_handle_old_lock_files( repo: Repository, installed: CustomInstalledRepository, config: Config, -): +) -> None: pool = RepositoryPool() pool.add_repository(MockRepository()) @@ -2439,7 +2442,7 @@ def test_installer_does_not_write_lock_file_when_installation_fails( repo: Repository, package: ProjectPackage, mocker: MockerFixture, -): +) -> None: repo.add_package(get_package("A", "1.0")) package.add_dependency(Factory.create_dependency("A", "~1.0")) @@ -2463,7 +2466,7 @@ def test_run_with_dependencies_quiet( repo: Repository, package: ProjectPackage, quiet: bool, -): +) -> None: package_a = get_package("A", "1.0") package_b = get_package("B", "1.1") repo.add_package(package_a) @@ -2490,7 +2493,7 @@ def test_run_with_dependencies_quiet( def test_installer_should_use_the_locked_version_of_git_dependencies( installer: Installer, locker: Locker, package: ProjectPackage, repo: Repository -): +) -> None: locker.locked(True) locker.mock_lock_data( { @@ -2559,7 +2562,7 @@ def test_installer_should_use_the_locked_version_of_git_dependencies_with_extras package: ProjectPackage, repo: Repository, is_locked: bool, -): +) -> None: if is_locked: locker.locked(True) locker.mock_lock_data(fixture("with-vcs-dependency-with-extras")) @@ -2602,7 +2605,7 @@ def test_installer_should_use_the_locked_version_of_git_dependencies_without_ref package: ProjectPackage, repo: Repository, is_locked: bool, -): +) -> None: """ If there is no explicit reference (branch or tag or rev) in pyproject.toml, HEAD is used. @@ -2644,7 +2647,7 @@ def test_installer_distinguishes_locked_packages_by_source( repo: Repository, package: ProjectPackage, env_platform: str, -): +) -> None: # Require 1.11.0+cpu from pytorch for most platforms, but specify 1.11.0 and pypi on # darwin. package.add_dependency( diff --git a/tests/integration/test_utils_vcs_git.py b/tests/integration/test_utils_vcs_git.py index ae979edf759..afbc256bd6b 100644 --- a/tests/integration/test_utils_vcs_git.py +++ b/tests/integration/test_utils_vcs_git.py @@ -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: diff --git a/tests/plugins/test_plugin_manager.py b/tests/plugins/test_plugin_manager.py index fb2ce6c94f7..05ebd7aa5b8 100644 --- a/tests/plugins/test_plugin_manager.py +++ b/tests/plugins/test_plugin_manager.py @@ -1,5 +1,6 @@ from __future__ import annotations +from pathlib import Path from typing import TYPE_CHECKING import pytest @@ -17,6 +18,7 @@ if TYPE_CHECKING: + from cleo.io.io import IO from pytest_mock import MockerFixture from tests.conftest import Config @@ -29,9 +31,9 @@ def __call__(self, group: str = Plugin.group) -> PluginManager: 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" diff --git a/tests/publishing/test_publisher.py b/tests/publishing/test_publisher.py index 5233785a854..f90e460cc57 100644 --- a/tests/publishing/test_publisher.py +++ b/tests/publishing/test_publisher.py @@ -9,6 +9,7 @@ from cleo.io.buffered_io import BufferedIO from cleo.io.null_io import NullIO +from packaging.utils import canonicalize_name from poetry.factory import Factory from poetry.publishing.publisher import Publisher diff --git a/tests/puzzle/test_provider.py b/tests/puzzle/test_provider.py index 560ae872f05..1264321b9d0 100644 --- a/tests/puzzle/test_provider.py +++ b/tests/puzzle/test_provider.py @@ -2,6 +2,7 @@ from subprocess import CalledProcessError from typing import TYPE_CHECKING +from typing import Any import pytest @@ -35,7 +36,7 @@ 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="")) diff --git a/tests/puzzle/test_solver.py b/tests/puzzle/test_solver.py index 10e67c9ab6e..8b639d21b04 100644 --- a/tests/puzzle/test_solver.py +++ b/tests/puzzle/test_solver.py @@ -356,7 +356,7 @@ def test_solver_sets_groups( transaction = solver.solve() - ops = check_solver_result( + _ = check_solver_result( transaction, [ {"job": "install", "package": package_c}, @@ -1090,7 +1090,7 @@ def test_solver_with_dependency_in_both_main_and_dev_dependencies( transaction = solver.solve() - ops = check_solver_result( + _ = check_solver_result( transaction, [ {"job": "install", "package": package_d}, @@ -1147,7 +1147,7 @@ def test_solver_with_dependency_in_both_main_and_dev_dependencies_with_one_more_ transaction = solver.solve() - ops = check_solver_result( + _ = check_solver_result( transaction, [ {"job": "install", "package": package_b}, @@ -1218,7 +1218,7 @@ def test_solver_circular_dependency( transaction = solver.solve() - ops = check_solver_result( + _ = check_solver_result( transaction, [ {"job": "install", "package": package_c}, @@ -1254,7 +1254,7 @@ def test_solver_circular_dependency_chain( transaction = solver.solve() - ops = check_solver_result( + _ = check_solver_result( transaction, [ {"job": "install", "package": package_d}, @@ -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")) diff --git a/tests/repositories/test_installed_repository.py b/tests/repositories/test_installed_repository.py index 592d99a999a..628852708a1 100644 --- a/tests/repositories/test_installed_repository.py +++ b/tests/repositories/test_installed_repository.py @@ -51,10 +51,10 @@ 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 diff --git a/tests/utils/test_authenticator.py b/tests/utils/test_authenticator.py index 05c5490ac11..2a0d1bee564 100644 --- a/tests/utils/test_authenticator.py +++ b/tests/utils/test_authenticator.py @@ -42,12 +42,12 @@ def mock_remote(http: type[httpretty.httpretty]) -> None: @pytest.fixture() -def repo(): +def repo() -> dict[str, dict[str, str]]: return {"foo": {"url": "https://foo.bar/simple/"}} @pytest.fixture -def mock_config(config: Config, repo: dict[str, dict[str, str]]): +def mock_config(config: Config, repo: dict[str, dict[str, str]]) -> Config: config.merge( { "repositories": repo, @@ -60,7 +60,7 @@ def mock_config(config: Config, repo: dict[str, dict[str, str]]): def test_authenticator_uses_url_provided_credentials( mock_config: Config, mock_remote: None, http: type[httpretty.httpretty] -): +) -> None: authenticator = Authenticator(mock_config, NullIO()) authenticator.request("get", "https://foo001:bar002@foo.bar/files/foo-0.1.0.tar.gz") @@ -71,7 +71,7 @@ def test_authenticator_uses_url_provided_credentials( def test_authenticator_uses_credentials_from_config_if_not_provided( mock_config: Config, mock_remote: None, http: type[httpretty.httpretty] -): +) -> None: authenticator = Authenticator(mock_config, NullIO()) authenticator.request("get", "https://foo.bar/files/foo-0.1.0.tar.gz") @@ -85,7 +85,7 @@ def test_authenticator_uses_username_only_credentials( mock_remote: None, http: type[httpretty.httpretty], with_simple_keyring: None, -): +) -> None: authenticator = Authenticator(mock_config, NullIO()) authenticator.request("get", "https://foo001@foo.bar/files/foo-0.1.0.tar.gz") @@ -96,7 +96,7 @@ def test_authenticator_uses_username_only_credentials( def test_authenticator_uses_password_only_credentials( mock_config: Config, mock_remote: None, http: type[httpretty.httpretty] -): +) -> None: authenticator = Authenticator(mock_config, NullIO()) authenticator.request("get", "https://:bar002@foo.bar/files/foo-0.1.0.tar.gz") @@ -111,7 +111,7 @@ def test_authenticator_uses_empty_strings_as_default_password( repo: dict[str, dict[str, str]], http: type[httpretty.httpretty], with_simple_keyring: None, -): +) -> None: config.merge( { "repositories": repo, @@ -132,7 +132,7 @@ def test_authenticator_uses_empty_strings_as_default_username( mock_remote: None, repo: dict[str, dict[str, str]], http: type[httpretty.httpretty], -): +) -> None: config.merge( { "repositories": repo, @@ -155,7 +155,7 @@ def test_authenticator_falls_back_to_keyring_url( http: type[httpretty.httpretty], with_simple_keyring: None, dummy_keyring: DummyBackend, -): +) -> None: config.merge( { "repositories": repo, @@ -163,7 +163,7 @@ def test_authenticator_falls_back_to_keyring_url( ) dummy_keyring.set_password( - "https://foo.bar/simple/", None, SimpleCredential(None, "bar") + "https://foo.bar/simple/", None, SimpleCredential("foo", "bar") ) authenticator = Authenticator(config, NullIO()) @@ -171,7 +171,7 @@ def test_authenticator_falls_back_to_keyring_url( request = http.last_request() - assert request.headers["Authorization"] == "Basic OmJhcg==" + assert request.headers["Authorization"] == "Basic Zm9vOmJhcg==" def test_authenticator_falls_back_to_keyring_netloc( @@ -181,35 +181,35 @@ def test_authenticator_falls_back_to_keyring_netloc( http: type[httpretty.httpretty], with_simple_keyring: None, dummy_keyring: DummyBackend, -): +) -> None: config.merge( { "repositories": repo, } ) - dummy_keyring.set_password("foo.bar", None, SimpleCredential(None, "bar")) + dummy_keyring.set_password("foo.bar", None, SimpleCredential("foo", "bar")) authenticator = Authenticator(config, NullIO()) authenticator.request("get", "https://foo.bar/files/foo-0.1.0.tar.gz") request = http.last_request() - assert request.headers["Authorization"] == "Basic OmJhcg==" + assert request.headers["Authorization"] == "Basic Zm9vOmJhcg==" @pytest.mark.filterwarnings("ignore::pytest.PytestUnhandledThreadExceptionWarning") def test_authenticator_request_retries_on_exception( mocker: MockerFixture, config: Config, http: type[httpretty.httpretty] -): +) -> None: sleep = mocker.patch("time.sleep") sdist_uri = f"https://foo.bar/files/{uuid.uuid4()!s}/foo-0.1.0.tar.gz" content = str(uuid.uuid4()) - seen = [] + seen: list[str] = [] def callback( - request: requests.Request, uri: str, response_headers: dict - ) -> list[int | dict | str]: + request: requests.Request, uri: str, response_headers: dict[str, str] + ) -> list[int | dict[str, str] | str]: if seen.count(uri) < 2: seen.append(uri) raise requests.exceptions.ConnectionError("Disconnected") @@ -226,7 +226,7 @@ def callback( @pytest.mark.filterwarnings("ignore::pytest.PytestUnhandledThreadExceptionWarning") def test_authenticator_request_raises_exception_when_attempts_exhausted( mocker: MockerFixture, config: Config, http: type[httpretty.httpretty] -): +) -> None: sleep = mocker.patch("time.sleep") sdist_uri = f"https://foo.bar/files/{uuid.uuid4()!s}/foo-0.1.0.tar.gz" @@ -246,15 +246,15 @@ def test_authenticator_request_respects_retry_header( mocker: MockerFixture, config: Config, http: type[httpretty.httpretty], -): +) -> None: sleep = mocker.patch("time.sleep") sdist_uri = f"https://foo.bar/files/{uuid.uuid4()!s}/foo-0.1.0.tar.gz" content = str(uuid.uuid4()) - seen = [] + seen: list[str] = [] def callback( - request: requests.Request, uri: str, response_headers: dict - ) -> list[int | dict | str]: + request: requests.Request, uri: str, response_headers: dict[str, str] + ) -> list[int | dict[str, str] | str]: if not seen.count(uri): seen.append(uri) return [429, {"Retry-After": "42"}, "Retry later"] @@ -290,14 +290,14 @@ def test_authenticator_request_retries_on_status_code( http: type[httpretty.httpretty], status: int, attempts: int, -): +) -> None: sleep = mocker.patch("time.sleep") sdist_uri = f"https://foo.bar/files/{uuid.uuid4()!s}/foo-0.1.0.tar.gz" content = str(uuid.uuid4()) def callback( - request: requests.Request, uri: str, response_headers: dict - ) -> list[int | dict | str]: + request: requests.Request, uri: str, response_headers: dict[str, str] + ) -> list[int | dict[str, str] | str]: return [status, response_headers, content] http.register_uri(httpretty.GET, sdist_uri, body=callback) @@ -319,7 +319,7 @@ def test_authenticator_uses_env_provided_credentials( mock_remote: type[httpretty.httpretty], http: type[httpretty.httpretty], monkeypatch: MonkeyPatch, -): +) -> None: monkeypatch.setenv("POETRY_HTTP_BASIC_FOO_USERNAME", "bar") monkeypatch.setenv("POETRY_HTTP_BASIC_FOO_PASSWORD", "baz") @@ -350,7 +350,7 @@ def test_authenticator_uses_certs_from_config_if_not_provided( mocker: MockerFixture, cert: str | None, client_cert: str | None, -): +) -> None: configured_cert = "/path/to/cert" configured_client_cert = "/path/to/client-cert" @@ -380,7 +380,7 @@ def test_authenticator_uses_certs_from_config_if_not_provided( def test_authenticator_uses_credentials_from_config_matched_by_url_path( config: Config, mock_remote: None, http: type[httpretty.httpretty] -): +) -> None: config.merge( { "repositories": { @@ -413,7 +413,7 @@ def test_authenticator_uses_credentials_from_config_matched_by_url_path( def test_authenticator_uses_credentials_from_config_with_at_sign_in_path( config: Config, mock_remote: None, http: type[httpretty.httpretty] -): +) -> None: config.merge( { "repositories": { @@ -439,7 +439,7 @@ def test_authenticator_falls_back_to_keyring_url_matched_by_path( http: type[httpretty.httpretty], with_simple_keyring: None, dummy_keyring: DummyBackend, -): +) -> None: config.merge( { "repositories": { @@ -450,10 +450,10 @@ def test_authenticator_falls_back_to_keyring_url_matched_by_path( ) dummy_keyring.set_password( - "https://foo.bar/alpha/files/simple/", None, SimpleCredential(None, "bar") + "https://foo.bar/alpha/files/simple/", None, SimpleCredential("foo", "bar") ) dummy_keyring.set_password( - "https://foo.bar/beta/files/simple/", None, SimpleCredential(None, "baz") + "https://foo.bar/beta/files/simple/", None, SimpleCredential("foo", "baz") ) authenticator = Authenticator(config, NullIO()) @@ -461,13 +461,13 @@ def test_authenticator_falls_back_to_keyring_url_matched_by_path( authenticator.request("get", "https://foo.bar/alpha/files/simple/foo-0.1.0.tar.gz") request = http.last_request() - basic_auth = base64.b64encode(b":bar").decode() + basic_auth = base64.b64encode(b"foo:bar").decode() assert request.headers["Authorization"] == f"Basic {basic_auth}" authenticator.request("get", "https://foo.bar/beta/files/simple/foo-0.1.0.tar.gz") request = http.last_request() - basic_auth = base64.b64encode(b":baz").decode() + basic_auth = base64.b64encode(b"foo:baz").decode() assert request.headers["Authorization"] == f"Basic {basic_auth}" @@ -477,7 +477,7 @@ def test_authenticator_uses_env_provided_credentials_matched_by_url_path( mock_remote: type[httpretty.httpretty], http: type[httpretty.httpretty], monkeypatch: MonkeyPatch, -): +) -> None: monkeypatch.setenv("POETRY_HTTP_BASIC_FOO_ALPHA_USERNAME", "bar") monkeypatch.setenv("POETRY_HTTP_BASIC_FOO_ALPHA_PASSWORD", "alpha") monkeypatch.setenv("POETRY_HTTP_BASIC_FOO_BETA_USERNAME", "baz") @@ -513,7 +513,7 @@ def test_authenticator_azure_feed_guid_credentials( http: type[httpretty.httpretty], with_simple_keyring: None, dummy_keyring: DummyBackend, -): +) -> None: config.merge( { "repositories": { @@ -558,7 +558,7 @@ def test_authenticator_add_repository( http: type[httpretty.httpretty], with_simple_keyring: None, dummy_keyring: DummyBackend, -): +) -> None: config.merge( { "http-basic": { @@ -594,7 +594,7 @@ def test_authenticator_git_repositories( http: type[httpretty.httpretty], with_simple_keyring: None, dummy_keyring: DummyBackend, -): +) -> None: config.merge( { "repositories": { diff --git a/tests/utils/test_password_manager.py b/tests/utils/test_password_manager.py index 468ef14f689..d09f88b1fdf 100644 --- a/tests/utils/test_password_manager.py +++ b/tests/utils/test_password_manager.py @@ -20,7 +20,7 @@ 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)