bgie UdZddlZddlZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z ddl mZddl mZddl mZddl mZdd l mZdd l mZdd l mZdd l mZdd l mZddl mZddl mZddl mZddl mZddlmZddlmZddlmZddlm 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/m1Z1dd l2m3Z3dd!l2m4Z4dd"l5m6Z6dd#l7m8Z8dd$l9m:Z:erddl;Z;d%Zd(Z?d)Z@ee?e@fZAdaBdaCeed*eDd+<d,e(d-dfd.ZEdad/ZFd0e d1e-d-eed2fd3ZGd4e d-eHfd5ZId6e&d4e d1e-d-eHfd7ZJd4e d-eHfd8ZKGd9d:e ZLGd;dZO dbd@ed*dAeeHdBePdCeHd-d=f dDZQGdEdFe.ZRd-eeSePffdGZTdHZUdIZVGdJdKe6ZWdcdNZXdOeYd-eHfdPZZe d-edQfdRZ[GdSdTe6Z\dUeRd-e+fdVZ]d-ed*fdWZ^dddXZ_d-ePfdYZ`d-ePfdZZad-ePfd[Zbd\eSd-ePfd]Zce*d^_d-eeSeffd`ZddS)ez4Discover and run doctests in modules and test files.N)contextmanager)Path)Any)Callable)Dict) Generator)Iterable)List)Optional)Pattern)Sequence)Tuple)Type) TYPE_CHECKING)Union)outcomes) ExceptionInfo)ReprFileLocation) TerminalRepr)TerminalWriter safe_getattr)Config)Parser)fixture)FixtureRequest) Collector)Item)OutcomeException)skip fnmatch_ex) import_path)Module)approx) PytestWarningnonecdiffndiffudiffonly_first_failuredoctest.OutputChecker CHECKER_CLASSparserreturnc|ddddg|ddd |d }|d d d dd|dtjddt d|ddgddd|dd d dd|dd d d d!dS)"Ndoctest_optionflagszOption flags for doctestsargsELLIPSIS)typedefaultdoctest_encodingzEncoding used for doctest fileszutf-8)r5collectz--doctest-modules store_trueFzRun doctests in all .py modulesdoctestmodules)actionr5helpdestz--doctest-reportr*z9Choose another output format for diffs on doctest failure doctestreport)r4r5r;choicesr<z--doctest-globappendpatz2Doctests file matching pattern, default: test*.txt doctestglob)r:r5metavarr;r<z--doctest-ignore-import-errorszIgnore doctest ImportErrorsdoctest_ignore_import_errorsz--doctest-continue-on-failurezz_is_doctest..s-88$z$%%888888rN)r\session isinitpath getoptionr^)r[rZrUglobss ` rLrbrbsh {&&&6>+D+DT+J+J&t   ] + + < }E 8888%888 8 88rNc|jdkS)Nz __main__.py)rgrYs rLr`r`s 9 %%rNcVeZdZdeeeeefddfdZdeddfdZ dS)ReprFailDoctestreprlocation_linesr/Nc||_dSrP)rv)selfrvs rL__init__zReprFailDoctest.__init__s#5rNtwc~|jD]4\}}|D]}||||5dSrP)rvline toterminal)rxrz reprlocationlinesr|s rLr}zReprFailDoctest.toterminalsZ#'#: ( ( L%    # #B ' ' ' ' ( (rN) __name__ __module__ __qualname__r rrrHryrr}rRrNrLrurusn5"*51A8C=1P+Q"R5 5555 (^(((((((rNruc4eZdZdedddffd ZxZS)MultipleDoctestFailuresfailureszdoctest.DocTestFailurer/NcVt||_dSrP)superryr)rxr __class__s rLryz MultipleDoctestFailures.__init__s$   rN)rrrr ry __classcell__rs@rLrrsQ!*B!C!!!!!!!!!!!rNrdoctest.DocTestRunnerc:ddlGfddj}|S)Nrc eZdZdZ ddeddeeded ed df fd Zd d ddded dffd Z d d ddde e e e e jfd dffd ZxZS)/_init_runner_class..PytestDoctestRunnerzRunner to collect failures. Note that the out variable in this case is a list instead of a stdout-like object. NrTcheckerr,verbose optionflagscontinue_on_failurer/c^t|||||_dS)N)rrr)rryr)rxrrrrrs rLryz8_init_runner_class..PytestDoctestRunner.__init__s2 GG  Wg;  W W W':D $ $ $rNtestdoctest.DocTestexamplezdoctest.Examplegotchj|||}|jr||dS|rP)DocTestFailurerr?)rxoutrrrfailuredoctests rLreport_failurez>_init_runner_class..PytestDoctestRunner.report_failuresC-g,T7C@@G'  7##### rNexc_infoct|dtr|dt|dtjrt jdj|||}|jr||dS|)NzQuitting debugger) isinstancerbdbBdbQuitrexitUnexpectedExceptionrr?)rxrrrrrrs rLreport_unexpected_exceptionzK_init_runner_class..PytestDoctestRunner.report_unexpected_exceptions(1+'788 "qk!(1+s{33 3 12221g1$JJG'  7##### rNNNrT)rrr__doc__r boolintryrHrrr BaseExceptiontypes TracebackTyperr)rrs@rLPytestDoctestRunnerrs5  :>&* (,  ; ;56 ;d^ ;  ; "&  ;   ; ; ; ; ; ; $ '           $ '   D/@SST              rNr)r DebugRunner)rrs @rL_init_runner_classrsLNNN-------g1---^ rNTrrrrcRttat||||S)Nrrrr)rQrrs rL _get_runnerrs:)++  /    rNc eZdZ ddedddeddedd df fd Zedddeddddffd Zdd Zdd Z ddZ de e d e eefffd Zd ee defeeeffdZxZS) DoctestItemNrgrUz%Union[DoctestTextfile, DoctestModule]runnerrdtestrr/ct||||_||_d|_d|_dSrP)rryrrobjfixture_request)rxrgrUrrrs rLryzDoctestItem.__init__sB v&&&  9=rNcNt||||S)zThe public named constructor.)rgrUrr)rra)clsrUrgrrrs rLrazDoctestItem.from_parent s'ww""VFRW"XXXrNc |jt||_t|jj}|jdD] \}}|||< |jj|dSdS)N) getfixturedoctest_namespace)r_setup_fixturesrdictgetfixturevalueitemsrrupdate)rxrrrgvalues rLsetupzDoctestItem.setups : !#24#8#8D D$8$HIIIE#3CC#  egg $ $ e$d J  # #E * * * * * " !rNc|jJ|jJt|j|g}|j|j||rt |dS)N)r)rr_check_all_skipped$_disable_output_capturing_for_darwinrunr)rxrs rLruntestzDoctestItem.runtest!sz%%%{&&&4:&&& 1133335  111  4)(33 3 4 4rNcTtjdkrdS|jjd}|rm|d|\}}tj |tj |dSdS)zFDisable output capturing. Otherwise, stdout is lost to doctest (#985).DarwinNcapturemanagerT)in_) platformsystemr[ pluginmanager getpluginsuspend_global_captureread_global_capturesysstdoutwritestderr)rxcapmanrerrs rLrz0DoctestItem._disable_output_capturing_for_darwin-s ?   ( ( F*445EFF  "  ) )d ) 3 3 31133HC J  S ! ! ! J  S ! ! ! ! !  " "rNexcinfocddl}d}t|j|j|jfr |jg}n&t|jt r |jj}|!t|Sg}|D]}|j }|j j }j d}nj |j zdz}t|j} t||| } t!} t#|jd} |z|j jJ|j jd} j Jfdt-| D} | t/|j dz d|j dz} n>dg} d}|jD]}| d |d |d } t||jr3| | ||j| d z } nTt;j|j}| d tA|jzgz } | dtCj"|jDz } || | ftG|S)Nrrr=Fc:g|]\}}d|jzdz|fzS)z%03d %sr)lineno)rlixrs rL z,DoctestItem.repr_failure.._s?=CaIT[1!4a 88rN z?EXAMPLE LOCATION UNKNOWN, not showing all tests of that examplez>>>z???  z... zUNEXPECTED EXCEPTION: %sc8g|]}|dS)r)strip)rlrs rLrz,DoctestItem.repr_failure..ss/&'AGGDMMrN)$rrrrrrrr repr_failurerrfilenamerr4rr _get_checker_get_report_choicer[rq docstring splitlines enumeratemaxsourcer?output_differencersplitr from_exc_inforrepr tracebackformat_exceptionru)rxrrrrvrrrrmessager~r report_choicerindentr| inner_excinforrs @rLrzDoctestItem.repr_failure9s     MG2G4OP   . HH  '> ? ? .}-H  77''00 0) =) =GoGA;MMNV#N5577##DLL!7!7!7!7!7888"FF'7#9:: 22W[-%++!. ;G > >8 >01 > )* >  > > > > > > Y7 Y Y ( Y ! Y Y Y Y Y[ Y++++ 4 4 4 4 " " " ">3}->3 sL !>3>3>3>3>3>3@HE%(:C(?"@(3-QT"TUHHHHHHHHrNrc ddl}t|j|j|j|j|j|jttt S)Nr) DONT_ACCEPT_TRUE_FOR_1DONT_ACCEPT_BLANKLINENORMALIZE_WHITESPACEr3IGNORE_EXCEPTION_DETAILCOMPARISON_FLAGS ALLOW_UNICODE ALLOW_BYTESNUMBER) rrrrrr3rr_get_allow_unicode_flag_get_allow_bytes_flag_get_number_flagrs rL_get_flag_lookupr ~saNNN &=%;$9! ' ? 1-//)++!!    rNcz|jd}t}d}|D] }|||z}|S)Nr1r)r[getinir )rUoptionflags_strflag_lookup_tableflag_accflags rLget_optionflagsrsOm**+@AAO(**H,,%d++ OrNcb|d}|r|drd}|S)NrDusepdbF)getvalue)r[rs rL_get_continue_on_failurers? //*GHH( ??8 $ $ ("'  rNc*eZdZdZdeefdZdS)rWNr/c#Kddl}|jd}|j|}t |j}|jj}ddi}t|}td|tt|j}|j } | ||||d} | j r't|| j|| VdSdS)Nrr6r__main__Frrrrrgrr)rr[rrZ read_textrHrgrrrr DocTestParser get_doctestexamplesrra) rxrencodingtextrrgrrrrr.rs rLr7zDoctestTextfile.collects;%%&899y""8,,ty>>y~Z(%d++ # NN 8 E E    '&((!!$tXqAA = ))49V4*       rN)rrrrr rr7rRrNrLrWrWs9 C+.rNrWrrcvddltfd|jD}|rtddSdS)zVRaise pytest.skip() if all examples in the given DocTest have the SKIP option set.rNc3XK|]$}|jjdV%dS)FN)optionsgetSKIP)rlrrs rLrnz%_check_all_skipped..s5PPQaimmGL%88PPPPPPrNz!all tests skipped by +SKIP option)rallr r )r all_skippedrs @rLrrsYNNNPPPP$-PPPPPK2 01111122rNrc(t|ddduS)zmReturn if an object is possibly a mock object by checking the existence of a highly improbable attribute.1pytest_mock_example_attribute_that_shouldnt_existNr)rs rL _is_mockedr,s! SMtTT rN)NNNc#Ktjdddtdtfdtttgtfdtffd}|t_ dVt_dS#t_wxYw)zContext manager which replaces ``inspect.unwrap`` with a version that's aware of mock objects and doesn't recurse into them.Nstopfunc.r/r/c | |turtS|fdS#t$r'}tjd|ddtd}~wwxYw)Nr.c8t|p SrP)r,)r_stopr0s rLzF_patch_unwrap_mock_aware.._mock_aware_unwrap..sjoo6TtrNzGot z when unwrapping z. This is usually caused by a violation of Python's object protocol; see e.g. https://github.com/pytest-dev/pytest/issues/5080)r, Exceptionwarningswarnr&)r0r/er3 real_unwraps` @rL_mock_aware_unwrapz4_patch_unwrap_mock_aware.._mock_aware_unwraps |tz11"{4j9999E;t*T*T*T*T*TUUU U    MMGHaaO      s55 A&"A!!A&)inspectunwraprrr )r:r9s @rL_patch_unwrap_mock_awarer=s.KMQsCx +3HcUCZ4H+I "(GN% $$$$$s &A88Bc&eZdZdeefdZdS)rVr/c#Kddl}Gdd|j}|jjdkrJ|jj|j|jd|jj}n~ t|j|jj|jd}nC#t$r6|j drtd |jznYnwxYw|}t|}td |tt!|j }|||jD].}|jr%t(||j|| V/dS) Nrc2eZdZdZfdZ dfd ZxZS)5DoctestModule.collect..MockAwareDocTestFinderzA hackish doctest finder that overrides stdlib internals to fix a stdlib bug. https://github.com/pytest-dev/pytest/issues/3456 https://bugs.python.org/issue25532 ct|trt|d|}t|drt j|}t ||S)a3Doctest code does not take into account `@property`, this is a hackish way to fix it. https://bugs.python.org/issue17446 Wrapped Doctests will need to be unwrapped so the correct line number is returned. This will be reported upstream. #8796 fget __wrapped__)rpropertygetattrhasattrr;r<r _find_lineno)rxr source_linesrs rLrHzBDoctestModule.collect..MockAwareDocTestFinder._find_linenosmc8,,4!#vs33C3 ...!.--Cww++ rNr/Nc t|rdSt5t|||||||ddddS#1swxYwYdSrP)r,r=r_find) rxtestsrrgmodulerIrrseenrs rLrKz;DoctestModule.collect..MockAwareDocTestFinder._findsc??F-//GGMMsD&,ts(AAAr)rrrrrHrKrrs@rLMockAwareDocTestFinderrAsh        (           rNrOz conftest.py importmode)rootpath)rootmoderCzunable to import module %rFrr)r DocTestFinderrZrgr[r_importconftestrqrQr# ImportErrorrr rrrrfindrr rra)rxrrOrMfinderrrrs rLr7zDoctestModule.collects$ $ $ $ $ W%:$ $ $ L 9>] * *[.>>  %%l33-?FF $I-..|<<    ;''(FGG5 ABBBBCB  ('))%d++ # NN 8 E E    KK88  D} !--tyt.  s59B//=C/.C/N)rrrr rr7rRrNrLrVrVs;I+.IIIIIIrNrV doctest_itemcdd}i|_|jj}|||dd|_t |d}||S) zEUsed by DoctestTextfile and DoctestItem to setup fixture information.r/NcdSrPrRrRrNrLr0z_setup_fixtures..funcAs rNF)noder0rfuncargsT) _ispytestr)r]ro_fixturemanagergetfixtureinfo _fixtureinfor _fillfixtures)rYr0fmrs rLrr>s}    L   -B " 1 1 $!2!!L%\TBBBO!!### rNcBddl}ddlGfdd|j}|S)NrceZdZdjZdjZdjZde de de de ffd Z de de de fd Z xZS) 2_init_checker_class..LiteralsOutputCheckerz(\W|^)[uU]([rR]?[\'\"])z(\W|^)[bB]([rR]?[\'\"])a (?P (?P (?P [+-]?\d*)\.(?P\d+) | (?P [+-]?\d+)\. ) (?: [Ee] (?P [+-]?\d+) )? | (?P [+-]?\d+) (?: [Ee] (?P [+-]?\d+) ) ) wantrrr/ct|||rdS|tz}|tz}|t z}|s|s|sdSdt t dt dt f fd }|r"||j|}||j|}|r"||j|}||j|}|r| ||}t|||S)NTFregexrdr/c2|d|S)Nz\1\2)sub)rirdres rLremove_prefixeszX_init_checker_class..LiteralsOutputChecker.check_output..remove_prefixes{svveWc222rN) r check_outputrr r r rH_unicode_literal_re_bytes_literal_re_remove_unwanted_precision) rxrgrr allow_unicode allow_bytes allow_numberrmrrls rLrnz?_init_checker_class..LiteralsOutputChecker.check_outputpsIww##D#{;; t'*A*C*CCM%(=(?(??K&)9););;L   \ u 3ws| 3# 3# 3 3 3 3 3 3 E&t'?FF%od&>DD C&t'=tDD%od&.LiteralsOutputChecker._remove_unwanted_precisions11$7788E005566D5zzSYY&& FE4(( J J1*+''**=*=*+''+*>*># ww{33H!)!1AAs8}} 'X.I##veAGGII.>.>B N'S'S'SSS 0aggii&001AGGII=AEEGGfDTDVDV@WWaeegg 1QUUWWqwwyy5HIIFJrN)rrrcompileUNICODErorpVERBOSEr|rHrrrnrqr)rrls@rLLiteralsOutputCheckerrfRs !jj)CRZPPJJ'A2:NNZZ & J)  . @S @s @ @ @ @ @ @ @ @ @6 3 S S        rNr)rrl OutputChecker)rrrls @rL_init_checker_classrNs_NNN IIIOOOOOOO 5OOOb ! rNcHttatS)aReturn a doctest.OutputChecker subclass that supports some additional options: * ALLOW_UNICODE and ALLOW_BYTES options to ignore u'' and b'' prefixes (respectively) in string literals. Useful when the same doctest should run in Python 2 and Python 3. * NUMBER to ignore floating-point differences smaller than the precision of the literal number in the doctest. An inner class is used to avoid importing "doctest" at the module level. )r-rrRrNrLrrs+-- ??rNc*ddl}|jdS)z+Register and return the ALLOW_UNICODE flag.rNrrregister_optionflagr s rLrrsNNN &7 & 7 77rNc*ddl}|jdS)z)Register and return the ALLOW_BYTES flag.rNrrr s rLr r sNNN &7 &} 5 55rNc*ddl}|jdS)z$Register and return the NUMBER flag.rNrrr s rLr r sNNN &7 &x 0 00rNkeyc ddl}t|jt|jt |jt|jtdi|S)zReturn the actual `doctest` module flag value. We want to do it as late as possible to avoid importing `doctest` and all its dependencies when parsing options, as it adds overhead and breaks tests. rN) rDOCTEST_REPORT_CHOICE_UDIFF REPORT_UDIFFDOCTEST_REPORT_CHOICE_CDIFF REPORT_CDIFFDOCTEST_REPORT_CHOICE_NDIFF REPORT_NDIFF(DOCTEST_REPORT_CHOICE_ONLY_FIRST_FAILUREREPORT_ONLY_FIRST_FAILUREDOCTEST_REPORT_CHOICE_NONE)rrs rLrrsH NNN $W%9#W%9#W%90'2S"A      rNro)scopectS)aFixture that returns a :py:class:`dict` that will be injected into the namespace of doctests. Usually this fixture is used in conjunction with another ``autouse`` fixture: .. code-block:: python @pytest.fixture(autouse=True) def add_np(doctest_namespace): doctest_namespace["np"] = numpy For more details: :ref:`doctest_namespace`. )rrRrNrLrrs  66MrNrr)rrr/N)r/r,)errr;osrrrrr6 contextlibrpathlibrtypingrrrrr r r r r rrrr_pytestr_pytest._code.coderrr _pytest._ior_pytest.compatr_pytest.configr_pytest.config.argparsingr_pytest.fixturesrr _pytest.nodesrr_pytest.outcomesrr _pytest.pathlibr"r#_pytest.pythonr$_pytest.python_apir%_pytest.warning_typesr&rrrrrrrJrQr-__annotations__rMrSrerr_rbr`rur5rrrrrrHr rrrWrobjectr,r=rVrrrrr r rrrRrNrLrs9:::    %%%%%% ,,,,,,//////++++++&&&&&&''''''!!!!!!,,,,,,$$$$$$++++++######------!!!!!!&&&&&&''''''!!!!!!%%%%%%//////NNN#%%%+?(,  9= x456===/V/////d  e678"AtAAAAA99d9I9$9999&d&t&&&& ( ( ( ( (l ( ( (!!!!!i!!! 2D!892222l26" $  - . d^   (HHHHH$HHHD $sCx.     f>2222Ft%),<"=%%%%:JJJJJFJJJZ + .     U!T"9:U!U!U!U!p(888886s66661#1111 C C    " y4S>rN