Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
tornado.testing.AsyncTestCase Class Reference
Inheritance diagram for tornado.testing.AsyncTestCase:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def __init__
def get_new_ioloop
def run
def setUp
def stop
def tearDown
def wait

Public Attributes

 io_loop

Private Member Functions

def __rethrow
def _stack_context

Private Attributes

 __failure
 __running
 __stop_args
 __stopped
 __timeout

Detailed Description

TestCase subclass for testing IOLoop-based asynchronous code.

The unittest framework is synchronous, so the test must be complete
by the time the test method returns.  This method provides the stop()
and wait() methods for this purpose.  The test method itself must call
self.wait(), and asynchronous callbacks should call self.stop() to signal
completion.

By default, a new IOLoop is constructed for each test and is available
as self.io_loop.  This IOLoop should be used in the construction of
HTTP clients/servers, etc.  If the code being tested requires a
global IOLoop, subclasses should override get_new_ioloop to return it.

The IOLoop's start and stop methods should not be called directly.
Instead, use self.stop self.wait.  Arguments passed to self.stop are
returned from self.wait.  It is possible to have multiple
wait/stop cycles in the same test.

Example::

    # This test uses an asynchronous style similar to most async
    # application code.
    class MyTestCase(AsyncTestCase):
        def test_http_fetch(self):
            client = AsyncHTTPClient(self.io_loop)
            client.fetch("http://www.tornadoweb.org/", self.handle_fetch)
            self.wait()

        def handle_fetch(self, response):
            # Test contents of response (failures and exceptions here
            # will cause self.wait() to throw an exception and end the
            # test).
            # Exceptions thrown here are magically propagated to
            # self.wait() in test_http_fetch() via stack_context.
            self.assertIn("FriendFeed", response.body)
            self.stop()

    # This test uses the argument passing between self.stop and self.wait
    # for a simpler, more synchronous style.
    # This style is recommended over the preceding example because it
    # keeps the assertions in the test method itself, and is therefore
    # less sensitive to the subtleties of stack_context.
    class MyTestCase2(AsyncTestCase):
        def test_http_fetch(self):
            client = AsyncHTTPClient(self.io_loop)
            client.fetch("http://www.tornadoweb.org/", self.stop)
            response = self.wait()
            # Test contents of response
            self.assertIn("FriendFeed", response.body)

Definition at line 54 of file testing.py.


Constructor & Destructor Documentation

def tornado.testing.AsyncTestCase.__init__ (   self,
  args,
  kwargs 
)

Definition at line 105 of file testing.py.


Member Function Documentation

def tornado.testing.AsyncTestCase.__rethrow (   self) [private]

Definition at line 142 of file testing.py.

Definition at line 135 of file testing.py.

Creates a new IOLoop for this test.  May be overridden in
subclasses for tests that require a specific IOLoop (usually
the singleton).

Definition at line 127 of file testing.py.

def tornado.testing.AsyncTestCase.run (   self,
  result = None 
)

Definition at line 148 of file testing.py.

def tornado.testing.AsyncTestCase.stop (   self,
  _arg = None,
  kwargs 
)
Stops the ioloop, causing one pending (or future) call to wait()
to return.

Keyword arguments or a single positional argument passed to stop() are
saved and will be returned by wait().

Definition at line 155 of file testing.py.

Reimplemented in tornado.testing.AsyncHTTPTestCase.

Definition at line 117 of file testing.py.

def tornado.testing.AsyncTestCase.wait (   self,
  condition = None,
  timeout = 5 
)
Runs the IOLoop until stop is called or timeout has passed.

In the event of a timeout, an exception will be thrown.

If condition is not None, the IOLoop will be restarted after stop()
until condition() returns true.

Definition at line 169 of file testing.py.


Member Data Documentation

Definition at line 105 of file testing.py.

Definition at line 105 of file testing.py.

Definition at line 105 of file testing.py.

Definition at line 105 of file testing.py.

Definition at line 105 of file testing.py.

Definition at line 113 of file testing.py.


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


rosbridge_server
Author(s): Jonathan Mace
autogenerated on Mon Oct 6 2014 06:58:15