Skip to content

Commit 2bb5e68

Browse files
committed
[Clipboard] unit tests
1 parent c8c4a33 commit 2bb5e68

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

tests/test_cmd2.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -937,19 +937,21 @@ def test_init_with_clipboard_allowed() -> None:
937937

938938
def test_pyperclip_exception_on_init(mocker) -> None:
939939
# Force pyperclip.paste to throw an exception
940-
pastemock = mocker.patch("pyperclip.paste")
941-
pastemock.side_effect = ValueError("foo")
940+
_ = mocker.patch("pyperclip.paste", side_effect=ValueError("paste fail on init"))
942941
app = cmd2.Cmd(allow_clipboard=True)
943942

944943
# Check if if the clipboard is an InMemoryClipboard when pyperclip cannot access
945944
# the system clipboard
946945
assert isinstance(app.clipboard, InMemoryClipboard)
947946

948947

948+
@pytest.mark.skipif(not pyperclip_can_paste, reason="Pyperclip could not find a copy/paste mechanism for your system")
949949
def test_get_paste_copy_exception(redirection_app, mocker, capsys) -> None:
950+
# check clipboard type
951+
assert isinstance(redirection_app.clipboard, PyperclipClipboard)
952+
950953
# Force pyperclip.copy to throw an exception
951-
copymock = mocker.patch("pyperclip.copy")
952-
copymock.side_effect = ValueError("copy fail")
954+
_ = mocker.patch("pyperclip.copy", side_effect=ValueError("copy fail"))
953955

954956
# Redirect command output to the clipboard
955957
redirection_app.onecmd_plus_hooks("print_output > ")
@@ -966,10 +968,13 @@ def test_get_paste_copy_exception(redirection_app, mocker, capsys) -> None:
966968
assert out == "print\n"
967969

968970

971+
@pytest.mark.skipif(not pyperclip_can_paste, reason="Pyperclip could not find a copy/paste mechanism for your system")
969972
def test_get_paste_buffer_exception(redirection_app, mocker, capsys) -> None:
973+
# check clipboard type
974+
assert isinstance(redirection_app.clipboard, PyperclipClipboard)
975+
970976
# Force pyperclip.paste to throw an exception
971-
pastemock = mocker.patch("pyperclip.paste")
972-
pastemock.side_effect = ValueError("paste fail")
977+
_ = mocker.patch("pyperclip.paste", side_effect=ValueError("paste fail"))
973978

974979
# Redirect command output to the clipboard
975980
redirection_app.onecmd_plus_hooks("print_output > ")

0 commit comments

Comments
 (0)