Skip to content

Commit

Permalink
some unit test typechecking (#7802)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby authored Apr 16, 2023
1 parent 3855bc5 commit 99f106c
Show file tree
Hide file tree
Showing 33 changed files with 410 additions and 365 deletions.
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -178,6 +183,10 @@ warn_unused_ignores = false
[[tool.mypy.overrides]]
module = [
'cachecontrol.*',
'cachy.*',
'deepdiff.*',
'httpretty.*',
'keyring.*',
'lockfile.*',
'pexpect.*',
'requests_toolbelt.*',
Expand Down
11 changes: 6 additions & 5 deletions tests/config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from pathlib import Path
from typing import TYPE_CHECKING
from typing import Any

import pytest

Expand All @@ -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:
Expand All @@ -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")


Expand All @@ -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

Expand All @@ -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
4 changes: 2 additions & 2 deletions tests/console/commands/cache/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""\
Expand All @@ -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 = """\
Expand Down
8 changes: 5 additions & 3 deletions tests/console/commands/debug/test_resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """\
Expand All @@ -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 = """\
Expand All @@ -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 = """\
Expand Down
12 changes: 7 additions & 5 deletions tests/console/commands/env/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -48,29 +48,31 @@ 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


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


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
10 changes: 5 additions & 5 deletions tests/console/commands/env/test_remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:]
Expand Down
16 changes: 8 additions & 8 deletions tests/console/commands/self/test_add_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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"))

Expand All @@ -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")
Expand All @@ -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"))

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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"))

Expand Down
4 changes: 2 additions & 2 deletions tests/console/commands/self/test_remove_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """\
Expand All @@ -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"""\
Expand Down
6 changes: 3 additions & 3 deletions tests/console/commands/self/test_show_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def mock_metadata_entry_points(
def test_show_displays_installed_plugins(
app: PoetryTestApplication,
tester: CommandTester,
):
) -> None:
tester.execute("")

expected = """
Expand All @@ -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 = """
Expand All @@ -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 = """
Expand Down
2 changes: 1 addition & 1 deletion tests/console/commands/test_about.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading

0 comments on commit 99f106c

Please sign in to comment.