Skip to content

Commit 2e351be

Browse files
branchvneersighted
authored andcommitted
chore(mypy): check tests
1 parent b13b1de commit 2e351be

File tree

7 files changed

+28
-27
lines changed

7 files changed

+28
-27
lines changed

pyproject.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,11 @@ lines_between_types = 1
4141
lines_after_imports = 2
4242

4343
[tool.mypy]
44-
check_untyped_defs = true
4544
ignore_missing_imports = true
4645
show_error_codes = true
47-
warn_redundant_casts = true
48-
warn_unused_configs = true
49-
warn_unused_ignores = true
46+
strict = true
5047
enable_error_code = ["ignore-without-code"]
51-
files = "src"
48+
files = ["src", "tests"]
5249

5350
[build-system]
5451
requires = ["poetry-core"]

src/poetry_plugin_bundle/bundlers/venv_bundler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def bundle(self, poetry: Poetry, io: IO) -> bool:
153153
poetry.package.name,
154154
poetry.package.version,
155155
source_type="file",
156-
source_url=wheel,
156+
source_url=str(wheel),
157157
)
158158
installer.executor.execute([Install(package)])
159159
except ModuleOrPackageNotFound:
@@ -216,7 +216,7 @@ def _get_executable_info(self, executable: str) -> tuple[str, Version]:
216216
pass
217217

218218
try:
219-
python_version = subprocess.check_output(
219+
python_version_str = subprocess.check_output(
220220
list_to_shell_command(
221221
[
222222
executable,
@@ -232,6 +232,6 @@ def _get_executable_info(self, executable: str) -> tuple[str, Version]:
232232

233233
raise EnvCommandError(e)
234234

235-
python_version = Version.parse(python_version.strip())
235+
python_version = Version.parse(python_version_str.strip())
236236

237237
return executable, python_version

tests/bundlers/test_bundler_manager.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ class MockBundler(Bundler):
1212
name = "mock"
1313

1414

15-
def test_bundler_returns_an_instance_of_the_correct_bundler_class():
15+
def test_bundler_returns_an_instance_of_the_correct_bundler_class() -> None:
1616
manager = BundlerManager()
1717

1818
bundler = manager.bundler("venv")
1919
assert isinstance(bundler, Bundler)
2020
assert bundler.name == "venv"
2121

2222

23-
def test_bundler_raises_an_error_for_incorrect_bundler_classes():
23+
def test_bundler_raises_an_error_for_incorrect_bundler_classes() -> None:
2424
manager = BundlerManager()
2525

2626
with pytest.raises(
@@ -29,7 +29,7 @@ def test_bundler_raises_an_error_for_incorrect_bundler_classes():
2929
manager.bundler("mock")
3030

3131

32-
def test_register_bundler_class_registers_new_bundler_classes():
32+
def test_register_bundler_class_registers_new_bundler_classes() -> None:
3333
manager = BundlerManager()
3434
manager.register_bundler_class(MockBundler)
3535

@@ -38,7 +38,7 @@ def test_register_bundler_class_registers_new_bundler_classes():
3838
assert bundler.name == "mock"
3939

4040

41-
def test_register_bundler_class_cannot_register_existing_bundler_classes():
41+
def test_register_bundler_class_cannot_register_existing_bundler_classes() -> None:
4242
manager = BundlerManager()
4343
manager.register_bundler_class(MockBundler)
4444

tests/bundlers/test_venv_bundler.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def poetry(config: Config) -> Poetry:
5353

5454
def test_bundler_should_build_a_new_venv_with_existing_python(
5555
io: BufferedIO, tmpdir: str, poetry: Poetry, mocker: MockerFixture
56-
):
56+
) -> None:
5757
shutil.rmtree(tmpdir)
5858
mocker.patch("poetry.installation.executor.Executor._execute_operation")
5959

@@ -75,7 +75,7 @@ def test_bundler_should_build_a_new_venv_with_existing_python(
7575

7676
def test_bundler_should_build_a_new_venv_with_given_executable(
7777
io: BufferedIO, tmpdir: str, poetry: Poetry, mocker: MockerFixture
78-
):
78+
) -> None:
7979
shutil.rmtree(tmpdir)
8080
mocker.patch("poetry.installation.executor.Executor._execute_operation")
8181

@@ -98,7 +98,7 @@ def test_bundler_should_build_a_new_venv_with_given_executable(
9898

9999
def test_bundler_should_build_a_new_venv_if_existing_venv_is_incompatible(
100100
io: BufferedIO, tmpdir: str, poetry: Poetry, mocker: MockerFixture
101-
):
101+
) -> None:
102102
mocker.patch("poetry.installation.executor.Executor._execute_operation")
103103

104104
bundler = VenvBundler()
@@ -120,7 +120,7 @@ def test_bundler_should_build_a_new_venv_if_existing_venv_is_incompatible(
120120

121121
def test_bundler_should_use_an_existing_venv_if_compatible(
122122
io: BufferedIO, tmp_venv: VirtualEnv, poetry: Poetry, mocker: MockerFixture
123-
):
123+
) -> None:
124124
mocker.patch("poetry.installation.executor.Executor._execute_operation")
125125

126126
bundler = VenvBundler()
@@ -141,7 +141,7 @@ def test_bundler_should_use_an_existing_venv_if_compatible(
141141

142142
def test_bundler_should_remove_an_existing_venv_if_forced(
143143
io: BufferedIO, tmp_venv: VirtualEnv, poetry: Poetry, mocker: MockerFixture
144-
):
144+
) -> None:
145145
mocker.patch("poetry.installation.executor.Executor._execute_operation")
146146

147147
bundler = VenvBundler()
@@ -165,7 +165,7 @@ def test_bundler_should_remove_an_existing_venv_if_forced(
165165

166166
def test_bundler_should_fail_when_installation_fails(
167167
io: BufferedIO, tmpdir: str, poetry: Poetry, mocker: MockerFixture
168-
):
168+
) -> None:
169169
mocker.patch(
170170
"poetry.installation.executor.Executor._do_execute_operation",
171171
side_effect=Exception(),
@@ -189,7 +189,7 @@ def test_bundler_should_fail_when_installation_fails(
189189

190190
def test_bundler_should_display_a_warning_for_projects_with_no_module(
191191
io: BufferedIO, tmp_venv: VirtualEnv, mocker: MockerFixture, config: Config
192-
):
192+
) -> None:
193193
poetry = Factory().create_poetry(
194194
Path(__file__).parent.parent / "fixtures" / "simple_project_with_no_module"
195195
)

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def config(
5656

5757
from keyring.backends.fail import Keyring
5858

59-
keyring.set_keyring(Keyring())
59+
keyring.set_keyring(Keyring()) # type: ignore[no-untyped-call]
6060

6161
c = Config()
6262
c.merge(config_source.config)

tests/console/commands/bundle/test_venv.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
from pytest_mock import MockerFixture
1212

1313

14-
def test_venv_calls_venv_bundler(app_tester: ApplicationTester, mocker: MockerFixture):
14+
def test_venv_calls_venv_bundler(
15+
app_tester: ApplicationTester, mocker: MockerFixture
16+
) -> None:
1517
mock = mocker.patch(
1618
"poetry_plugin_bundle.bundlers.venv_bundler.VenvBundler.bundle",
1719
side_effect=[True, False],

tests/helpers.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
from typing import TYPE_CHECKING
4+
from typing import Any
45

56
from poetry.console.application import Application
67
from poetry.core.toml.file import TOMLFile
@@ -12,6 +13,7 @@
1213
from pathlib import Path
1314

1415
from poetry.poetry import Poetry
16+
from tomlkit.toml_document import TOMLDocument
1517

1618

1719
class TestApplication(Application):
@@ -21,7 +23,8 @@ def __init__(self, poetry: Poetry) -> None:
2123

2224
def reset_poetry(self) -> None:
2325
poetry = self._poetry
24-
self._poetry = Factory().create_poetry(self._poetry.file.path.parent)
26+
assert poetry is not None
27+
self._poetry = Factory().create_poetry(poetry.file.path.parent)
2528
self._poetry.set_pool(poetry.pool)
2629
self._poetry.set_config(poetry.config)
2730
self._poetry.set_locker(
@@ -30,13 +33,12 @@ def reset_poetry(self) -> None:
3033

3134

3235
class TestLocker(Locker):
33-
def __init__(self, lock: str | Path, local_config: dict) -> None:
36+
def __init__(self, lock: str | Path, local_config: dict[str, Any]) -> None:
3437
self._lock = TOMLFile(lock)
3538
self._local_config = local_config
36-
self._lock_data: dict | None = None
39+
self._lock_data: TOMLDocument | None = None
3740
self._content_hash = self._get_content_hash()
3841
self._locked = False
39-
self._lock_data = None
4042
self._write = False
4143

4244
def write(self, write: bool = True) -> None:
@@ -50,15 +52,15 @@ def locked(self, is_locked: bool = True) -> TestLocker:
5052

5153
return self
5254

53-
def mock_lock_data(self, data: dict) -> None:
55+
def mock_lock_data(self, data: TOMLDocument) -> None:
5456
self.locked()
5557

5658
self._lock_data = data
5759

5860
def is_fresh(self) -> bool:
5961
return True
6062

61-
def _write_lock_data(self, data: dict) -> None:
63+
def _write_lock_data(self, data: TOMLDocument) -> None:
6264
if self._write:
6365
super()._write_lock_data(data)
6466
self._locked = True

0 commit comments

Comments
 (0)