aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorSamoilenko Roman <ttahabatt@gmail.com>2018-02-03 14:53:09 +0200
committerMaximilian Hils <git@maximilianhils.com>2018-02-03 13:53:09 +0100
commit773325262790b419e2865adcf9b151f7cbc5d17a (patch)
treec82e4a321070ad0b7f9367bb290ad3ef33e12381 /test
parent957a630bb5d2fcd6a8ad7092863d19e38307f090 (diff)
downloadmitmproxy-773325262790b419e2865adcf9b151f7cbc5d17a.tar.gz
mitmproxy-773325262790b419e2865adcf9b151f7cbc5d17a.tar.bz2
mitmproxy-773325262790b419e2865adcf9b151f7cbc5d17a.zip
don't raise when pyperclip doesn't find a clipboard, fix #2816
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/addons/test_cut.py8
-rw-r--r--test/mitmproxy/addons/test_export.py13
2 files changed, 19 insertions, 2 deletions
diff --git a/test/mitmproxy/addons/test_cut.py b/test/mitmproxy/addons/test_cut.py
index 266f9de7..56568f21 100644
--- a/test/mitmproxy/addons/test_cut.py
+++ b/test/mitmproxy/addons/test_cut.py
@@ -7,6 +7,7 @@ from mitmproxy.test import taddons
from mitmproxy.test import tflow
from mitmproxy.test import tutils
import pytest
+import pyperclip
from unittest import mock
@@ -89,6 +90,13 @@ def test_cut_clip():
tctx.command(c.clip, "@all", "request.method,request.content")
assert pc.called
+ with mock.patch('pyperclip.copy') as pc:
+ log_message = "Pyperclip could not find a " \
+ "copy/paste mechanism for your system."
+ pc.side_effect = pyperclip.PyperclipException(log_message)
+ tctx.command(c.clip, "@all", "request.method")
+ assert tctx.master.has_log(log_message, level="error")
+
def test_cut_save(tmpdir):
f = str(tmpdir.join("path"))
diff --git a/test/mitmproxy/addons/test_export.py b/test/mitmproxy/addons/test_export.py
index 4ceb0429..07227a7a 100644
--- a/test/mitmproxy/addons/test_export.py
+++ b/test/mitmproxy/addons/test_export.py
@@ -1,6 +1,8 @@
-import pytest
import os
+import pytest
+import pyperclip
+
from mitmproxy import exceptions
from mitmproxy.addons import export # heh
from mitmproxy.test import tflow
@@ -111,7 +113,7 @@ def test_export_open(exception, log_message, tmpdir):
def test_clip(tmpdir):
e = export.Export()
- with taddons.context():
+ with taddons.context() as tctx:
with pytest.raises(exceptions.CommandError):
e.clip("nonexistent", tflow.tflow(resp=True))
@@ -122,3 +124,10 @@ def test_clip(tmpdir):
with mock.patch('pyperclip.copy') as pc:
e.clip("curl", tflow.tflow(resp=True))
assert pc.called
+
+ with mock.patch('pyperclip.copy') as pc:
+ log_message = "Pyperclip could not find a " \
+ "copy/paste mechanism for your system."
+ pc.side_effect = pyperclip.PyperclipException(log_message)
+ e.clip("raw", tflow.tflow(resp=True))
+ assert tctx.master.has_log(log_message, level="error")