j7i[^dZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm Z dd l Z dd l Z dd l Z dd lZdd lmZdd lmZdd lmZdd lZdd lmZddlmZddlmZddlmZddlmZddlmZddl m!Z!ddl m"Z"ddl#m$Z$ddl#m%Z%ddl#m&Z&ddl#m'Z'ddl(m)Z)ddl(m*Z*ddl(m+Z+ddl,m-Z-ddl,m.Z.ddl/m0Z0ddl/m1Z1e jdd d d!krdd"l3m4Z4erdd#lm5Z5dd lZdd l6Z7e8e9e:e:ejjfe8d$zZ; d6d%Z<Gd&d'e)Z=Gd(d)e*Z>ed*+d7d,Z?d8d-Z@d9d.ZAGd/d0e ZBd:d1ZCd2ZDed*3d;d4ZE dzEUnitTestCase._register_unittest_setup_class_fixture..r=ctdd}|sy|Dcgc]\}}}| }}}t|dk(r|dtd|cc}}w)NtearDown_exceptionsrzUnittest class cleanup errors)rBlenr$) exc_infos_exc exceptionsrNs r4process_teardown_exceptionszXUnitTestCase._register_unittest_setup_class_fixture..process_teardown_exceptionss^ %:DAI1:;+1c1#;J;:!# m#$%DjQQ .unittest_setup_class_fixtures++C322nnVEE G  .'J +-!I/1 +-s5=BA%B BB%A>>BBB_unittest_setUpClass_fixture_classTr(funcrJscopeautousereturnNonerkrrxzGenerator[None]rBrGrH_register_fixture __qualname__rJ)r;rNrprmrfrnros ` @@@@r4rEz3UnitTestCase._register_unittest_setup_class_fixturezs\4036 =X-#0,? R .# .  . .0 $$6601A1A0BC-;; 7 r=ct|ddt|ddy d fd }|jjjd|j||j ddy) zWRegister an auto-use fixture to invoke setup_method and teardown_method (#517). setup_methodNteardown_methodc3K|j}t|r#|j}tj|d||j d||j yywrh)instancerCrjrr-function)rkr;rlrnros r4unittest_setup_method_fixturez[UnitTestCase._register_unittest_setup_method_fixture..unittest_setup_method_fixturesl##D4 33nnVEE dG,,- #w//0$sA+A._unittest_setup_method_fixture_rTrsrzr{)r;rNrrnros @@r4rDz4UnitTestCase._register_unittest_setup_method_fixtures^T23 148 =X- 1# 1  1 $$66233C3C2DE.;; 7 r=N)rxzIterable[Item | Collector])rNtyperxry)__name__ __module__r} nofuncargsr<rTrErDr[r=r4r0r0NsJ#M>6 p r=r0c2eZdZUdZdZdZded<dZedZ dfd Z dfd Z dd Z dd Z dd Z dd Zdd ddZ d ddZ d d!dZddZddZd"dZddZ d#fd Z d$dZd%dZxZS)&rLTFNz7list[_pytest._code.ExceptionInfo[BaseException]] | None_excinfoct|jtsJ|jj|jSrZ) isinstanceparentr0r)r(r:s r4 _getinstancezTestCaseFunction._getinstances-$++|444{{tyy))r=c|jSrZ)rr:s r4 _testcasezTestCaseFunction._testcases }}r=cfd|_t| tjdkrd|_yy)Nr!)_explicit_tearDownsuperrnr* version_info_cached_errors_and_skipsr; __class__s r4rnzTestCaseFunction.setups3=A     g %QUD ) &r=cz|j|jd|_d|_|`t|yrZ)r_obj _instancerrors r4rozTestCaseFunction.teardowns:  " " .  # # %&*D # N r=cyrZr[r;testcases r4 startTestzTestCaseFunction.startTest r=ct|} tjjtj |}|j }|j}|j j#dgj%y#t$r tj|}|jddtdj|dn8#tjtf$rt$rtd|dYnwxYwnJ#t$rtj$r+tjjj}YnwxYwYwxYw)NrzCNOTE: Incompatible Exception Representation, displaying natively: Fpytracez6ERROR: Unknown Incompatible Exception representation: r)_handle_twisted_exc_info_pytest_coder BaseException from_exc_infovalue traceback TypeErrorformat_exceptioninsertrjoinr-KeyboardInterrupt from_current__dict__ setdefaultappend)r; rawexcinfoexcinforcvaluess r4 _addexcinfozTestCaseFunction._addexcinfos8-j9  Emm11-@NNG  A!!A.   R077@- E E&77DFMM3 %8(9:$,,6>; % % >> E!--55BBD E) EsVAB E AC  D 2D?DDDEAE  E E  EEc t|dtjrt|dj|j |y#t$rYwxYw)Nr`)rrr-msgrrr;rrs r4addErrorzTestCaseFunction.addErrorsO *Q-8Z]&&' $   s5A AAc&|j|yrZ)rrs r4 addFailurezTestCaseFunction.addFailure s $r=handle_subtestscddlm}dfd }|s|yt||rA|j-jd}j |j ||yyt jdkr@jj*j\}}t|dk(r|yy|y)Nr_SubTestc tjd#tj$r&jtjYywxYwrh)rr-rr*exc_info)rlr;sr4add_skipz*TestCaseFunction.addSkip..add_skip*s@ 1nnVEE>> 1  0 1s6AAr!rw) unittest.caserrr addSubTest test_caser*rr_outcome_obtain_errors_and_skipsra) r;rrlrrrrsubtest_errorsrcs ` ` r4addSkipzTestCaseFunction.addSkip%s + 1  J  h ) J}}(==, 2 2HhG)')dmm.D.D.P$($A$A$C!~&!+J, r=c tt|y#tj$r&|jt j YywxYwrZ)rstrr-rr*r)r;rrrls r4addExpectedFailurez#TestCaseFunction.addExpectedFailureFs:  - #f+  -   S\\^ , -s6AAcd}|r|d|jz } t|dy#tj$r&|jt j YywxYw)NzUnexpected successz: Fr)rlrr-rr*r)r;rrlrs r4addUnexpectedSuccessz%TestCaseFunction.addUnexpectedSuccessQsW #  R ' 'C - e $~~ -   S\\^ , -s &6AAcyrZr[rs r4 addSuccesszTestCaseFunction.addSuccess_rr=cyrZr[rs r4stopTestzTestCaseFunction.stopTestbrr=cyrZr[)r;relapseds r4 addDurationzTestCaseFunction.addDurationerr=cRddlm}|j}|J||t|jr ||yt |j tsJt|jxst|j j}|jjdr!|s|j|_ t|ddt||j|j ||t||jy#t||jwxYw)Nr)&maybe_wrap_pytest_function_for_tracing)resultusepdbtearDowncyrZr[)argss r4r\z*TestCaseFunction.runtest..r]r=)_pytest.debuggingrrrr)rrr0rCconfig getoptionrrsetattrr(delattr)r;rrrOs r4rSzTestCaseFunction.runtesthsL==###.t4 TXX & D !dkk<8 88!$((+K{4;;??/KG{{$$X.w*2*;*;'*.@A Hdii 2 -%$)),$)),s . DD&cTt||}|jd}|s|}|S)NcN|jjjd S)N __unittest)frame f_globalsrM)rRs r4r\z4TestCaseFunction._traceback_filter..s!''++// ==r=)r_traceback_filterfilter)r;rr ntracebackrs r4rz"TestCaseFunction._traceback_filters9G-g6 %Y%% = "Jr=c |xtdx\t|d}n&xxtdx\nxnn|}n }t|tddddddd}t |j t r |j nd}|jj||}tj|t|t|jdd } |jj| t|| r|jj!||| t"j$d kr]|j'\} } t)| dkDr;t)| dkDr,| d } || d ur| D]\} }|j+| |dyyyyy)Nr[T) _ispytestrcall)startstopdurationwhenr)itemr)rkwargs)captured_output captured_logs)report)noderrr!rFr)tupler rrr_messagerihookpytest_runtest_makereportr_newrdictparamspytest_runtest_logreportrpytest_exception_interactr*rrrar)r;rtestrexception_info unreachable call_inforr sub_reportrnon_subtest_skiplast_subset_errorrrls r4rzTestCaseFunction.addSubTests!.x4!H'4'!)[)TN    *$--=dmm4554i5P"''  s4 +< =   ++:+> &y* = JJ 0 0 * 1    g %/3/L/L/N ,N,#$q(S-@1-D$22$6!044,<N(& Xvu MN5.E( &r=cddlm}tjdksJd|j |jS|j j jDcgc]\}}t||r|||f}}}|j j jDcgc]\}}t||s||f}}}||f|_||fScc}}wcc}}w)zMCompute or obtain the cached values for subtest errors and non-subtest skips.rrr!z2This workaround only should be used in Python 3.10) rrr*rrrrerrorsrrO)r;rrRyrnon_subtest_skipss r4rz)TestCaseFunction._obtain_errors_and_skipss*') @ )  ( ( 400 0 ..55 1!X&1=F   ..66 1a*F  *89J(K%000  s CCrw)runittest.TestCaserxry)r_SysExcInfoTyperxry)rrrrrxry)rrrlrrboolrxry)r)rrrrrlrrxryrZ)rrrlz"twisted.trial.unittest.Todo | Nonerxry)rrrfloatrxry)rz*_pytest._code.ExceptionInfo[BaseException]rxz_pytest._code.Traceback)rr rr rz^ExceptionInfo[BaseException] | tuple[type[BaseException], BaseException, TracebackType] | Nonerxry)rxztuple[list[Any], list[Any]])rrr}rfailfastr__annotations__rpropertyrrnrorrrrrrrrrrrSrrr __classcell__)rs@r4rLrLseJHHLHEL* U  AD%)%7F% %%)%7F% % TX)36LP J -# -$ - -  -6: -# -3 -  -   -B A   4N4N4N 4N 4Nl1r=rLT)tryfirstct|tr/|jr#|jjd|_ |`tjjd}|r||jrot|jj|jrD|jtdjfd|j}|j|_yyyy#t $rYwxYw)Nrr'c@ttjSrZ)rrr)rsr4r\z+pytest_runtest_makereport..sc'--6H1Ir=)rrLrpoprrAttributeErrorr*r+rMrSkipTestr from_callr)rrr'call2rs @r4rrs$() ====,,Q/DL K {{z*HDLLZ 0B0BHDUDU%V,,(()I499U}} &WLx "  sC C+*C+c.tt|ddS)zDReturn True if the given object has been marked with @unittest.skip.__unittest_skip__F)rrBr9s r4rCrCs 0%8 99r=clttjurddlm}ddlm}|t|yy)zRRegister the TestCaseFunction class as an IReporter if twisted.trial is available.r) IReporter)classImplementsN)_get_twisted_versionTwistedVersion NotInstalledtwisted.trial.itrialr#zope.interfacer$rL)r#r$s r4pytest_configurer*s*^%@%@@22()4 Ar=c:eZdZdZeZeZeZy)r&z The Twisted version installed in the environment. We have different workarounds in place for different versions of Twisted. N)rrr}__doc__r Version24 Version25r'r[r=r4r&r&sII6Lr=r&c dtjvrtjSddl}ddl}|j jd}|jj|}|jdkrtjStjS)NrArtwisted) r*r+r&r'importlib.metadatapackaging.versionmetadataversionparsemajorr-r.) importlib packaging version_strr5s r4r%r%sr s{{2***$$,,Y7K%%k2G}}''''''r=_twisted_raw_excinfo)wrapperc#*Kttjureddlmcm}|j j dfd }tj5}|j|j d|dcdddSdS#1swYyxYww)Nrc|tj}n+| t|}|tjd}|||f}t|tt | |||||y#t $r||||YywxYw)Nr ) captureVars)r*rrrTWISTED_RAW_EXCINFO_ATTRrr)r; exc_valueexc_typeexc_tbr? raw_exc_infooriginal__init__s r4store_raw_exception_infoz9pytest_runtest_protocol..store_raw_exception_info4s "||~ ##IH> \\^A.F ()V< D2E,4G H D )Xv; D y(FC Ds A--BB__init__)NNNN) r%r&r-twisted.python.failurepythonfailureFailurerGrcontextr)rr3rFpatcherrEs @r4pytest_runtest_protocolrN,s!9!99++::..KO D& " g OOBJJ 4L M     sAB!B9BB Bct}|tjur|S|tjur4t |t r"t |t }t|t |S|S|tjurt|truddl }t||jjjrG|j}|t!j"d}t%|j&|j&|fS|SJd|)z Twisted passes a custom Failure instance to `addError()` instead of using `sys.exc_info()`. Therefore, if `rawexcinfo` is a `Failure` instance, convert it into the equivalent `sys.exc_info()` tuple as expected by pytest. rNr zUnexpected Twisted version: )r%r&r'r-hasattrr@rBrr.rrrHrIrJrK __traceback__r*rrr)rtwisted_versionsaved_exc_infor0tbs r4rrNs+,O.555 N44 4 :7 8$Z1IJN J 8 9! ! N44 4 j- 0 )*gnn&<&<&D&DE--:*BJ,,-z/?/?CC G4_4EFFur=)r2zModule | Classr(rr)objectrxzUnitTestCase | None)rrrzCallInfo[None]rxry)rxrrw)rxr&)rrrxzIterator[None])rz_SysExcInfoType | BaseExceptionrxr)Gr, __future__rcollections.abcrrrrenumrr r.r*rtypestypingr r r'r _pytest._coderr _pytest.compatrr_pytest.configr_pytest.fixturesr_pytest.monkeypatchr _pytest.nodesrr_pytest.outcomesrrrr_pytest.pythonrrr_pytest.runnerrr_pytest.subtestsrrrexceptiongroupr$r%twisted.trial.unittestr0rrrrr5r0rLrrCr*r&r%r@rNrr[r=r4rgsy:"$%$$   '',#++#!!!" #!#6+*BQ'!-#! $} }e.A.A AB  CC%(C/5CC(@ 5@ FO1xO1d 4%%$: 5 T (,2 $B&G/&G&Gr=