/usr/local/lib/python3.6/site-packages/asynctest/__pycache__
NameSizeModeActions
case.cpython-36.pyc149730644editdlrm
helpers.cpython-36.pyc7310644editdlrm
mock.cpython-36.pyc398800644editdlrm
selector.cpython-36.pyc112240644editdlrm
_fail_on.cpython-36.pyc45500644editdlrm
__init__.cpython-36.pyc9070644editdlrm
Edit: /usr/local/lib/python3.6/site-packages/asynctest/__pycache__/case.cpython-36.pyc (14973B)
3 8%EgD@sdZddlZddlZddlZddlZddlZddlZddlTddlZ ddl Z Gdddej Z Gdddej Z Gdd d e ejZGd d d e 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@sLeZdZddZddZddZddZd d Zd d Zd dZ ddZ dS)_PolicycCs||_||_||_d|_dS)N)original_policyforbid_get_event_looploopwatcher)selfrrrr 8/usr/local/lib/python3.6/site-packages/asynctest/case.py__init__;sz_Policy.__init__cCs*|jrtdn|jr|jS|jjSdS)NzSTestCase.forbid_get_event_loop is True, asyncio.get_event_loop() must not be called)rAssertionErrorrrget_event_loop)rr r r r Es  z_Policy.get_event_loopcCs |jjS)N)rnew_event_loop)rr r r rNsz_Policy.new_event_loopcCs|jj|}||_|S)N)rset_event_loopr)rrresultr r r rQs z_Policy.set_event_loopcCsttdstdS)NSafeChildWatcher)hasattrasyncioNotImplementedError)rr r r _check_unixVs z_Policy._check_unixcCsD|j|jr6|jdkr0tj|_|jj|j|jS|jjSdS)N)rrrrr attach_looprget_child_watcher)rr r r rZs  z_Policy.get_child_watchercCs4|j|jr$|jj|}||_|S|jj|SdS)N)rrrset_child_watcherr)rrrr r r res  z_Policy.set_child_watchercCs |jr|jj|jjddS)N)rcloserr)rr r r reset_watcherns z_Policy.reset_watcherN) __name__ __module__ __qualname__r r rrrrrrr r r r r:s    rcseZdZdZdZdZdZddZddZdd Z d d Z d d Z d ddZ ddZ ddZejddZfddZejddZejddZejddZejddZZS)!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|jrtj|_d}ntj}|_ttj||j}tj||j |j|_dS)N) use_default_looprr rrrget_event_loop_policyrset_event_loop_policy _patch_loop)rrpolicyr r r _init_loops   zTestCase._init_loopcCsRtj}|js.wraps..wrapper) functoolswrapstypes MethodType)r/r0)r)r/r r2sz#TestCase._patch_loop..wraps run_foreverr))r5r)) rr,setattrgetattr isinstancerselector_eventsBaseSelectorEventLoop asynctestselectorZ TestSelector _selector)rrr2r/r )rr r"s  zTestCase._patch_loopcCsr|jt||j}t|tjjd}|p0tjj|_|jj|tj |j r^|j j |j n|j d|j _ dS)NF)r$r7_testMethodNamer;_fail_onZ _FAIL_ON_ATTR_checkerZ before_testriscoroutinefunctionZsetUprr)r,)rtestcheckerr r r _setUps   zTestCase._setUpcCs6tj|jr|jj|jn|j|jj|dS)N)rrAZtearDownrr)r@Z check_test)rr r r _tearDowns zTestCase._tearDownc (Cs|}|dkr.|j}t|dd}|dk r.||j|t||j}t|jdds^t|ddrz,t|jddpxt|dd}|j|||Wd|j|XdSt|dd}tjj |}z||_ |j ||j WdQRX|j r2||_|j |dd|j|WdQRXd|_|j ||jWdQRX|jj|j|jx"|jD]\}} |j||| qRW|j||j|j r|r|jr|j||jn |j|n |j||S|j||dkrt|d d} | dk r| |jjd|_d|_ XdS) N startTestRunZ__unittest_skip__FZ__unittest_skip_why__Z__unittest_expecting_failure__T)ZisTest stopTestRun)ZdefaultTestResultr7Z startTestr> __class__Z_addSkipZstopTestunittestZcase_Outcome_outcometestPartExecutorrDsuccessexpecting_failure_run_test_methodrErr) doCleanupsr+skippedZ_feedErrorsToResulterrorsZexpectedFailureZ_addExpectedFailureZ_addUnexpectedSuccessZ addSuccessclear) rrZ orig_resultrFZ testMethodZskip_whyrOoutcomerBreasonrHr r r run sd                z TestCase.runcCs|jzyd|jt||j|jxD|jrj|jjd\}}}tj|r^|j j |||q(|||q(WWnt k rYnXWd|j XdS)N) rDrPr7r>rE _cleanupspoprrArr) Exceptionr+)rfunctionr-r.r r r debugLs  zTestCase.debugcCs |}tj|r|jj|dS)N)r iscoroutinerr))rr/rr r r rP]s zTestCase._run_test_methodc csn|jptjj}xV|jrf|jj\}}}|j|,tj|rP|||EdHn |||WdQRXqW|j S)zX Execute all cleanup functions. Normally called for you after tearDown. N) rLrJZmockrKrZr[rMrrArN)rrUr]r-r.r r r rQds  zTestCase.doCleanupscstj|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 ratszTestCase.addCleanupc cs |j| |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"|j|| |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)rrcregexrdr r r assertAsyncRaisesRegexszTestCase.assertAsyncRaisesRegexc cs |j| |EdHSQRXdS)z Test that a warning is triggered when awaiting ``awaitable``, a future or a coroutine. :see: :meth:`unittest.TestCase.assertWarns()` N)Z assertWarns)rwarningrdr r r assertAsyncWarnss zTestCase.assertAsyncWarnsc cs"|j|| |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)rrirgrdr r r assertAsyncWarnsRegexszTestCase.assertAsyncWarnsRegex)N)rrr__doc__rrrr$r+r"rDrErWr^rPr coroutinerQrarerhrjrk __classcell__r r )rIr rws$6  C    rc@seZdZdZdS)FunctionTestCasezv Enables the same features as :class:`~asynctest.TestCase`, but for :class:`~asynctest.FunctionTestCase`. N)rrrrlr r r r rosrocsDeZdZdZfddZejddZddZejdd 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. cs2tjtjjjfddj_d_dS)NcsjS)N)_timer )rr r sz,ClockedTestCase._init_loop..r)r`r$r1r2rtimerq)r)rI)rr r$s zClockedTestCase._init_loopccsz|dkrtdj||jEdH|j|}x2|j}|dksH||krJP||_|jEdHq0W||_|jEdHdS)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) ValueErrorformat _drain_looprq_next_scheduled)rsecondsZ target_time next_timer r r advances  zClockedTestCase.advancec Cs(y|jjdjStk r"dSXdS)Nr)r _scheduled_when IndexError)rr r r rwszClockedTestCase._next_scheduledccsHxB|j}|jj r(|dks&||jkr(PtjdEdHd|j_qWdS)NrT)rwr_readyrqrsleepZ_TestCase_asynctest_ran)rryr r r rvs zClockedTestCase._drain_loop) rrrrlr$rrmrzrwrvrnr r )rIr rps  $rpcCs0tjdttjjddi}|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)Z unused_loopFN)warningswarnDeprecationWarningr;r?)funcrCr r r ignore_loopsr)N)rlrr1r3rJr'rZ unittest.caseZasynctest.selectorr;Zasynctest._fail_onAbstractEventLoopPolicyrrrorprr r r r +s =4B