%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib64/python2.7/site-packages/tornado/
Upload File :
Create Path :
Current File : //lib64/python2.7/site-packages/tornado/testing.pyc

�
��L]c@�s�dZddlmZmZmZmZyzddlmZddlm	Z	ddl
mZddlm
Z
ddlmZmZddlmZdd	lmZWn;ek
r�d
Z	d
Zd
Zd
Zd
Zd
Z
d
ZnXdd
lmZmZddlmZddlmZmZdd
lZdd
lZdd
l Z dd
l!Z!dd
l"Z"dd
l#Z#dd
l$Z$dd
l%Z%yddl&m'Z'Wn!ek
r�ddl(m'Z'nXe$j)d#kr�dd
l*Z*n0ydd
l+Z*Wnek
rdd
l*Z*nXda,d�Z-d�Z.d�Z/de0fd��YZ1de*j2fd��YZ3de3fd��YZ4de4fd��YZ5d
d
d�Z6e7e6_8de*j2fd��YZ9dej:fd ��YZ;d!�Z<e=d"kr�e<�nd
S($s�Support classes for automated testing.

* `AsyncTestCase` and `AsyncHTTPTestCase`:  Subclasses of unittest.TestCase
  with additional support for testing asynchronous (`.IOLoop` based) code.

* `ExpectLog` and `LogTrapTestCase`: Make test logs less spammy.

* `main()`: A simple test runner (wrapper around unittest.main()) with support
  for the tornado.autoreload module to rerun the tests when code changes.
i(tabsolute_importtdivisiontprint_functiontwith_statement(tgen(tAsyncHTTPClient(t
HTTPServer(tSimpleAsyncHTTPClient(tIOLooptTimeoutError(tnetutil(t
Subprocess(tgen_logtapp_log(tExceptionStackContext(traise_exc_infotbasestring_typeN(tStringIOii'cC�st}tda|S(s@Returns a (hopefully) unused port number.

    This function does not guarantee that the port it returns is available,
    only that a series of get_unused_port calls in a single process return
    distinct ports.

    .. deprecated::
       Use bind_unused_port instead, which is guaranteed to find an unused port.
    i(t
_next_port(tport((s5/usr/lib64/python2.7/site-packages/tornado/testing.pytget_unused_portCs
cC�s8tjdddtj�\}|j�d}||fS(sbBinds a server socket to an available port on localhost.

    Returns a tuple (socket, port).
    t	localhosttfamilyiN(R
tbind_socketstNonetsockettAF_INETtgetsockname(tsockR((s5/usr/lib64/python2.7/site-packages/tornado/testing.pytbind_unused_portSscC�s9yttjjd��SWnttfk
r4dSXdS(s}Get the global timeout setting for async tests.

    Returns a float, the timeout in seconds.

    .. versionadded:: 3.1
    tASYNC_TEST_TIMEOUTiN(tfloattostenvirontgett
ValueErrort	TypeError(((s5/usr/lib64/python2.7/site-packages/tornado/testing.pytget_async_test_timeout]st_TestMethodWrappercB�s)eZdZd�Zd�Zd�ZRS(s}Wraps a test method to raise an error if it returns a value.

    This is mainly used to detect undecorated generators (if a test
    method yields it must use a decorator to consume the generator),
    but will also detect other kinds of return values (these are not
    necessarily errors, but we alert anyway since there is no good
    reason to return a value from a test.
    cC�s
||_dS(N(torig_method(tselfR'((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyt__init__sscO�sV|j||�}t|tj�r3td��n|dk	rRtd|��ndS(NsHGenerator test methods should be decorated with tornado.testing.gen_tests)Return value from test method ignored: %r(R't
isinstancettypest
GeneratorTypeR$RR#(R(targstkwargstresult((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyt__call__vscC�st|j|�S(s�Proxy all unknown attributes to the original method.

        This is important for some of the decorators in the `unittest`
        module, such as `unittest.skipIf`.
        (tgetattrR'(R(tname((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyt__getattr__s(t__name__t
__module__t__doc__R)R0R3(((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyR&js			t
AsyncTestCasecB�sneZdZdd�Zd�Zd�Zd�Zd�Zd�Zdd�Z
dd	�Zddd
�ZRS(sk`~unittest.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 means that
    asynchronous code cannot be used in quite the same way as usual.
    To write test functions that use the same ``yield``-based patterns
    used with the `tornado.gen` module, decorate your test methods
    with `tornado.testing.gen_test` instead of
    `tornado.gen.coroutine`.  This class also provides the `stop()`
    and `wait()` methods for a more manual style of testing.  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 <stop>` and `self.wait
    <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 coroutine style.
        class MyTestCase(AsyncTestCase):
            @tornado.testing.gen_test
            def test_http_fetch(self):
                client = AsyncHTTPClient(self.io_loop)
                response = yield client.fetch("http://www.tornadoweb.org")
                # Test contents of response
                self.assertIn("FriendFeed", response.body)

        # This test uses argument passing between self.stop and self.wait.
        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)

        # This test uses an explicit callback-based style.
        class MyTestCase3(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()
    trunTestcK�sitt|�j||�t|_t|_d|_d|_d|_	t
||tt||���dS(N(
tsuperR7R)tFalset_AsyncTestCase__stoppedt_AsyncTestCase__runningRt_AsyncTestCase__failuret_AsyncTestCase__stop_argst_AsyncTestCase__timeouttsetattrR&R1(R(t
methodNameR.((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyR)�s					cC�s3tt|�j�|j�|_|jj�dS(N(R9R7tsetUptget_new_iolooptio_looptmake_current(R(((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyRB�scC�sptj�|jj�tj�s9|jtj�k	rO|jjdt�nt	t
|�j�|j�dS(Ntall_fds(
RtuninitializeRDt
clear_currentRtinitializedtinstancetclosetTrueR9R7ttearDownt_AsyncTestCase__rethrow(R(((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyRM�s


cC�st�S(s�Creates a new `.IOLoop` for this test.  May be overridden in
        subclasses for tests that require a specific `.IOLoop` (usually
        the singleton `.IOLoop.instance()`).
        (R(R(((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyRC�scC�sN|jdkr$|||f|_ntjdd|||f�|j�tS(Ns%multiple unhandled exceptions in testtexc_info(R=RR
terrortstopRL(R(ttyptvaluettb((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyt_handle_exception�s
cC�s2|jdk	r.|j}d|_t|�ndS(N(R=RR(R(tfailure((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyt	__rethrow�s		cC�s:t|j��tt|�j|�WdQX|j�dS(N(RRUR9R7trunRN(R(R/((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyRXscK�sW|dks|st�|p"||_|jrJ|jj�t|_nt|_dS(s�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()`.
        N(	RtAssertionErrorR>R<RDRQR:RLR;(R(t_argR.((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyRQ
s	
c�s�dkrt��n�js��ra��fd�}�jj�jj��|��_nxHtr�t�_�jj	��j
dk	s�|dks�|�rdPqdqdW�jdk	r��jj�j�d�_q�n�js�t�t
�_�j��j}d�_|S(s"Runs the `.IOLoop` until stop is called or timeout has passed.

        In the event of a timeout, an exception will be thrown. The
        default timeout is 5 seconds; it may be overridden with a
        ``timeout`` keyword argument or globally with the
        ``ASYNC_TEST_TIMEOUT`` environment variable.

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

        .. versionchanged:: 3.1
           Added the ``ASYNC_TEST_TIMEOUT`` environment variable.
        c�sHy�jd���Wn tk
r9tj��_nX�j�dS(Ns*Async operation timed out after %s seconds(tfailureExceptiont	ExceptiontsysROR=RQ((R(ttimeout(s5/usr/lib64/python2.7/site-packages/tornado/testing.pyttimeout_func+s
N(RR%R;RDtadd_timeoutttimeR?RLR<tstartR=tremove_timeoutRYR:RNR>(R(t	conditionR^R_R/((R(R^s5/usr/lib64/python2.7/site-packages/tornado/testing.pytwaits*	(		
	
		N(
R4R5R6R)RBRMRCRURNRRXRQRe(((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyR7�s=							tAsyncHTTPTestCasecB�sheZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�ZRS(sSA test case that starts up an HTTP server.

    Subclasses must override `get_app()`, which returns the
    `tornado.web.Application` (or other `.HTTPServer` callback) to be tested.
    Tests will typically use the provided ``self.http_client`` to fetch
    URLs from this server.

    Example::

        class MyHTTPTest(AsyncHTTPTestCase):
            def get_app(self):
                return Application([('/', MyHandler)...])

            def test_homepage(self):
                # The following two lines are equivalent to
                #   response = self.fetch('/')
                # but are shown in full here to demonstrate explicit use
                # of self.stop and self.wait.
                self.http_client.fetch(self.get_url('/'), self.stop)
                response = self.wait()
                # test contents of response
    cC�sott|�j�t�\}}||_|j�|_|j�|_|j	�|_
|j
j|g�dS(N(R9RfRBRt_AsyncHTTPTestCase__porttget_http_clientthttp_clienttget_appt_apptget_http_serverthttp_servertadd_sockets(R(RR((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyRB\s	cC�std|j�S(NRD(RRD(R(((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyRhfscC�st|jd|j|j��S(NRD(RRkRDtget_httpserver_options(R(((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyRliscC�s
t��dS(szShould be overridden by subclasses to return a
        `tornado.web.Application` or other `.HTTPServer` callback.
        N(tNotImplementedError(R(((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyRjmscK�s,|jj|j|�|j|�|j�S(s1Convenience method to synchronously fetch a url.

        The given path will be appended to the local server's host and
        port.  Any additional kwargs will be passed directly to
        `.AsyncHTTPClient.fetch` (and so could be used to pass
        ``method="POST"``, ``body="..."``, etc).
        (Ritfetchtget_urlRQRe(R(tpathR.((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyRqss"cC�siS(sgMay be overridden by subclasses to return additional
        keyword arguments for the server.
        ((R(((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyRo~scC�s|jS(sZReturns the port used by the server.

        A new port is chosen for each test.
        (Rg(R(((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyt
get_http_port�scC�sdS(Nthttp((R(((s5/usr/lib64/python2.7/site-packages/tornado/testing.pytget_protocol�scC�sd|j�|j�|fS(s>Returns an absolute url for the given path on the test server.s%s://localhost:%s%s(RvRt(R(Rs((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyRr�scC�sx|jj�|jj|jjdt��tj�sQ|jjtj	�k	ra|jj
�ntt|�j
�dS(NR^(RmRQRDtrun_synctclose_all_connectionsR%RRIRiRJRKR9RfRM(R(((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyRM�s


(
R4R5R6RBRhRlRjRqRoRtRvRrRM(((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyRfEs	
								tAsyncHTTPSTestCasecB�s2eZdZd�Zd�Zd�Zd�ZRS(sjA test case that starts an HTTPS server.

    Interface is generally the same as `AsyncHTTPTestCase`.
    c	C�s%td|jdtdtdt��S(NRDtforce_instancetdefaultst
validate_cert(RRDRLtdictR:(R(((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyRh�scC�std|j��S(Ntssl_options(R}tget_ssl_options(R(((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyRo�scC�sItjjt�}tdtjj|dd�dtjj|dd��S(sMay be overridden by subclasses to select SSL options.

        By default includes a self-signed testing certificate.
        tcertfiletteststest.crttkeyfilestest.key(R Rstdirnamet__file__R}tjoin(R(t
module_dir((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyR�scC�sdS(Nthttps((R(((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyRv�s(R4R5R6RhRoRRv(((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyRy�s
			c�sE�dkrt��n�fd�}|dk	r=||�S|SdS(s>Testing equivalent of ``@gen.coroutine``, to be applied to test methods.

    ``@gen.coroutine`` cannot be used on tests because the `.IOLoop` is not
    already running.  ``@gen_test`` should be applied to test methods
    on subclasses of `AsyncTestCase`.

    Example::

        class MyTest(AsyncHTTPTestCase):
            @gen_test
            def test_something(self):
                response = yield gen.Task(self.fetch('/'))

    By default, ``@gen_test`` times out after 5 seconds. The timeout may be
    overridden globally with the ``ASYNC_TEST_TIMEOUT`` environment variable,
    or for each test with the ``timeout`` keyword argument::

        class MyTest(AsyncHTTPTestCase):
            @gen_test(timeout=10)
            def test_something_slow(self):
                response = yield gen.Task(self.fetch('/'))

    .. versionadded:: 3.1
       The ``timeout`` argument and ``ASYNC_TEST_TIMEOUT`` environment
       variable.

    .. versionchanged:: 4.0
       The wrapper now passes along ``*args, **kwargs`` so it can be used
       on functions with arguments.
    c�sRtj���fd��}tj|��tj����fd��}|S(Nc�s=�|||�}t|tj�r0||_n	d|_|S(N(R*R+R,t_test_generatorR(R(R-R.R/(tf(s5/usr/lib64/python2.7/site-packages/tornado/testing.pyt
pre_coroutine�s
	c�sYy,|jjtj�|||�d��SWn&tk
rT}|jj|��nXdS(NR^(RDRwt	functoolstpartialR	R�tthrow(R(R-R.te(tcoroR^(s5/usr/lib64/python2.7/site-packages/tornado/testing.pytpost_coroutine�s	(R�twrapsRt	coroutine(R�R�R�(R^(R�R�s5/usr/lib64/python2.7/site-packages/tornado/testing.pytwrap�s		!N(RR%(tfuncR^R�((R^s5/usr/lib64/python2.7/site-packages/tornado/testing.pytgen_test�s%
tLogTrapTestCasecB�seZdZdd�ZRS(sQA test case that captures and discards all logging output
    if the test passes.

    Some libraries can produce a lot of logging output even when
    the test succeeds, so this class can be useful to minimize the noise.
    Simply use it as a base class for your test case.  It is safe to combine
    with AsyncTestCase via multiple inheritance
    (``class MyTestCase(AsyncHTTPTestCase, LogTrapTestCase):``)

    This class assumes that only one log handler is configured and
    that it is a `~logging.StreamHandler`.  This is true for both
    `logging.basicConfig` and the "pretty logging" configured by
    `tornado.options`.  It is not compatible with other log buffering
    mechanisms, such as those provided by some test runners.

    .. deprecated:: 4.1
       Use the unittest module's ``--buffer`` option instead, or `.ExpectLog`.
    cC�s%tj�}|js"tj�n|jd}t|j�dksWt|tj�rqtt|�j	|�dS|j
}z�t�|_
tj
dt|��t|j�t|j�}tt|�j	|�t|j�t|j�}||kr|j|j
j��nWd||_
XdS(NiisRUNNING TEST: (tloggingt	getLoggerthandlerstbasicConfigtlenR*t
StreamHandlerR9R�RXtstreamRRtinfotstrtfailuresterrorstwritetgetvalue(R(R/tloggerthandlert
old_streamtold_error_counttnew_error_count((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyRX#s$	

	N(R4R5R6RRX(((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyR�st	ExpectLogcB�s5eZdZed�Zd�Zd�Zd�ZRS(sPContext manager to capture and suppress expected log output.

    Useful to make tests of error conditions less noisy, while still
    leaving unexpected log entries visible.  *Not thread safe.*

    Usage::

        with ExpectLog('tornado.application', "Uncaught exception"):
            error_response = self.fetch("/some_page")
    cC�sRt|t�r!tj|�}n||_tj|�|_||_t	|_
dS(s�Constructs an ExpectLog context manager.

        :param logger: Logger object (or name of logger) to watch.  Pass
            an empty string to watch the root logger.
        :param regex: Regular expression to match.  Any log entries on
            the specified logger that match this regex will be suppressed.
        :param required: If true, an exeption will be raised if the end of
            the ``with`` statement is reached without matching any log entries.
        N(R*RR�R�R�tretcompiletregextrequiredR:tmatched(R(R�R�R�((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyR)Fs
		cC�s/|j�}|jj|�r+t|_tStS(N(t
getMessageR�tmatchRLR�R:(R(trecordtmessage((s5/usr/lib64/python2.7/site-packages/tornado/testing.pytfilterWs
	cC�s|jj|�dS(N(R�t	addFilter(R(((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyt	__enter__^scC�s=|jj|�|r9|jr9|jr9td��ndS(Ns did not get expected log message(R�tremoveFilterR�R�R\(R(RRRSRT((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyt__exit__as(R4R5R6RLR)R�R�R�(((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyR�;s

		cK�s(ddlm}m}m}|ddtdtdd�|ddt�|d	dt�|d
dt�|ddt�|ddt�tjdg|tj�}|js�t	j	t	j
t	j�n|jdk	r�d
|d<n|jdk	r�d|d<n|jdk	rt|d
<n|jdk	r7t|d<n|jdk	rSt|d<ntdkr�t|�dkr�tddtj�tjd�nyKt|�dkr�tjddd||�ntjddd||�WnBtk
r#}|jdkrtjd�n
tjd��nXdS(s�A simple test runner.

    This test runner is essentially equivalent to `unittest.main` from
    the standard library, but adds support for tornado-style option
    parsing and log formatting.

    The easiest way to run a test is via the command line::

        python -m tornado.testing tornado.test.stack_context_test

    See the standard library unittest module for ways in which tests can
    be specified.

    Projects with many tests may wish to define a test script like
    ``tornado/test/runtests.py``.  This script should define a method
    ``all()`` which returns a test suite and then call
    `tornado.testing.main()`.  Note that even when a test script is
    used, the ``all()`` test suite may be overridden by naming a
    single test on the command line::

        # Runs all tests
        python -m tornado.test.runtests
        # Runs one test
        python -m tornado.test.runtests tornado.test.stack_context_test

    Additional keyword arguments passed through to ``unittest.main()``.
    For example, use ``tornado.testing.main(verbosity=2)``
    to show many test details as they are run.
    See http://docs.python.org/library/unittest.html#unittest.main
    for full argument list.
    i(tdefinetoptionstparse_command_linetexception_on_interruptttypetdefaultthelps�If true (default), ctrl-c raises a KeyboardInterrupt exception.  This prints a stack trace but cannot interrupt certain operations.  If false, the process is more reliably killed, but does not print a stack trace.tverbosetquiettfailfasttcatchtbufferit	verbosityt
catchbreakt__main__isNo tests specifiedtfiletmoduletargvtdefaultTesttalltPASStFAILN(ttornado.optionsR�R�R�tboolRLR]R�R�tsignaltSIGINTtSIG_DFLR�RR�R�R�R�R4R�tprinttstderrtexittunittesttmaint
SystemExittcodeRR�RP(R.R�R�R�R�R�((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyR�gsB 	





R�(i(>R6t
__future__RRRRttornadoRttornado.httpclientRttornado.httpserverRttornado.simple_httpclientRttornado.ioloopRR	R
ttornado.processRtImportErrorRttornado.logRR
ttornado.stack_contextRttornado.utilRRR�R�R R�R�RR]R+t	cStringIORtiotversion_infoR�t	unittest2RRRR%tobjectR&tTestCaseR7RfRyR�R:t__test__R�tFilterR�R�R4(((s5/usr/lib64/python2.7/site-packages/tornado/testing.pyt<module>
sj"



		
	
�XT	+,	T

Zerion Mini Shell 1.0