Skip to content

Commit

Permalink
Merge pull request #3 from radarhere/grabclipboard
Browse files Browse the repository at this point in the history
Added test
  • Loading branch information
nik012003 committed Feb 2, 2024
2 parents e7470ed + d57b5e8 commit 8156798
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
12 changes: 12 additions & 0 deletions Tests/test_imagegrab.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,15 @@ def test_grabclipboard_wl_clipboard(self, ext):
subprocess.call(["wl-copy"], stdin=fp)
im = ImageGrab.grabclipboard()
assert_image_equal_tofile(im, image_path)

@pytest.mark.skipif(
(
sys.platform != "linux"
or not all(shutil.which(cmd) for cmd in ("wl-paste", "wl-copy"))
),
reason="Linux with wl-clipboard only",
)
@pytest.mark.parametrize("arg", ("text", "--clear"))
def test_grabclipboard_wl_clipboard_errors(self, arg):
subprocess.call(["wl-copy", arg])
assert ImageGrab.grabclipboard() is None
14 changes: 9 additions & 5 deletions src/PIL/ImageGrab.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,18 @@ def grabclipboard():
for silent_error in [
# wl-paste, when the clipboard is empty
b"Nothing is copied",
# wl-paste/debian xclip, when an image isn't available
b"not available",
# Ubuntu/Debian wl-paste, when the clipboard is empty
b"No selection",
# Ubuntu/Debian wl-paste, when an image isn't available
b"No suitable type of content copied",
# wl-paste or Ubuntu/Debian xclip, when an image isn't available
b" not available",
# xclip, when an image isn't available
b"cannot convert",
b"cannot convert ",
# xclip, when the clipboard isn't initialized
b"There is no owner",
b"xclip: Error: There is no owner for the ",
]:
if err in silent_error:
if silent_error in err:
return None
msg = f"{args[0]} error"
if err:
Expand Down

0 comments on commit 8156798

Please sign in to comment.