Skip to content

Commit 5efa2ad

Browse files
committed
Added test
1 parent 39cbd4f commit 5efa2ad

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

Tests/test_imagegrab.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,15 @@ def test_grabclipboard_wl_clipboard(self, ext):
119119
subprocess.call(["wl-copy"], stdin=fp)
120120
im = ImageGrab.grabclipboard()
121121
assert_image_equal_tofile(im, image_path)
122+
123+
@pytest.mark.skipif(
124+
(
125+
sys.platform != "linux"
126+
or not all(shutil.which(cmd) for cmd in ("wl-paste", "wl-copy"))
127+
),
128+
reason="Linux with wl-clipboard only",
129+
)
130+
@pytest.mark.parametrize("arg", ("text", "--clear"))
131+
def test_grabclipboard_wl_clipboard_errors(self, arg):
132+
subprocess.call(["wl-copy", arg])
133+
assert ImageGrab.grabclipboard() is None

src/PIL/ImageGrab.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,11 @@ def grabclipboard():
162162
for silent_error in [
163163
# wl-paste, when the clipboard is empty
164164
b"Nothing is copied",
165-
# wl-paste/debian xclip, when an image isn't available
165+
# Ubuntu/Debian wl-paste, when the clipboard is empty
166+
b"No selection",
167+
# Ubuntu/Debian wl-paste, when an image isn't available
168+
b"No suitable type of content copied",
169+
# wl-paste or Ubuntu/Debian xclip, when an image isn't available
166170
b" not available",
167171
# xclip, when an image isn't available
168172
b"cannot convert ",

0 commit comments

Comments
 (0)