diff --git a/pyproject.toml b/pyproject.toml index e3ccc7e..c538a95 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,7 +37,7 @@ packages = [ ] [tool.mypy] -files = ["src"] +files = ['src', 'tests'] mypy_path = 'src' explicit_package_bases = true strict = true diff --git a/tests/demo/test__main.py b/tests/demo/test__main.py index 775b212..d4cbd79 100644 --- a/tests/demo/test__main.py +++ b/tests/demo/test__main.py @@ -3,7 +3,7 @@ from pathlib import Path -def test_quickstart_runs(): +def test_quickstart_runs() -> None: script = Path("demo/main.py") result = subprocess.run( diff --git a/tests/driver/test_close.py b/tests/driver/test_close.py index 880164c..f462996 100644 --- a/tests/driver/test_close.py +++ b/tests/driver/test_close.py @@ -21,12 +21,12 @@ @pytest.fixture(scope="function", autouse=True) -def setup(request: FixtureRequest) -> Generator[None]: +def setup(request: FixtureRequest) -> Generator[None, None, None]: self: HasTestContextDesktopDriver = request.instance self.desktop_driver = DesktopDriverWindowsImplementation() node: Node = request.node self.test_case_name = node.name - return + yield @pytest.fixture(scope="function") diff --git a/tests/driver/test_find_element_by_image.py b/tests/driver/test_find_element_by_image.py index 11d5c31..21d7ec2 100644 --- a/tests/driver/test_find_element_by_image.py +++ b/tests/driver/test_find_element_by_image.py @@ -42,13 +42,13 @@ @pytest.fixture(scope="function", autouse=True) -def setup(request: FixtureRequest) -> Generator[None]: +def setup(request: FixtureRequest) -> Generator[None, None, None]: self: HasTestContextDesktopDriver = request.instance setup_common_paths(request) self.desktop_driver = DesktopDriverWindowsImplementation() node: Node = request.node self.test_case_name = node.name - return + yield class TestFindElementByImage: @@ -56,7 +56,7 @@ class TestFindElementByImage: test_case_name: str test_suite_output_dir: str - def test_match_with_color_param(self): + def test_match_with_color_param(self) -> None: gui_code_snippet = f""" import tkinter as tk root = tk.Tk() @@ -105,7 +105,7 @@ def test_match_with_color_param(self): self.desktop_driver.close(OS_PROCESS_KILL_TIMEOUT=OS_PROCESS_KILL_TIMEOUT) - def test_image_detected_by_template_matching(self): + def test_image_detected_by_template_matching(self) -> None: gui_code_snippet = f""" import tkinter as tk root = tk.Tk() @@ -138,7 +138,7 @@ def test_image_detected_by_template_matching(self): self.desktop_driver.close(OS_PROCESS_KILL_TIMEOUT=OS_PROCESS_KILL_TIMEOUT) - def test_image_detected_with_altered_colors(self): + def test_image_detected_with_altered_colors(self) -> None: gui_code_snippet = f""" import tkinter as tk root = tk.Tk() @@ -171,7 +171,7 @@ def test_image_detected_with_altered_colors(self): self.desktop_driver.close(OS_PROCESS_KILL_TIMEOUT=OS_PROCESS_KILL_TIMEOUT) - def test_element_detected_after_motion_stops(self): + def test_element_detected_after_motion_stops(self) -> None: gui_code_snippet = f""" import tkinter as tk, time, threading root = tk.Tk() @@ -213,7 +213,7 @@ def move(): self.desktop_driver.close(OS_PROCESS_KILL_TIMEOUT=OS_PROCESS_KILL_TIMEOUT) - def test_element_detected_despite_background_motion(self): + def test_element_detected_despite_background_motion(self) -> None: gui_code_snippet = f""" import tkinter as tk, threading, time root = tk.Tk() @@ -256,7 +256,7 @@ def wiggle(): self.desktop_driver.close(OS_PROCESS_KILL_TIMEOUT=OS_PROCESS_KILL_TIMEOUT) - def test_element_detected_but_not_stable(self): + def test_element_detected_but_not_stable(self) -> None: gui_code_snippet = f""" import tkinter as tk, threading, time root = tk.Tk() @@ -299,7 +299,7 @@ def wiggle(): self.desktop_driver.close(OS_PROCESS_KILL_TIMEOUT=OS_PROCESS_KILL_TIMEOUT) - def test_element_not_found(self): + def test_element_not_found(self) -> None: gui_code_snippet = f""" import tkinter as tk root = tk.Tk() @@ -332,7 +332,7 @@ def test_element_not_found(self): self.desktop_driver.close(OS_PROCESS_KILL_TIMEOUT=OS_PROCESS_KILL_TIMEOUT) - def test_click_on_abrir_button_with_alpha_centered_image(self): + def test_click_on_abrir_button_with_alpha_centered_image(self) -> None: gui_code_snippet = f""" import tkinter as tk root = tk.Tk() diff --git a/tests/driver/test_find_window.py b/tests/driver/test_find_window.py index ee2eed4..7690d6e 100644 --- a/tests/driver/test_find_window.py +++ b/tests/driver/test_find_window.py @@ -28,12 +28,12 @@ @pytest.fixture(scope="function", autouse=True) -def setup(request: FixtureRequest) -> Generator[None]: +def setup(request: FixtureRequest) -> Generator[None, None, None]: self: HasTestContextDesktopDriver = request.instance self.desktop_driver = DesktopDriverWindowsImplementation() node: Node = request.node self.test_case_name = node.name - return + yield @pytest.fixture(scope="function") @@ -52,10 +52,10 @@ def dummy_app_path(request: FixtureRequest, tmp_path: Path) -> Path: return path -def launch_gui_subprocess(script_path: Path) -> subprocess.Popen: +def launch_gui_subprocess(script_path: Path) -> subprocess.Popen[bytes]: proc = subprocess.Popen(["python", str(script_path)]) for _ in range(30): - if any(script_path.stem == w.title for w in pywinctl.getAllWindows()): + if any(script_path.stem == w.title for w in pywinctl.getAllWindows()): # type: ignore[no-untyped-call] break time.sleep(0.1) return proc diff --git a/tests/driver/test_switch_to.py b/tests/driver/test_switch_to.py index 6893b60..aa755c9 100644 --- a/tests/driver/test_switch_to.py +++ b/tests/driver/test_switch_to.py @@ -1,6 +1,7 @@ import os import re from collections.abc import Generator +from typing import Any import pytest import pywinctl @@ -24,13 +25,13 @@ @pytest.fixture(scope="function", autouse=True) -def setup(request: FixtureRequest) -> Generator[None]: +def setup(request: FixtureRequest) -> Generator[None, None, None]: self: HasTestContextDesktopDriver = request.instance setup_common_paths(request) self.desktop_driver = DesktopDriverWindowsImplementation() node: Node = request.node self.test_case_name = node.name - return + yield class TestSwitchTo: @@ -39,12 +40,14 @@ class TestSwitchTo: test_suite_output_dir: str def test_switch_to_raises_on_invalid_type(self) -> None: + invalid_target: Any = "not a window object" with pytest.raises(TypeError): - self.desktop_driver.switch_to(target_window="not a window object") + self.desktop_driver.switch_to(target_window=invalid_target) def test_switch_to_raises_on_none(self) -> None: + invalid_target: Any = None with pytest.raises(TypeError): - self.desktop_driver.switch_to(target_window=None) + self.desktop_driver.switch_to(target_window=invalid_target) def test_switch_to_activates_window(self) -> None: gui_code_snippet = f""" diff --git a/tests/driver/test_wait_for_window_to_disappear.py b/tests/driver/test_wait_for_window_to_disappear.py index 1d45512..a45fc53 100644 --- a/tests/driver/test_wait_for_window_to_disappear.py +++ b/tests/driver/test_wait_for_window_to_disappear.py @@ -28,12 +28,12 @@ @pytest.fixture(scope="function", autouse=True) -def setup(request: FixtureRequest) -> Generator[None]: +def setup(request: FixtureRequest) -> Generator[None, None, None]: self: HasTestContextDesktopDriver = request.instance self.desktop_driver = DesktopDriverWindowsImplementation() node: Node = request.node self.test_case_name = node.name - return + yield @pytest.fixture(scope="function") @@ -52,10 +52,10 @@ def dummy_app_path(request: FixtureRequest, tmp_path: Path) -> Path: return path -def launch_gui_subprocess(script_path: Path) -> subprocess.Popen: +def launch_gui_subprocess(script_path: Path) -> subprocess.Popen[bytes]: proc = subprocess.Popen(["python", str(script_path)]) for _ in range(30): - if any(script_path.stem == w.title for w in pywinctl.getAllWindows()): + if any(script_path.stem == w.title for w in pywinctl.getAllWindows()): # type: ignore[no-untyped-call] break time.sleep(0.1) return proc diff --git a/tests/element/test_action_click.py b/tests/element/test_action_click.py index 4c889b8..8ea6475 100644 --- a/tests/element/test_action_click.py +++ b/tests/element/test_action_click.py @@ -37,13 +37,13 @@ @pytest.fixture(scope="function", autouse=True) -def setup(request: FixtureRequest) -> Generator[None]: +def setup(request: FixtureRequest) -> Generator[None, None, None]: self: HasTestContextDesktopDriver = request.instance setup_common_paths(request) self.desktop_driver = DesktopDriverWindowsImplementation() node: Node = request.node self.test_case_name = node.name - return + yield class TestClickElement: diff --git a/tests/element/test_action_type.py b/tests/element/test_action_type.py index 2758fc0..5b29136 100644 --- a/tests/element/test_action_type.py +++ b/tests/element/test_action_type.py @@ -40,13 +40,13 @@ @pytest.fixture(scope="function", autouse=True) -def setup(request: FixtureRequest) -> Generator[None]: +def setup(request: FixtureRequest) -> Generator[None, None, None]: self: HasTestContextDesktopDriver = request.instance setup_common_paths(request) self.desktop_driver = DesktopDriverWindowsImplementation() node: Node = request.node self.test_case_name = node.name - return + yield class TestTypeIntoEntry: