HEX
Server: LiteSpeed
System: Linux us-phx-web1284.main-hosting.eu 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: u300739242 (300739242)
PHP: 8.2.30
Disabled: system, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
Upload Files
File: //opt/alt/python37/lib/python3.7/site-packages/asynctest/__pycache__/case.cpython-37.pyc
B

�P�e�D�@s�dZddlZddlZddlZddlZddlZddlZddlTddlZ	ddl
Z	Gdd�dej�ZGdd�dej
�Z
Gdd	�d	e
ej�ZGd
d�de
�Zddd
�ZdS)a�
Module ``case``
---------------

Enhance :class:`unittest.TestCase`:

* a new loop is issued and set as the default loop before each test, and
  closed and disposed after,

* if the loop uses a selector, it will be wrapped with
  :class:`asynctest.TestSelector`,

* a test method in a TestCase identified as a coroutine function or returning
  a coroutine will run on the loop,

* :meth:`~TestCase.setUp()` and :meth:`~TestCase.tearDown()` methods can be
  coroutine functions,

* cleanup functions registered with :meth:`~TestCase.addCleanup()` can be
  coroutine functions,

* a test fails if the loop did not run during the test.

class-level set-up
~~~~~~~~~~~~~~~~~~

Since each test runs in its own loop, it is not possible to run
:meth:`~TestCase.setUpClass()` and :meth:`~TestCase.tearDownClass()` as
coroutines.

If one needs to perform set-up actions at the class level (meaning
once for all tests in the class), it should be done using a loop created for
this sole purpose and that is not shared with the tests. Ideally, the loop
shall be closed in the method which creates it.

If one really needs to share a loop between tests,
:attr:`TestCase.use_default_loop` can be set to ``True`` (as a class
attribute). The test case will use the loop returned by
:meth:`asyncio.get_event_loop()` instead of creating a new loop for each test.
This way, the event loop or event loop policy can be set during class-level
set-up and tear down.
�N)�*c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�_PolicycCs||_||_||_d|_dS)N)�original_policy�forbid_get_event_loop�loop�watcher)�selfrrr�r	�?/opt/alt/python37/lib/python3.7/site-packages/asynctest/case.py�__init__;sz_Policy.__init__cCs*|jrtd��n|jr|jS|j��SdS)NzSTestCase.forbid_get_event_loop is True, asyncio.get_event_loop() must not be called)r�AssertionErrorrr�get_event_loop)rr	r	r
r
Es

z_Policy.get_event_loopcCs
|j��S)N)r�new_event_loop)rr	r	r
rNsz_Policy.new_event_loopcCs|j�|�}||_|S)N)r�set_event_loopr)rr�resultr	r	r
rQsz_Policy.set_event_loopcCsttd�st�dS)N�SafeChildWatcher)�hasattr�asyncio�NotImplementedError)rr	r	r
�_check_unixVs
z_Policy._check_unixcCsD|��|jr6|jdkr0t��|_|j�|j�|jS|j��SdS)N)rrrrr�attach_loopr�get_child_watcher)rr	r	r
rZs

z_Policy.get_child_watchercCs4|��|jr$|j�|�}||_|S|j�|�SdS)N)rrr�set_child_watcherr)rrrr	r	r
resz_Policy.set_child_watchercCs |jr|j��|j�d�dS)N)r�closerr)rr	r	r
�
reset_watcherns
z_Policy.reset_watcherN)�__name__�
__module__�__qualname__rr
rrrrrrr	r	r	r
r:s
		rcs�eZdZdZdZdZdZdd�Zdd�Zdd	�Z	d
d�Z
dd
�Zd dd�Zdd�Z
dd�Zejdd��Z�fdd�Zejdd��Zejdd��Zejdd��Zejdd��Z�ZS)!�TestCaseaJ
    A test which is a coroutine function or which returns a coroutine will run
    on the loop.

    Once the test returned, one or more assertions are checked. For instance,
    a test fails if the loop didn't run. These checks can be enabled or
    disabled using the :func:`~asynctest.fail_on` decorator.

    By default, a new loop is created and is set as the default loop before
    each test. Test authors can retrieve this loop with
    :attr:`~asynctest.TestCase.loop`.

    If :attr:`~asynctest.TestCase.use_default_loop` is set to ``True``, the
    current default event loop is used instead. In this case, it is up to the
    test author to deal with the state of the loop in each test: the loop might
    be closed, callbacks and tasks may be scheduled by previous tests. It is
    also up to the test author to close the loop and dispose the related
    resources.

    If :attr:`~asynctest.TestCase.forbid_get_event_loop` is set to ``True``,
    a call to :func:`asyncio.get_event_loop()` will raise an
    :exc:`AssertionError`. Since Python 3.6, calling
    :func:`asyncio.get_event_loop()` from a callback or a coroutine will return
    the running loop (instead of raising an exception).

    These behaviors should be configured when defining the test case class::

        class With_Reusable_Loop_TestCase(asynctest.TestCase):
            use_default_loop = True

            forbid_get_event_loop = False

            def test_something(self):
                pass

    If :meth:`setUp()` and :meth:`tearDown()` are coroutine functions, they
    will run on the loop. Note that :meth:`setUpClass()` and
    :meth:`tearDownClass()` can not be coroutines.

    .. versionadded:: 0.5

        attribute :attr:`~asynctest.TestCase.use_default_loop`.

    .. versionadded:: 0.7

        attribute :attr:`~asynctest.TestCase.forbid_get_event_loop`.
        In any case, the default loop is now reset to its original state
        outside a test function.

    .. versionadded:: 0.8

        ``ignore_loop`` has been deprecated in favor of the extensible
        :func:`~asynctest.fail_on` decorator.
    FNcCsR|jrt��|_d}nt��}|_tt��||j�}t�|�|�	|j�|_dS)N)
�use_default_looprr
rrr�get_event_loop_policyr�set_event_loop_policy�_patch_loop)rr�policyr	r	r
�
_init_loop�s


zTestCase._init_loopcCsRt��}|js<tjdkr*|j�|j���|j��|�	�t�
|j�d|_dS)N)��)rr r�sys�version_infor�run_until_complete�shutdown_asyncgensrrr!r)rr#r	r	r
�_unset_loop�s

zTestCase._unset_loopcsft�d�r�Sd�_�fdd�}x"dD]}t�||t�|���q&Wt�tjj�rbtj	�
�j��_�S)N�_asynctest_ranFcs$t�����fdd��}t�|��S)Ncsz
�||�Sd�_XdS)NT)r,)r�args�kwargs)r�methodr	r
�wrapper�s
z4TestCase._patch_loop.<locals>.wraps.<locals>.wrapper)�	functools�wraps�types�
MethodType)r/r0)r)r/r
r2�sz#TestCase._patch_loop.<locals>.wraps)�run_foreverr))rr,�setattr�getattr�
isinstancer�selector_events�BaseSelectorEventLoop�	asynctest�selectorZTestSelector�	_selector)rrr2r/r	)rr
r"�s


zTestCase._patch_loopcCsr|��t||j�}t|tjjd�}|p0tj��|_|j�|�t�	|j
�r^|j�|�
��n|�
�d|j_
dS)NF)r$r7�_testMethodNamer;�_fail_onZ
_FAIL_ON_ATTR�_checkerZbefore_testr�iscoroutinefunctionZsetUprr)r,)r�test�checkerr	r	r
�_setUp�szTestCase._setUpcCs6t�|j�r|j�|���n|��|j�|�dS)N)rrAZtearDownrr)r@Z
check_test)rr	r	r
�	_tearDown�szTestCase._tearDownc
Cs|}|dkr.|��}t|dd�}|dk	r.|�|�|�t||j�}t|jdd�s^t|dd�r�z,t|jdd�pxt|dd�}|�|||�Wd|�|�XdSt|dd�}tj�	|�}�z||_
|�|��|��WdQRX|j
�r2||_|j|dd��|�|�WdQRXd|_|�|��|��WdQRX|j�|���|��x"|jD]\}}	|�|||	��qRW|�||j�|j
�r�|�r�|j�r�|�||j�n
|�|�n
|�|�|S|�|�|dk�r�t|d	d�}
|
dk	�r�|
�|j��d|_d|_
XdS)
N�startTestRunZ__unittest_skip__FZ__unittest_skip_why__�Z__unittest_expecting_failure__T)ZisTest�stopTestRun)ZdefaultTestResultr7Z	startTestr>�	__class__Z_addSkipZstopTest�unittest�case�_Outcome�_outcome�testPartExecutorrD�success�expecting_failure�_run_test_methodrErr)�
doCleanupsr+ZskippedZ_feedErrorsToResult�errorsZexpectedFailureZ_addExpectedFailureZ_addUnexpectedSuccessZ
addSuccess�clear)rrZorig_resultrFZ
testMethodZskip_whyrP�outcomerB�reasonrHr	r	r
�run	sd





zTestCase.runcCs�|��z�yd|�t||j��|��xD|jrj|j�d�\}}}t�|�r^|j	�
|||��q(|||�q(WWntk
r��YnXWd|��XdS)N���)
rDrQr7r>rE�	_cleanups�poprrArr)�	Exceptionr+)r�functionr-r.r	r	r
�debugLs
zTestCase.debugcCs |�}t�|�r|j�|�dS)N)r�iscoroutinerr))rr/rr	r	r
rQ]s
zTestCase._run_test_methodc	csn|jptj��}xV|jrf|j��\}}}|�|��,t�|�rP|||�EdHn
|||�WdQRXqW|j	S)zX
        Execute all cleanup functions. Normally called for you after tearDown.
        N)
rMrJZmockrLrYrZrNrrArO)rrUr\r-r.r	r	r
rRds
zTestCase.doCleanupscst�j|f|�|�S)z�
        Add a function, with arguments, to be called when the test is
        completed. If function is a coroutine function, it will run on the loop
        before it's cleaned.
        )�super�
addCleanup)rr\r-r.)rIr	r
r`tszTestCase.addCleanupc	cs |�|��|EdHSQRXdS)z�
        Test that an exception of type ``exception`` is raised when an
        exception is raised when awaiting ``awaitable``, a future or coroutine.

        :see: :meth:`unittest.TestCase.assertRaises()`
        N)�assertRaises)r�	exception�	awaitabler	r	r
�assertAsyncRaises|szTestCase.assertAsyncRaisesc	cs"|�||��|EdHSQRXdS)z�
        Like :meth:`assertAsyncRaises()` but also tests that ``regex`` matches
        on the string representation of the raised exception.

        :see: :meth:`unittest.TestCase.assertRaisesRegex()`
        N)�assertRaisesRegex)rrb�regexrcr	r	r
�assertAsyncRaisesRegex�szTestCase.assertAsyncRaisesRegexc	cs |�|��|EdHSQRXdS)z�
        Test that a warning is triggered when awaiting ``awaitable``, a future
        or a coroutine.

        :see: :meth:`unittest.TestCase.assertWarns()`
        N)ZassertWarns)r�warningrcr	r	r
�assertAsyncWarns�szTestCase.assertAsyncWarnsc	cs"|�||��|EdHSQRXdS)z�
        Like :meth:`assertAsyncWarns()` but also tests that ``regex`` matches
        on the message of the triggered warning.

        :see: :meth:`unittest.TestCase.assertWarnsRegex()`
        N)ZassertWarnsRegex)rrhrfrcr	r	r
�assertAsyncWarnsRegex�szTestCase.assertAsyncWarnsRegex)N)rrr�__doc__rrrr$r+r"rDrErWr]rQr�	coroutinerRr`rdrgrirj�
__classcell__r	r	)rIr
rws$6

Crc@seZdZdZdS)�FunctionTestCasezv
    Enables the same features as :class:`~asynctest.TestCase`, but for
    :class:`~asynctest.FunctionTestCase`.
    N)rrrrkr	r	r	r
rn�srncsDeZdZdZ�fdd�Zejdd��Zdd�Zejdd	��Z	�Z
S)
�ClockedTestCasez�
    Subclass of :class:`~asynctest.TestCase` with a controlled loop clock,
    useful for testing timer based behaviour without slowing test run time.

    The clock will only advance when :meth:`advance()` is called.
    cs2t���t��jj��fdd���j_d�_dS)Ncs�jS)N)�_timer	)rr	r
�<lambda>��z,ClockedTestCase._init_loop.<locals>.<lambda>r)r_r$r1r2r�timerp)r)rI)rr
r$�s
zClockedTestCase._init_loopccsz|dkrtd�|���|��EdH|j|}x2|��}|dksH||krJP||_|��EdHq0W||_|��EdHdS)a
        Fast forward time by a number of ``seconds``.

        Callbacks scheduled to run up to the destination clock time will be
        executed on time:

        >>> self.loop.call_later(1, print_time)
        >>> self.loop.call_later(2, self.loop.call_later, 1, print_time)
        >>> await self.advance(3)
        1
        3

        In this example, the third callback is scheduled at ``t = 2`` to be
        executed at ``t + 1``. Hence, it will run at ``t = 3``. The callback as
        been called on time.
        rz#Cannot go back in time ({} seconds)N)�
ValueError�format�_drain_looprp�_next_scheduled)r�secondsZtarget_time�	next_timer	r	r
�advance�s
zClockedTestCase.advancecCs(y|jjdjStk
r"dSXdS)Nr)r�
_scheduled�_when�
IndexError)rr	r	r
rw�szClockedTestCase._next_scheduledccsFx@|��}|jjs&|dks$||jkr&Pt�d�EdHd|j_qWdS)NrT)rwr�_readyrpr�sleepZ_TestCase_asynctest_ran)rryr	r	r
rv�s
zClockedTestCase._drain_loop)rrrrkr$rrlrzrwrvrmr	r	)rIr
ro�s
$rocCs0t�dt�tj�ddi�}|dkr(|S||�S)zK
    Ignore the error case where the loop did not run during the test.
    zBignore_loop() is deprecated in favor of fail_on(unused_loop=False)Zunused_loopFN)�warnings�warn�DeprecationWarningr;r?)�funcrCr	r	r
�ignore_loop�sr�)N)rkrr1r3rJr'r�Z
unittest.caseZasynctest.selectorr;Zasynctest._fail_on�AbstractEventLoopPolicyrrrnror�r	r	r	r
�<module>+s =4B