Skip to content

Commit 8156798

Browse files
authored
Merge pull request #3 from radarhere/grabclipboard
Added test
2 parents e7470ed + d57b5e8 commit 8156798

2 files changed

Lines changed: 21 additions & 5 deletions

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: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,18 @@ 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
166-
b"not 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
170+
b" not available",
167171
# xclip, when an image isn't available
168-
b"cannot convert",
172+
b"cannot convert ",
169173
# xclip, when the clipboard isn't initialized
170-
b"There is no owner",
174+
b"xclip: Error: There is no owner for the ",
171175
]:
172-
if err in silent_error:
176+
if silent_error in err:
173177
return None
174178
msg = f"{args[0]} error"
175179
if err:

0 commit comments

Comments
 (0)