wL ieu UdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m Z ddlmZmZmZmZmZmZmZmZmZmZmZmZmZddlZddlmZddlm Z m!Z!m"Z"ddl#m$Z$dd l%m&Z&dd l'm(Z(dd l)m*Z* dd l+m,Z-ddl/m0Z0ddl1m2Z2ddl3m4Z4m5Z5ddl6m7Z7ddl8m9Z9er ddl:Z:ddl;mdZ?dZ@dZAe=e>e?e@eAfZBdaCdaDeedeEd<eFejjdDcgc] }eI| c}ZJde*ddfdZKdRd ZLd!e d"e0deed#fd$ZMeJdd%kreMZNd"e0deed#fd&ZMe5ZOd'Z5d(e dePfd)ZQd*e(d(e d"e0dePfd+ZRd(e dePfd,ZSGd-d.e"ZTGd/d0eUZVded1fd2ZW dSd3edd4eePd5eId6ePdd1f d7ZXGd8d9ejZZdee[eIffd:Z\d;Z]d<Z^Gd=d>ejZ`dTd?Zad@ebdePfdAZce dedBfdCZdGdDdEejZedFeZde-fdGZfdedfdHZgdUdIZhdeIfdJZideIfdKZjdeIfdLZkdMe[deIfdNZlejdOPdee[effdQZny#e.$r dd l+m-Z-YwxYwcc}w)Vz6Discover and run ipdoctests in modules and test files.N)contextmanager)Path) TYPE_CHECKINGAnyCallableDict GeneratorIterableListOptionalPatternSequenceTupleTypeUnion)outcomes) ExceptionInfoReprFileLocation TerminalRepr)TerminalWriter safe_getattr)Config)Parser) TopRequest)FixtureRequest) Collector)OutcomeException) fnmatch_ex import_path)approx) PytestWarningIPDoctestOutputCheckernonecdiffndiffudiffonly_first_failurer% CHECKER_CLASS.parserreturnc~|jddddg|jddd |jd }|jd d d dd|jdtjddt d|jddgddd|jdd d dd|jdd d d d!y)"Nipdoctest_optionflagszoption flags for ipdoctestsargsELLIPSIS)typedefaultipdoctest_encodingz!encoding used for ipdoctest fileszutf-8)r4collectz--ipdoctest-modules store_trueFz!run ipdoctests in all .py modulesipdoctestmodules)actionr4helpdestz--ipdoctest-reportr)z;choose another output format for diffs on ipdoctest failureipdoctestreport)r3r4r:choicesr;z--ipdoctest-globappendpatz4ipdoctests file matching pattern, default: test*.txt ipdoctestglob)r9r4metavarr:r;z --ipdoctest-ignore-import-errorszignore ipdoctest ImportErrorsipdoctest_ignore_import_errorsz--ipdoctest-continue-on-failurez>for a given ipdoctest, continue to run after the first failureipdoctest_continue_on_failure)addinigetgroup addoptionstrlowerDOCTEST_REPORT_CHOICES)r-groups m/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/IPython/testing/plugin/pytest_ipdoctest.pypytest_addoptionrLPs MM%    MMA7 OOI &E OO 0   OO YY J&   OO C   OO* , -  OO) M , cdayN) RUNNER_CLASSrMrKpytest_unconfigurerRs LrM file_pathparent)IPDoctestModuleIPDoctestTextfilec$|j}|jdk(rO|jjr8t t |t |fstj||}|Syt|||rtj||}|Sy)Nz.pypath) configsuffixoptionr8any _is_setup_py _is_main_pyrU from_parent _is_ipdoctestrV)rSrTrZmodtxts rKpytest_collect_filerds]]F5 == ) )# ) $k)&< =3 $3#>#>vI#>#VCJ  vy& 1!2!>!>vI!>!V rMc,tt||SrO) _collect_filer)rYrTs rKrdrdsT$Z00rMcRddl}t|jj|S)Nr)py.path _import_pathrYlocal)rYrootpys rKr r sBGGMM$/00rMrYcV|jdk7ry|j}d|vxsd|vS)Nzsetup.pyFs setuptoolss distutils)name read_bytes)rYcontentss rKr^r^s2 yyJ H H $ @ (@@rMrZcjdvr|jjry|jdxsdg}t fd|DS)N)z.txtz.rstTr@z test*.txtc36K|]}t|ywrO)r).0globrYs rK z _is_ipdoctest..s8$z$%8s)r[session isinitpath getoptionr])rZrYrTglobss ` rKrarasL {{&&6>>+D+DT+J   _ - >+E 8%8 88rMc |jdk(S)Nz __main__.py)rorXs rKr_r_s 99 %%rMcBeZdZdeeeeefddfdZdeddfdZ y)ReprFailDoctestreprlocation_linesr.Nc||_yrO)r~)selfr~s rK__init__zReprFailDoctest.__init__s #5rMtwc~|jD].\}}|D]}|j||j|0yrO)r~line toterminal)rr reprlocationlinesrs rKrzReprFailDoctest.toterminalsD#'#:#: ( L%     # #B ' (rM) __name__ __module__ __qualname__rrrrGrrrrQrMrKr}r}s>5"*51A8C=1P+Q"R5 5 (^((rMr}c.eZdZdedddffd ZxZS)MultipleDoctestFailuresfailureszdoctest.DocTestFailurer.Nc0t|||_yrO)superrr)rr __class__s rKrz MultipleDoctestFailures.__init__s   rM)rrrrr __classcell__rs@rKrrs!!*B!C!!!rMrIPDocTestRunnerc6ddlddlm}Gfdd|}|S)Nrr#)rc eZdZdZ ddeddeedededdf fd Zd d d d deddffd Z d d d d de e e e e jfddffd 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. Ncheckerr%verbose optionflagscontinue_on_failurer.c8t||||||_y)N)rrr)rrr)rrrrrrs rKrz8_init_runner_class..PytestDoctestRunner.__init__s! G Wg;  W':D $rMtestdoctest.DocTestexamplezdoctest.Examplegotclj|||}|jr|j|y|rO)DocTestFailurerr>)routrrrfailuredoctests rKreport_failurez>_init_runner_class..PytestDoctestRunner.report_failures5-g,,T7C@G'' 7# rMexc_infoct|dtr|dt|dtjrt j dj |||}|jr|j|y|)Nr#zQuitting debugger) isinstancerbdbBdbQuitrexitUnexpectedExceptionrr>)rrrrrrrs rKreport_unexpected_exceptionzK_init_runner_class..PytestDoctestRunner.report_unexpected_exceptionsm(1+'78qk!(1+s{{3 121g11$JG'' 7# rMNNrT)rrr__doc__r boolintrrGrrr BaseExceptiontypes TracebackTyperr)rrs@rKPytestDoctestRunnerrs ;?&* (,  ;67 ;d^ ;  ; "&  ;   ; $ '      $ '   D/@S@SST      rMr)r ipdoctestr)rrrs @rK_init_runner_classrs*-o-^ rMrrrrc@t tat||||S)Nrrrr)rPrrs rK _get_runnerrs-)+  /  rMc eZdZUeeefed< ddedddedded d df fd Ze dddedddd ffd Z dd Z ddZ ddZ ddZdeed eeefffd Zd eedefeeeffdZeddkred efdZxZSxZS) IPDoctestItem _user_ns_origNrorTz)Union[IPDoctestTextfile, IPDoctestModule]runnerrdtestrr.clt|||||_||_d|_d|_i|_yrO)rrrrobjfixture_requestr)rrorTrrrs rKrzIPDoctestItem.__init__s9 v&  9=rMc*t|||||S)zThe public named constructor.)rorTrr)rr`)clsrTrorrrs rKr`zIPDoctestItem.from_parent*sw"VFRW"XXrMc|jot||_t|jj}|jj dj D] \}}|||< |jj j|ddlm }t|jjd|ri|_ |jjtjtjj|jj tjjddt tjd<tj|j_yyy)N) getfixtureipdoctest_namespacer# IPExampler_ __builtins__)r_setup_fixturesrdictgetfixturevalueitemsrzupdaterrrexamplesr_ipuser_nspopbuiltins)rrzrovaluers rKsetupzIPDoctestItem.setup7s :: !#24#8D D$8$8$H$HIE#33CC% eg $ e$d  $ JJ   # #E * ,$**--a0)<&("""))#++6 ""4::#3#34 T*.6 N+#&;;  = "rMcRddlm}t|jjd|rZi|j_t jjt jj|j|` |jj jy)Nr#rr) rrrrrrzrrclearrr)rrs rKteardownzIPDoctestItem.teardownPsp( djj))!,i 8!DJJ  KK    KK  t11 2"  rMc|jJ|jJt|j|jg}t t d}t t dd}tj}tj|jj |jj|j|dtj||rtt d|n!t t drtt d |r t|y#tj||rtt d|wt t drtt dwwxYw)NrF)r clear_globs)rr_check_all_skipped$_disable_output_capturing_for_darwinhasattrrgetattrosgetcwdchdirfspathdirnamerunsetattrdelattrr)rrhad_underscore_valueunderscore_original_valuecurdirs rKruntestzIPDoctestItem.runtest\szz%%%{{&&&4::& 11313 'x5$+Hc4$@!  $$% ' KKOODJJH%O H HHV ##'@A3'#& )(3 3  HHV ##'@A3'#&(s #(D##A E/cJtjdk7ry|jjj d}|rd|j d|j \}}tjj|tjj|yy)zNDisable output capturing. Otherwise, stdout is lost to ipdoctest (pytest#985).DarwinNcapturemanagerT)in_) platformsystemrZ pluginmanager getpluginsuspend_global_captureread_global_capturesysstdoutwritestderr)rcapmanrerrs rKrz2IPDoctestItem._disable_output_capturing_for_darwinzs~ ??  ( **445EF   ) )d ) 3113HC JJ  S ! JJ  S ! rMexcinfocddl}d}t|j|j|jfr|jg}n0t|jt r|jj }|t|!|Sg}|D]X}|j}|j}|j}|jd} n|j|jzdz} t|j} t|| | } t!} t#|j$j'd} | |jj(J|jj(j+d}|jJt-|Dcgc]\}}d||jzdz|fz}}}|t/|jdz d|jdz}n=dg}d}|j0j+D]}|j3d |d |d }t||jr0|| j5||j6| j9d z }nwt;j<|j>}|d tA|jzgz }|tCjD|j>Dcgc]}|jGd c}z }|j3| |f[tI|Scc}}wcc}w)Nrr#r<Fz%03d %s z?EXAMPLE LOCATION UNKNOWN, not showing all tests of that examplez>>>z???  z... zUNEXPECTED EXCEPTION: %s)%rrrrrrrr repr_failurerrfilenamelinenor3rr _get_checker_get_report_choicerZry docstring splitlines enumeratemaxsourcer>output_differencersplitr from_exc_inforrepr tracebackformat_exceptionstripr})rrrrr~rrrrrmessagerr report_choicerixindentr inner_excinfors rKrzIPDoctestItem.repr_failures     MMG22G4O4OP  H  '> ?}}--H  7'0 0) =GooG<>A;MNV#NN557#DLL4xq!78"F#'7#9#9:22W[[-%+!. ; ;G! /3-1    <  *+  )*     Y; Y Y " Y ! Y Y/2 !4< ">3}->3 sL !>3@JE%(:C(?"@(3-QT"TUJa1  %$ %  %rMrc ddl}t|j|j|j|j |j |jttt S)Nr) DONT_ACCEPT_TRUE_FOR_1DONT_ACCEPT_BLANKLINENORMALIZE_WHITESPACEr2IGNORE_EXCEPTION_DETAILCOMPARISON_FLAGS ALLOW_UNICODE ALLOW_BYTESNUMBER) rrr%r&r'r2r(r)_get_allow_unicode_flag_get_allow_bytes_flag_get_number_flagrs rK_get_flag_lookupr1sZ &==%;;$99!! ' ? ? 11-/)+!  rMcr|jjd}t}d}|D] }|||z} |S)Nr0r)rZgetinir1)rToptionflags_strflag_lookup_tableflag_accflags rKget_optionflagsr8sImm**+BCO(*H,%d++, OrMcR|jd}|r|jdrd}|S)NrCusepdbF)getvalue)rZrs rK_get_continue_on_failurer<s/ //*IJ ??8 $"'  rMceZdZdZdeefdZeddkr#ede fdZ e dddde e ffd Z xZSxZS) rVNr.c#Kddl}ddlm}|jj d}|j j |}t|j }|j j}ddi}t|}td|tt|j} |} | j||||d} | jr&tj!|| j| | yyw) Nrr#)IPDocTestParserr5r__main__Frrrrrorr)rrr?rZr3rY read_textrGror8rrr< get_doctestrrr`) rrr?encodingtextrrorzrrr-rs rKr6zIPDoctestTextfile.collects.;;%%&:;yy""8,tyy>yy~~Z(%d+ # N 8 E  !"!!$tXqA ==++499V4,  sC4C6rrec,t|jSrOrrs rKrYzIPDoctestTextfile.pathrrMrrYrYc j|ddl}|jj|}t|d||d|SNr)rTrrQrirYrkrr`rrTrrYkwrmrs rKr`zIPDoctestTextfile.from_parent:t,7&JfVJrJ JrM)rrrrr rr6r"r#rrYr!r r`rrs@rKrVrVss C-08a1  %$ %  %  #' K 4. K  KrMrVczddltfd|jD}|rtjdyy)zVRaise pytest.skip() if all examples in the given DocTest have the SKIP option set.rNc3jK|]*}|jjjd,yw)FN)optionsgetSKIP)rtrrs rKrvz%_check_all_skipped...s$PQaiimmGLL%8Ps03z%all docstests skipped by +SKIP option)rallrpytestskip)r all_skippedrs @rKrr)s1P$--PPK ;<rMrc 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 rK _is_mockedrZ3s SMtT rM)NNNc#Ktjdddtdtfdtttgtfdtffd}|t_ dt_y#t_wxYww)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\c.t|xsSrO)rZ)r_stopr^s rKzF_patch_unwrap_mock_aware.._mock_aware_unwrap..Isjo6TtrMzGot 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)rZ Exceptionwarningswarnr")r^r]era real_unwraps` @rK_mock_aware_unwrapz4_patch_unwrap_mock_aware.._mock_aware_unwrapBsi |tz1"4j99Et*TU U  MMGHO    s-- A"AA)inspectunwraprrr )rhrgs @rK_patch_unwrap_mock_awarerk<sn..KMQsCx +3HcUCZ4H+I "(GN% $sAA9A) A9) A66A9c|eZdZdeefdZeddkr#edefdZ e dddde effd Z xZ SxZ S) rUr.c#>Kddl}ddlm}m}Gdd|}|jj dk(rt ddkrJ|jjj|j|jjd}nd |jji}t d k\rd |d <|jjj|j|jjdfi|}n= d |jji}t d k\rd |d <t|jfi|}||}t#|}t%d |t't)|j} |j+|j,D]4} | j.st0j3|| j | | 6y#t$rB|jjdr#tj d|jznYwxYww)Nrr#) DocTestFinderr?c2eZdZdZfdZ dfd ZxZS)7IPDoctestModule.collect..MockAwareDocTestFinderzA hackish ipdoctest finder that overrides stdlib internals to fix a stdlib bug. https://github.com/pytest-dev/pytest/issues/3456 https://bugs.python.org/issue25532 ct|tr t|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__)rr#rrrirjr _find_lineno)rr source_linesrs rKrtzDIPDoctestModule.collect..MockAwareDocTestFinder._find_linenofsOc8,!#vs3C3 .!..-Cw+ rMc t|ryt5t| |||||||dddy#1swYyxYwrO)rZrkr_find) rtestsrromodulerurzseenrs rKrwz=IPDoctestModule.collect..MockAwareDocTestFinder._findzsEc?-/GMsD&,ts 7Ar)rrrrrtrwrrs@rKMockAwareDocTestFinderrp_s   (   rMr{z conftest.pyre importmoderootpath)r#Fconsider_namespace_packagesrlrBzunable to import module %r)r-rArB)rrrnr?rYror"rZr_importconftestryr}r ImportErrorr;rUrVr8rrr<findrrrr`) rrrnr?r{rykwargsfinderrrrs rKr6zIPDoctestModule.collect[s=$ ]$ L 99>>] *a 1$22BBIIKK)),7 %dkk&:&:;!V+.funcs rM)noder^r)r~rFfuncargsT) _ispytestrrQ)rrw_fixturemanagerr"getfixtureinfo _fixtureinfor _fillfixtures)rr^fmrrs rKrrs L    - -B"D >F"z 1 1 1! !L%\TBO%%' rMc>ddl}ddlddlm}Gfdd|}|S)Nrr#r$ceZdZWjdWjZWjdWjZWjdWjZde 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||||ry|tz}|tz}|t z}|s|s|sydt t dt dt f fd }|r&||j|}||j|}|r&||j|}||j|}|r|j||}t||||S)NTFregexrcr.c*j|d|S)Nz\1\2)sub)rrcres rKremove_prefixeszX_init_checker_class..LiteralsOutputChecker.check_output..remove_prefixessvveWc22rM) r check_outputr-r.r/r rG_unicode_literal_re_bytes_literal_re_remove_unwanted_precision) rrrr allow_unicode allow_bytes allow_numberrrrs rKrz?_init_checker_class..LiteralsOutputChecker.check_outputsw#D#{;'*A*CCM%(=(??K&)9);;L \ 3ws| 3# 3# 3&t'?'?F%d&>&>D&t'='=tD%d&<&.LiteralsOutputChecker._remove_unwanted_precisionsc11$78E0056D5zSY& FE4( J1*+''**=*+''+*># ww{3H!)!1As8} 'X.I#veAGGI.>B N'SS 0aggi&01AGGI=AEEGfDTDV@WWaeeg 1QUUWqwwy5HIIF J JrM)rrrcompileUNICODErrVERBOSErrGrrrrr)rrs@rKLiteralsOutputCheckerrs !jj)CRZZPJJ'A2::NZZ & JJ) . @S @s @ @ @6 3 S S rMr)rrrr%)rr%rrs @rK_init_checker_classrs$ 1O 6Ob ! rMc6t tatS)aReturn a IPDoctestOutputChecker 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 ipdoctest should run in Python 2 and Python 3. * NUMBER to ignore floating-point differences smaller than the precision of the literal number in the ipdoctest. An inner class is used to avoid importing "ipdoctest" at the module level. )r+rrQrMrKrr2s+- ?rMc.ddl}|jdS)z+Register and return the ALLOW_UNICODE flag.rNr*rregister_optionflagr0s rKr-r-Fs &7 & & 77rMc.ddl}|jdS)z)Register and return the ALLOW_BYTES flag.rNr+rr0s rKr.r.Ms &7 & &} 55rMc.ddl}|jdS)z$Register and return the NUMBER flag.rNr,rr0s rKr/r/Ts &7 & &x 00rMkeyc ddl}t|jt|jt |j t|jtdi|S)zReturn the actual `ipdoctest` module flag value. We want to do it as late as possible to avoid importing `ipdoctest` 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 rKrr[sN  $W%9%9#W%9%9#W%9%90'2S2S"A      rMrw)scopectS)zcFixture that returns a :py:class:`dict` that will be injected into the namespace of ipdoctests.)rrQrMrKrrls  6MrMrr)rrr.N)r.r%)orrrrirrrrrrd contextlibrpathlibrtypingrrrrr r r r r rrrrrU_pytestr_pytest._code.coderrr _pytest._ior_pytest.compatr_pytest.configr_pytest.config.argparsingr_pytest.fixturesrrr _pytest.nodesr_pytest.outcomesr_pytest.pathlibrr _pytest.python_apir!_pytest.warning_typesr"rrr%rrrrrrIrPr+r tuple __version__r rr"rLrRrdrgrjrr^rar_r}rcrrrItemrrGr1r8r<ModulerVrobjectrZrkrUrrrr-r.r/rfixturer)parts0rKrs =    % LL&'!,0=$-3%/1#%%%+?(,  :> x567>f.@.@.F.Fs.KLdD LM/V//d  e:;<"!q'M11 %>? @1 L1 AtAA9&99i9D9&d&t& (l (!i! 3D!233n37" $  . / d^   (u%FKKu%p $sCx.  2K 2Kj=Ft%),<"=%%:hKfmmhKV-N(V!T":;V!r(886s61#1 C C "i T#s(^!A0//0@Ms?I0I  II