summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2017-06-30 17:11:06 -0400
committerTodd Leonhardt <todd.leonhardt@gmail.com>2017-06-30 17:11:06 -0400
commit959aeed2438f00720845383daba2a1f30097a8dc (patch)
tree9b12aa422b2a8b19d47b8045c8a76368d5254d7d
parentff3583a67ee02550acbfe85c1599688d941643cf (diff)
downloadcmd2-git-959aeed2438f00720845383daba2a1f30097a8dc.tar.gz
Added code to set can_clip to False on Linux if can't copy/paste clipboard
If Pyperclip could not find a copy/paste mechanism for your system, then cmd2.can_clip gets set to False. If cmd2.can_clip is False, then the "send_to_paste_buffer" test gets skipped.
-rwxr-xr-xcmd2.py7
-rw-r--r--tests/test_cmd2.py11
2 files changed, 10 insertions, 8 deletions
diff --git a/cmd2.py b/cmd2.py
index cbb98ec7..97160515 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -303,8 +303,13 @@ def options(option_list, arg_desc="arg"):
return option_setup
-# Can we access the clipboard?
+# Can we access the clipboard, always true on Windows and Mac, but only sometimes on Linux
can_clip = True
+if sys.platform == 'linux':
+ try:
+ pyperclip.paste()
+ except pyperclip.exceptions.PyperclipException:
+ can_clip = False
def get_paste_buffer():
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index db7f8cf7..d288f78f 100644
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -472,23 +472,20 @@ def test_pipe_to_shell(base_app):
assert out[0].strip() == expected[0].strip()
+@pytest.mark.skipif(not cmd2.can_clip,
+ reason="Pyperclip could not find a copy/paste mechanism for your system")
def test_send_to_paste_buffer(base_app):
from cmd2 import can_clip
# Test writing to the PasteBuffer/Clipboard
run_cmd(base_app, 'help >')
expected = normalize(BASE_HELP)
-
- # If the tools for interacting with the clipboard/pastebuffer are available
- if cmd2.can_clip:
- # Read from the clipboard
- assert normalize(cmd2.get_paste_buffer()) == expected
+ assert normalize(cmd2.get_paste_buffer()) == expected
# Test appending to the PasteBuffer/Clipboard
run_cmd(base_app, 'help history >>')
expected = normalize(BASE_HELP + '\n' + HELP_HISTORY)
- if cmd2.can_clip:
- assert normalize(cmd2.get_paste_buffer()) == expected
+ assert normalize(cmd2.get_paste_buffer()) == expected
def test_base_timing(base_app, capsys):