From 1e2665df19a866d5676abec566b9d8f190ecdc80 Mon Sep 17 00:00:00 2001 From: mathieui Date: Thu, 12 Feb 2015 12:23:47 +0100 Subject: Update the test suite. - monkey-patch our own monkey-patched idle_call to run events immediatly rather than adding them to the event queue, and add a fake transport with a fake socket. - remove the test file related to xep_0059 as it relies on blocking behavior, and comment out one xep_0030 test uses xep_0059 - remove many instances of threading and sleep()s because they do nothing except waste time and introduce race conditions. - keep exactly two sleep() in IoT xeps because they rely on timeouts --- slixmpp/test/mocksocket.py | 89 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) (limited to 'slixmpp/test/mocksocket.py') diff --git a/slixmpp/test/mocksocket.py b/slixmpp/test/mocksocket.py index 79961279..9583231e 100644 --- a/slixmpp/test/mocksocket.py +++ b/slixmpp/test/mocksocket.py @@ -150,3 +150,92 @@ class TestSocket(object): return self.recv_queue.get(block, timeout) except: return None + +class TestTransport(object): + + """ + A transport socket that reads and writes to queues instead + of an actual networking socket. + + Methods: + next_sent -- Return the next sent stanza. + recv_data -- Make a stanza available to read next. + recv -- Read the next stanza from the socket. + send -- Write a stanza to the socket. + makefile -- Dummy call, returns self. + read -- Read the next stanza from the socket. + """ + + def __init__(self, xmpp): + self.xmpp = xmpp + self.socket = TestSocket() + # ------------------------------------------------------------------ + # Testing Interface + + def next_sent(self, timeout=None): + """ + Get the next stanza that has been 'sent'. + + Arguments: + timeout -- Optional timeout for waiting for a new value. + """ + return self.socket.next_sent() + + def disconnect_error(self): + """ + Simulate a disconnect error by raising a socket.error exception + for any current or further socket operations. + """ + self.socket.disconnect_error() + + # ------------------------------------------------------------------ + # Socket Interface + + def recv(self, *args, **kwargs): + """ + Read a value from the received queue. + + Arguments: + Placeholders. Same as for socket.Socket.recv. + """ + return + + def write(self, data): + """ + Send data by placing it in the send queue. + + Arguments: + data -- String value to write. + """ + self.socket.send(data) + return len(data) + + # ------------------------------------------------------------------ + # File Socket + + def makefile(self, *args, **kwargs): + """ + File socket version to use with ElementTree. + + Arguments: + Placeholders, same as socket.Socket.makefile() + """ + return self + + def read(self, block=True, timeout=None, **kwargs): + """ + Implement the file socket interface. + + Arguments: + block -- Indicate if the read should block until a + value is ready. + timeout -- Time in seconds a block should last before + returning None. + """ + return self.socket.recv(block, timeout, **kwargs) + + def get_extra_info(self, *args, **kwargs): + return self.socket + + def abort(self, *args, **kwargs): + return -- cgit v1.2.3