From 4116c67cab4878ae0cabb926b18625b88e86dfe3 Mon Sep 17 00:00:00 2001 From: jeanluyac-sketch <338926131+jeanluyac-sketch@users.noreply.github.com> Date: Mon, 30 Nov 2026 23:11:36 +0000 Subject: [PATCH] tests: do not assume the virtual screen starts at 0,0 on Windows test_coordinates_capture expected sct-2x12_40x67.png, but CLI coordinates are relative to monitor 0, whose origin is negative when a monitor sits left of or above the primary one (e.g. left=-1366 gives sct-2x-1354_...). test_callback renamed mon0.png to an existing .old file, which raises FileExistsError on Windows; use Path.replace(). AI-assisted (Claude): drafted with AI, reviewed and run by the author. --- src/tests/test_implementation.py | 6 +++++- src/tests/test_save.py | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/tests/test_implementation.py b/src/tests/test_implementation.py index 7dc8851e..53762427 100644 --- a/src/tests/test_implementation.py +++ b/src/tests/test_implementation.py @@ -250,7 +250,11 @@ def test_output_pattern_with_date(self, with_cursor: bool, capsys: pytest.Captur @pytest.mark.parametrize("coordinates", ["2,12,40,67", "40x67+12+2"]) def test_coordinates_capture(self, with_cursor: bool, capsys: pytest.CaptureFixture, coordinates: str) -> None: - filename = Path("sct-2x12_40x67.png") + # Coordinates are relative to the selected monitor (monitor 0 by default: the whole virtual screen), whose + # origin is not 0,0 when a monitor sits left of or above the primary one. + with mss.MSS() as sct: + origin = sct.monitors[0] + filename = Path(f"sct-{origin.top + 2}x{origin.left + 12}_40x67.png") for opt in ("-c", "--coordinates"): self._run_main(with_cursor, opt, coordinates) captured = capsys.readouterr() diff --git a/src/tests/test_save.py b/src/tests/test_save.py index 8457cefe..7f824df9 100644 --- a/src/tests/test_save.py +++ b/src/tests/test_save.py @@ -39,7 +39,8 @@ def test_callback(mss_impl: Callable[..., MSS]) -> None: def on_exists(fname: str) -> None: file = Path(fname) if Path(file).is_file(): - file.rename(f"{file.name}.old") + # replace() overwrites a leftover .old file on every OS; rename() raises FileExistsError on Windows. + file.replace(f"{file.name}.old") with mss_impl() as sct: filename = sct.shot(mon=0, output="mon0.png", callback=on_exists)