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 241c190
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 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,22 +25,19 @@ 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"):
ImageGrab.grab()
# test XCB is used when gnome-screenshot is not available
with monkeypatch.setattr(shutil, "which", lambda x: False):
ImageGrab.grab()

ImageGrab.grab(xdisplay="")
except OSError as e:
pytest.skip(str(e))

@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 241c190

Please sign in to comment.