Unit test reorganization.
Moved SleekTest to sleekxmpp.test. Organized test suites by their focus. - Suites focused on testing stanza objects are named test_stanza_X.py - Suites focused on testing stream behavior are name test_stream_X.py
This commit is contained in:
parent
21c32c6e1c
commit
0fffbb8200
22 changed files with 192 additions and 171 deletions
10
sleekxmpp/test/__init__.py
Normal file
10
sleekxmpp/test/__init__.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
"""
|
||||
SleekXMPP: The Sleek XMPP Library
|
||||
Copyright (C) 2010 Nathanael C. Fritz, Lance J.T. Stout
|
||||
This file is part of SleekXMPP.
|
||||
|
||||
See the file LICENSE for copying permission.
|
||||
"""
|
||||
|
||||
from sleekxmpp.test.mocksocket import TestSocket
|
||||
from sleekxmpp.test.sleektest import *
|
139
sleekxmpp/test/mocksocket.py
Normal file
139
sleekxmpp/test/mocksocket.py
Normal file
|
@ -0,0 +1,139 @@
|
|||
"""
|
||||
SleekXMPP: The Sleek XMPP Library
|
||||
Copyright (C) 2010 Nathanael C. Fritz, Lance J.T. Stout
|
||||
This file is part of SleekXMPP.
|
||||
|
||||
See the file LICENSE for copying permission.
|
||||
"""
|
||||
|
||||
import socket
|
||||
try:
|
||||
import queue
|
||||
except ImportError:
|
||||
import Queue as queue
|
||||
|
||||
|
||||
class TestSocket(object):
|
||||
|
||||
"""
|
||||
A dummy 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, *args, **kwargs):
|
||||
"""
|
||||
Create a new test socket.
|
||||
|
||||
Arguments:
|
||||
Same as arguments for socket.socket
|
||||
"""
|
||||
self.socket = socket.socket(*args, **kwargs)
|
||||
self.recv_queue = queue.Queue()
|
||||
self.send_queue = queue.Queue()
|
||||
|
||||
def __getattr__(self, name):
|
||||
"""
|
||||
Return attribute values of internal, dummy socket.
|
||||
|
||||
Some attributes and methods are disabled to prevent the
|
||||
socket from connecting to the network.
|
||||
|
||||
Arguments:
|
||||
name -- Name of the attribute requested.
|
||||
"""
|
||||
|
||||
def dummy(*args):
|
||||
"""Method to do nothing and prevent actual socket connections."""
|
||||
return None
|
||||
|
||||
overrides = {'connect': dummy,
|
||||
'close': dummy,
|
||||
'shutdown': dummy}
|
||||
|
||||
return overrides.get(name, getattr(self.socket, name))
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# 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.
|
||||
"""
|
||||
args = {'block': False}
|
||||
if timeout is not None:
|
||||
args = {'block': True, 'timeout': timeout}
|
||||
try:
|
||||
return self.send_queue.get(**args)
|
||||
except:
|
||||
return None
|
||||
|
||||
def recv_data(self, data):
|
||||
"""
|
||||
Add data to the receiving queue.
|
||||
|
||||
Arguments:
|
||||
data -- String data to 'write' to the socket to be received
|
||||
by the XMPP client.
|
||||
"""
|
||||
self.recv_queue.put(data)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Socket Interface
|
||||
|
||||
def recv(self, *args, **kwargs):
|
||||
"""
|
||||
Read a value from the received queue.
|
||||
|
||||
Arguments:
|
||||
Placeholders. Same as for socket.Socket.recv.
|
||||
"""
|
||||
return self.read(block=True)
|
||||
|
||||
def send(self, data):
|
||||
"""
|
||||
Send data by placing it in the send queue.
|
||||
|
||||
Arguments:
|
||||
data -- String value to write.
|
||||
"""
|
||||
self.send_queue.put(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.
|
||||
"""
|
||||
if timeout is not None:
|
||||
block = True
|
||||
try:
|
||||
return self.recv_queue.get(block, timeout)
|
||||
except:
|
||||
return None
|
|
@ -7,145 +7,15 @@
|
|||
"""
|
||||
|
||||
import unittest
|
||||
import socket
|
||||
try:
|
||||
import queue
|
||||
except ImportError:
|
||||
import Queue as queue
|
||||
|
||||
import sleekxmpp
|
||||
from sleekxmpp import ClientXMPP, ComponentXMPP
|
||||
from sleekxmpp.stanza import Message, Iq, Presence
|
||||
from sleekxmpp.test import TestSocket
|
||||
from sleekxmpp.xmlstream.stanzabase import registerStanzaPlugin, ET
|
||||
from sleekxmpp.xmlstream.tostring import tostring
|
||||
|
||||
|
||||
class TestSocket(object):
|
||||
|
||||
"""
|
||||
A dummy 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, *args, **kwargs):
|
||||
"""
|
||||
Create a new test socket.
|
||||
|
||||
Arguments:
|
||||
Same as arguments for socket.socket
|
||||
"""
|
||||
self.socket = socket.socket(*args, **kwargs)
|
||||
self.recv_queue = queue.Queue()
|
||||
self.send_queue = queue.Queue()
|
||||
|
||||
def __getattr__(self, name):
|
||||
"""
|
||||
Return attribute values of internal, dummy socket.
|
||||
|
||||
Some attributes and methods are disabled to prevent the
|
||||
socket from connecting to the network.
|
||||
|
||||
Arguments:
|
||||
name -- Name of the attribute requested.
|
||||
"""
|
||||
|
||||
def dummy(*args):
|
||||
"""Method to do nothing and prevent actual socket connections."""
|
||||
return None
|
||||
|
||||
overrides = {'connect': dummy,
|
||||
'close': dummy,
|
||||
'shutdown': dummy}
|
||||
|
||||
return overrides.get(name, getattr(self.socket, name))
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# 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.
|
||||
"""
|
||||
args = {'block': False}
|
||||
if timeout is not None:
|
||||
args = {'block': True, 'timeout': timeout}
|
||||
try:
|
||||
return self.send_queue.get(**args)
|
||||
except:
|
||||
return None
|
||||
|
||||
def recv_data(self, data):
|
||||
"""
|
||||
Add data to the receiving queue.
|
||||
|
||||
Arguments:
|
||||
data -- String data to 'write' to the socket to be received
|
||||
by the XMPP client.
|
||||
"""
|
||||
self.recv_queue.put(data)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Socket Interface
|
||||
|
||||
def recv(self, *args, **kwargs):
|
||||
"""
|
||||
Read a value from the received queue.
|
||||
|
||||
Arguments:
|
||||
Placeholders. Same as for socket.Socket.recv.
|
||||
"""
|
||||
return self.read(block=True)
|
||||
|
||||
def send(self, data):
|
||||
"""
|
||||
Send data by placing it in the send queue.
|
||||
|
||||
Arguments:
|
||||
data -- String value to write.
|
||||
"""
|
||||
self.send_queue.put(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.
|
||||
"""
|
||||
if timeout is not None:
|
||||
block = True
|
||||
try:
|
||||
return self.recv_queue.get(block, timeout)
|
||||
except:
|
||||
return None
|
||||
|
||||
|
||||
class SleekTest(unittest.TestCase):
|
||||
|
||||
"""
|
|
@ -1,6 +1,5 @@
|
|||
import sleekxmpp
|
||||
import time
|
||||
from . sleektest import *
|
||||
from sleekxmpp.test import *
|
||||
|
||||
|
||||
class TestEvents(SleekTest):
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from . sleektest import *
|
||||
from sleekxmpp.test import *
|
||||
from sleekxmpp.xmlstream.jid import JID
|
||||
|
||||
|
||||
class TestJIDClass(SleekTest):
|
||||
def testJIDfromfull(self):
|
||||
j = JID('user@someserver/some/resource')
|
||||
|
@ -23,4 +24,5 @@ class TestJIDClass(SleekTest):
|
|||
self.assertEqual(j.full, 'user@someserver/some/resource', "Full does not match")
|
||||
self.assertEqual(str(j), 'user@someserver/some/resource', "String does not match")
|
||||
|
||||
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(TestJIDClass)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from . sleektest import *
|
||||
import sleekxmpp
|
||||
from sleekxmpp.test import *
|
||||
from sleekxmpp.xmlstream.stanzabase import ET, StanzaBase
|
||||
|
||||
|
||||
class TestStanzaBase(SleekTest):
|
||||
|
||||
def testTo(self):
|
|
@ -1,6 +1,7 @@
|
|||
from . sleektest import *
|
||||
from sleekxmpp.test import *
|
||||
from sleekxmpp.xmlstream.stanzabase import ElementBase
|
||||
|
||||
|
||||
class TestElementBase(SleekTest):
|
||||
|
||||
def testFixNs(self):
|
|
@ -1,4 +1,5 @@
|
|||
from . sleektest import *
|
||||
from sleekxmpp.test import *
|
||||
|
||||
|
||||
class TestErrorStanzas(SleekTest):
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
from . sleektest import *
|
||||
from sleekxmpp.test import *
|
||||
import sleekxmpp.plugins.gmail_notify as gmail
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
from . sleektest import *
|
||||
from sleekxmpp.test import *
|
||||
from sleekxmpp.xmlstream.stanzabase import ET
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
from . sleektest import *
|
||||
from sleekxmpp.test import *
|
||||
from sleekxmpp.stanza.message import Message
|
||||
from sleekxmpp.stanza.htmlim import HTMLIM
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
import sleekxmpp
|
||||
from . sleektest import *
|
||||
from sleekxmpp.test import *
|
||||
from sleekxmpp.stanza.presence import Presence
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
from . sleektest import *
|
||||
from sleekxmpp.test import *
|
||||
from sleekxmpp.stanza.roster import Roster
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
from . sleektest import *
|
||||
from sleekxmpp.test import *
|
||||
import sleekxmpp.plugins.xep_0004 as xep_0004
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
from . sleektest import *
|
||||
from sleekxmpp.test import *
|
||||
import sleekxmpp.plugins.xep_0030 as xep_0030
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
from . sleektest import *
|
||||
from sleekxmpp.test import *
|
||||
import sleekxmpp.plugins.xep_0033 as xep_0033
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
from . sleektest import *
|
||||
from sleekxmpp.test import *
|
||||
import sleekxmpp.plugins.xep_0004 as xep_0004
|
||||
import sleekxmpp.plugins.stanza_pubsub as pubsub
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
from . sleektest import *
|
||||
from sleekxmpp.test import *
|
||||
import sleekxmpp.plugins.xep_0085 as xep_0085
|
||||
|
||||
class TestChatStates(SleekTest):
|
|
@ -1,4 +1,4 @@
|
|||
from . sleektest import *
|
||||
from sleekxmpp.test import *
|
||||
import sleekxmpp.plugins.xep_0033 as xep_0033
|
||||
|
||||
|
||||
|
@ -55,6 +55,6 @@ class TestStreamTester(SleekTest):
|
|||
def testSendStreamHeader(self):
|
||||
"""Test that we can check a sent stream header."""
|
||||
self.stream_start(mode='client', skip=False)
|
||||
self.streamSendHeader(sto='localhost')
|
||||
self.stream_send_header(sto='localhost')
|
||||
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamTester)
|
|
@ -1,8 +1,8 @@
|
|||
from . sleektest import *
|
||||
import sleekxmpp
|
||||
from sleekxmpp.test import *
|
||||
from sleekxmpp.xmlstream.handler import *
|
||||
from sleekxmpp.xmlstream.matcher import *
|
||||
|
||||
|
||||
class TestHandlers(SleekTest):
|
||||
"""
|
||||
Test using handlers and waiters.
|
|
@ -1,4 +1,4 @@
|
|||
from . sleektest import *
|
||||
from sleekxmpp.test import *
|
||||
from sleekxmpp.stanza import Message
|
||||
from sleekxmpp.xmlstream.stanzabase import ET
|
||||
from sleekxmpp.xmlstream.tostring import tostring, xml_escape
|
||||
|
|
Loading…
Reference in a new issue