summaryrefslogtreecommitdiff
path: root/sleekxmpp/test/mocksocket.py
diff options
context:
space:
mode:
authorLance Stout <lance@dingus.local>2011-05-27 11:01:30 -0700
committerLance Stout <lance@dingus.local>2011-05-27 11:01:30 -0700
commit384e1a92b716250c168f5dedc1f9693111f81423 (patch)
tree431d0e7718f365a93ce01e5922e71c2d050bcac0 /sleekxmpp/test/mocksocket.py
parentec9aed5b751cac187b774794c7d8ca9de298838a (diff)
downloadslixmpp-384e1a92b716250c168f5dedc1f9693111f81423.tar.gz
slixmpp-384e1a92b716250c168f5dedc1f9693111f81423.tar.bz2
slixmpp-384e1a92b716250c168f5dedc1f9693111f81423.tar.xz
slixmpp-384e1a92b716250c168f5dedc1f9693111f81423.zip
Added support for testind disconnect errors.
Diffstat (limited to 'sleekxmpp/test/mocksocket.py')
-rw-r--r--sleekxmpp/test/mocksocket.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/sleekxmpp/test/mocksocket.py b/sleekxmpp/test/mocksocket.py
index e3ddd700..a2af8d6b 100644
--- a/sleekxmpp/test/mocksocket.py
+++ b/sleekxmpp/test/mocksocket.py
@@ -39,6 +39,7 @@ class TestSocket(object):
self.recv_queue = queue.Queue()
self.send_queue = queue.Queue()
self.is_live = False
+ self.disconnected = False
def __getattr__(self, name):
"""
@@ -89,6 +90,13 @@ class TestSocket(object):
"""
self.recv_queue.put(data)
+ def disconnect_error(self):
+ """
+ Simulate a disconnect error by raising a socket.error exception
+ for any current or further socket operations.
+ """
+ self.disconnected = True
+
# ------------------------------------------------------------------
# Socket Interface
@@ -99,6 +107,8 @@ class TestSocket(object):
Arguments:
Placeholders. Same as for socket.Socket.recv.
"""
+ if self.disconnected:
+ raise socket.error
return self.read(block=True)
def send(self, data):
@@ -108,6 +118,8 @@ class TestSocket(object):
Arguments:
data -- String value to write.
"""
+ if self.disconnected:
+ raise socket.error
self.send_queue.put(data)
# ------------------------------------------------------------------
@@ -132,6 +144,8 @@ class TestSocket(object):
timeout -- Time in seconds a block should last before
returning None.
"""
+ if self.disconnected:
+ raise socket.error
if timeout is not None:
block = True
try: