Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
test.test_socket.ThreadableTest Class Reference
Inheritance diagram for test.test_socket.ThreadableTest:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def __init__
def serverExplicitReady
def clientRun
def clientSetUp
def clientTearDown

Public Attributes

 setUp
 tearDown
 server_ready
 client_ready
 done
 queue
 client_thread

Private Member Functions

def _setUp
def _tearDown

Private Attributes

 __setUp
 __tearDown

Detailed Description

Threadable Test class

The ThreadableTest class makes it easy to create a threaded
client/server pair from an existing unit test. To create a
new threaded class from an existing unit test, use multiple
inheritance:

    class NewClass (OldClass, ThreadableTest):
        pass

This class defines two new fixture functions with obvious
purposes for overriding:

    clientSetUp ()
    clientTearDown ()

Any new test functions within the class must then define
tests in pairs, where the test name is preceeded with a
'_' to indicate the client portion of the test. Ex:

    def testFoo(self):
        # Server portion

    def _testFoo(self):
        # Client portion

Any exceptions raised by the clients during their tests
are caught and transferred to the main thread to alert
the testing framework.

Note, the server setup function cannot call any blocking
functions that rely on the client thread during setup,
unless serverExplicitReady() is called just before
the blocking call (such as in setting up a client/server
connection and performing the accept() in setUp().

Definition at line 78 of file test_socket.py.


Constructor & Destructor Documentation

Definition at line 116 of file test_socket.py.

00116 
00117     def __init__(self):
00118         # Swap the true setup function
00119         self.__setUp = self.setUp
00120         self.__tearDown = self.tearDown
00121         self.setUp = self._setUp
00122         self.tearDown = self._tearDown

Here is the caller graph for this function:


Member Function Documentation

def test.test_socket.ThreadableTest._setUp (   self) [private]

Definition at line 130 of file test_socket.py.

00130 
00131     def _setUp(self):
00132         self.server_ready = threading.Event()
00133         self.client_ready = threading.Event()
00134         self.done = threading.Event()
00135         self.queue = queue.Queue(1)
00136 
00137         # Do some munging to start the client test.
00138         methodname = self.id()
00139         i = methodname.rfind('.')
00140         methodname = methodname[i+1:]
00141         test_method = getattr(self, '_' + methodname)
00142         self.client_thread = thread.start_new_thread(
00143             self.clientRun, (test_method,))
00144 
00145         self.__setUp()
00146         if not self.server_ready.is_set():
00147             self.server_ready.set()
00148         self.client_ready.wait()

Definition at line 149 of file test_socket.py.

00149 
00150     def _tearDown(self):
00151         self.__tearDown()
00152         self.done.wait()
00153 
00154         if self.queue.qsize():
00155             exc = self.queue.get()
00156             raise exc

def test.test_socket.ThreadableTest.clientRun (   self,
  test_func 
)

Definition at line 157 of file test_socket.py.

00157 
00158     def clientRun(self, test_func):
00159         self.server_ready.wait()
00160         self.client_ready.set()
00161         self.clientSetUp()
00162         if not hasattr(test_func, '__call__'):
00163             raise TypeError("test_func must be a callable function")
00164         try:
00165             test_func()
00166         except BaseException as e:
00167             self.queue.put(e)
00168         finally:
00169             self.clientTearDown()

Here is the call graph for this function:

This method allows the server to explicitly indicate that
it wants the client thread to proceed. This is useful if the
server is about to execute a blocking routine that is
dependent upon the client thread during its setup routine.

Definition at line 123 of file test_socket.py.

00123 
00124     def serverExplicitReady(self):
00125         """This method allows the server to explicitly indicate that
00126         it wants the client thread to proceed. This is useful if the
00127         server is about to execute a blocking routine that is
00128         dependent upon the client thread during its setup routine."""
00129         self.server_ready.set()

Here is the caller graph for this function:


Member Data Documentation

Definition at line 118 of file test_socket.py.

Definition at line 119 of file test_socket.py.

Definition at line 132 of file test_socket.py.

Definition at line 141 of file test_socket.py.

Definition at line 133 of file test_socket.py.

Definition at line 134 of file test_socket.py.

Definition at line 131 of file test_socket.py.

Definition at line 120 of file test_socket.py.

Definition at line 121 of file test_socket.py.


The documentation for this class was generated from the following file: