aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2013-01-26 21:19:35 +1300
committerAldo Cortesi <aldo@nullcube.com>2013-01-26 21:19:35 +1300
commite5b125eec8e732112af9884cf3ab35377913303a (patch)
treed39170962cce39e4c19fa97bd70057fa9a2599bc /test
parentcc4867064be42409fd5fb8271901b03029b787de (diff)
downloadmitmproxy-e5b125eec8e732112af9884cf3ab35377913303a.tar.gz
mitmproxy-e5b125eec8e732112af9884cf3ab35377913303a.tar.bz2
mitmproxy-e5b125eec8e732112af9884cf3ab35377913303a.zip
Introduce the mock module to improve unit tests.
There are a few socket corner-cases that are incredibly hard to reproduce in a unit test suite, so we use mock to trigger the exceptions instead.
Diffstat (limited to 'test')
-rw-r--r--test/test_tcp.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/test/test_tcp.py b/test/test_tcp.py
index ad09143d..e7524fdc 100644
--- a/test/test_tcp.py
+++ b/test/test_tcp.py
@@ -1,5 +1,6 @@
-import cStringIO, threading, Queue, time
+import cStringIO, threading, Queue, time, socket
from netlib import tcp, certutils, test
+import mock
import tutils
class SNIHandler(tcp.BaseHandler):
@@ -275,6 +276,22 @@ class TestFileLike:
s.write("x")
assert s.get_log() == "xx"
+ def test_writer_flush_error(self):
+ s = cStringIO.StringIO()
+ s = tcp.Writer(s)
+ o = mock.MagicMock()
+ o.flush = mock.MagicMock(side_effect=socket.error)
+ s.o = o
+ tutils.raises(tcp.NetLibDisconnect, s.flush)
+
+ def test_reader_read_error(self):
+ s = cStringIO.StringIO("foobar\nfoobar")
+ s = tcp.Reader(s)
+ o = mock.MagicMock()
+ o.read = mock.MagicMock(side_effect=socket.error)
+ s.o = o
+ tutils.raises(tcp.NetLibDisconnect, s.read, 10)
+
def test_reset_timestamps(self):
s = cStringIO.StringIO("foobar\nfoobar")
s = tcp.Reader(s)