Skip to content

Commit c20d199

Browse files
fix(tests): work with all multi-monitor setups (#457)
The setup of having a monitor to the left or above the primary monitor was not working correctly. A number of tests would fail.
1 parent b56744b commit c20d199

2 files changed

Lines changed: 4 additions & 15 deletions

File tree

src/mss/base.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,6 @@ def grab(self, monitor: Monitor | tuple[int, int, int, int], /) -> ScreenShot:
186186
"height": monitor[3] - monitor[1],
187187
}
188188

189-
if monitor["left"] < 0 or monitor["top"] < 0:
190-
msg = f"Region has negative coordinates: {monitor!r}"
191-
raise ScreenShotError(msg)
192189
if monitor["width"] <= 0 or monitor["height"] <= 0:
193190
msg = f"Region has zero or negative size: {monitor!r}"
194191
raise ScreenShotError(msg)

src/tests/test_implementation.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -255,23 +255,15 @@ def test_grab_with_tuple(mss_impl: Callable[..., MSSBase]) -> None:
255255
def test_grab_with_invalid_tuple(mss_impl: Callable[..., MSSBase]) -> None:
256256
with mss_impl() as sct:
257257
# Remember that rect tuples are PIL-style: (left, top, right, bottom)
258+
# Negative left/top coordinates are valid for multi-monitor setups
259+
# where monitors can be positioned to the left of or above the primary.
258260

259-
# Negative top
260-
negative_box = (100, -100, 500, 500)
261-
with pytest.raises(ScreenShotError):
262-
sct.grab(negative_box)
263-
264-
# Negative left
265-
negative_box = (-100, 100, 500, 500)
266-
with pytest.raises(ScreenShotError):
267-
sct.grab(negative_box)
268-
269-
# Negative width (but right > 0)
261+
# Negative width (right < left)
270262
negative_box = (100, 100, 50, 500)
271263
with pytest.raises(ScreenShotError):
272264
sct.grab(negative_box)
273265

274-
# Negative height (but bottom > 0)
266+
# Negative height (bottom < top)
275267
negative_box = (100, 100, 500, 50)
276268
with pytest.raises(ScreenShotError):
277269
sct.grab(negative_box)

0 commit comments

Comments
 (0)