Skip to content

Commit

Permalink
update ImageGrab tests for python-pillow#6361
Browse files Browse the repository at this point in the history
  • Loading branch information
nulano committed Nov 1, 2022
1 parent 7854f6c commit ebec6c1
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions Tests/test_imagegrab.py
@@ -1,4 +1,5 @@
import os
import shutil
import subprocess
import sys

Expand All @@ -11,7 +12,9 @@

class TestImageGrab:
@pytest.mark.skipif(
sys.platform not in ("win32", "darwin"), reason="requires Windows or macOS"
sys.platform not in ("win32", "darwin")
and not shutil.which("gnome-screenshot"),
reason="requires Windows or macOS, or Linux with gnome-screenshot",
)
def test_grab(self):
ImageGrab.grab()
Expand All @@ -22,9 +25,11 @@ def test_grab(self):
assert im.size == (40, 60)

@skip_unless_feature("xcb")
def test_grab_x11(self):
def test_grab_xcb(self, monkeypatch):
try:
if sys.platform not in ("win32", "darwin"):
# test XCB is used when gnome-screenshot is not available
monkeypatch.setattr(shutil, "which", lambda x: False)
ImageGrab.grab()

ImageGrab.grab(xdisplay="")
Expand All @@ -33,11 +38,6 @@ def test_grab_x11(self):

@pytest.mark.skipif(Image.core.HAVE_XCB, reason="tests missing XCB")
def test_grab_no_xcb(self):
if sys.platform not in ("win32", "darwin"):
with pytest.raises(OSError) as e:
ImageGrab.grab()
assert str(e.value).startswith("Pillow was built without XCB support")

with pytest.raises(OSError) as e:
ImageGrab.grab(xdisplay="")
assert str(e.value).startswith("Pillow was built without XCB support")
Expand Down

0 comments on commit ebec6c1

Please sign in to comment.