'L iUddlmZddlZddlmZddlmZddlmZddlmZddlZddl Z ddl m Z ddl m Z dd l m Z ddlZdd lmZddlZddlZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddlm$Z$ddlm%Z%ddlm&Z&ddl'Z'ddl(Z(ddl)m*Z*ddl)m+Z+ddl)m,Z,ddl)m-Z-dd l.m/Z/dd!l0m1Z1dd"l0m2Z2dd#l3m4Z4dd$l5m6Z6dd%l7m8Z8dd&l7m9Z9ejtd'krdd(l;me?e@e>e?d*fzZAGd+d,ZBGd-d.ZCGd/d0ZDGd1d2eEeDZF d[ d\d4ZGe&d5e?d36ZHe ejGd7d8e!eHZJeKeeJe?geFfzZLd9eMd:<ejGd;d<ZNejd=>Gd?d@ZOejd=>GdAdBeOZPejd=>GdCdDePZQejd=>GdEdFePZRejd=>GdGdHeOZSGdIdJeSZTejd=>GdKdLeOZUejd=>GdMdNeOZVejd=>GdOdPeOZWejd=>GdQdReOZXejd=>GdSdTeOZYd]dUZZdVZ[ee'jjdWZ^e^jdXk(r e^jZ^ee(jjZad^dYZb d_dZZcy)`) annotationsN)Callable)Iterable)Mapping)Sequence) CO_VARARGS)CO_VARKEYWORDS)StringIO)Path) extract_tb)format_exception)format_exception_only) FrameSummary)CodeType) FrameType) TracebackType)Any)ClassVar)Final)final)Generic)Literal)overload) SupportsIndex) TypeAlias)TypeVar) findsource getrawcode)getstatementrange_ast)Source)TerminalWriter) safeformatsaferepr) get_real_func)check_ispytest) absolutepath) bestrelpath )BaseExceptionGroup)longshortlinenonativevalueauto.ceZdZdZdZd dZeddZdZdZ e ddZ e ddZ e dd Z e dd Zdd Zddd Zy)Codez#Wrapper around Python code objects.rawc||_yNr7)selfobjs X/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/_pytest/_code/code.py__init__z Code.__init__As c$|t|Sr:r)clsr<s r= from_functionzCode.from_functionDs:c?##r?c4|j|jk(Sr:r7)r;others r=__eq__z Code.__eq__Hsxx599$$r?Nc4|jjdz SN)r8co_firstlinenor;s r= firstlinenozCode.firstlinenoNsxx&&**r?c.|jjSr:)r8co_namerJs r=namez Code.nameRsxxr?c|jjsy t|jj}|js t d|S#t$r|jjcYSwxYw)zoReturn a path object pointing to source code, or an ``str`` in case of ``OSError`` / non-existing file.zpath check failed.)r8 co_filenamer(existsOSError)r;ps r=pathz Code.pathVshxx## (TXX112A88:233H (88'' ' (s;AA76A7c6t|j\}}|S)zJReturn a _pytest._code.Source object for the full source file of the code.)rr8)r;full_s r= fullsourcezCode.fullsourcegsTXX&a r?c,t|jS)zGReturn a _pytest._code.Source object for the code object's source only.)r!r8rJs r=sourcez Code.sourcemsdhhr?c|j}|j}|r,||jtzz }||jtzz }|j d|S)zReturn a tuple with the argument names for the code object. If 'var' is set True also return the names of the variable and keyword arguments when present. N)r8 co_argcountco_flagsrr co_varnames)r;varr8argcounts r=getargsz Code.getargsrsPhh??   z1 1H  ~5 5Hy))r?)r<rreturnNone)r<objectrcr6rcintrcstrrc Path | str)rc Source | Nonercr!F)r`boolrcztuple[str, ...])__name__ __module__ __qualname____doc__ __slots__r> classmethodrBrE__hash__propertyrKrNrUrYr[rbr?r=r6r6<s-I$$%H ++  ((   *r?r6ceZdZdZdZd dZeddZeddZeddZ eddZ eddZ d Z dd Z ddd Zy )FramezgWrapper around a Python frame holding f_locals and f_globals in which expressions can be evaluated.r7c||_yr:r7)r;frames r=r>zFrame.__init__s r?c4|jjdz SrG)r8f_linenorJs r=linenoz Frame.linenosxx  1$$r?c.|jjSr:)r8 f_globalsrJs r=rzFrame.f_globalssxx!!!r?c.|jjSr:)r8f_localsrJs r=rzFrame.f_localssxx   r?c@t|jjSr:)r6r8f_coderJs r=codez Frame.codesDHHOO$$r?c|jj tdS|jjj|jS)zStatement this frame is at.rP)rrYr! getstatementrrJs r= statementzFrame.statements= 99   '": yy##00==r?c |jj}|j|t||j|S)zEvaluate 'code' in the frame. 'vars' are optional additional local variables. Returns the result of the evaluation. )rcopyupdateevalr)r;rvarsrs r=rz Frame.evals5==%%'D$..(33r?ct|S)zCReturn a 'safe' (non-recursive, one-line) string repr for 'object'.r$)r;res r=reprz Frame.reprs r?cg}|jj|D]#} |j||j|f%|S#t$rY3wxYw)zReturn a list of tuples (name, value) for all arguments. If 'var' is set True, also include the variable and keyword arguments when present. )rrbappendrKeyError)r;r`retvalargs r=rbz Frame.getargssa 99$$S) C  sDMM#$678     s A AAN)r|rrcrdrfrczdict[str, Any])rcr6rm)rerercrirn)r`ro)rprqrrrsrtr>rwrrrrrrrrbrxr?r=rzrzs.I%%""!!%%>> 4  r?rzceZdZdZdZ d ddZ ddZeddZddZ e jdkredd Z edd Z edd Znedd Z edd Z eddZed dZeddZd!dZed"dZed#dZed$dZddZ d d%dZeeZd&dZd!dZed!dZy)'TracebackEntryzA single entry in a Traceback. _rawentry _repr_styleNc ||_||_yr:r)r;rawentry repr_styles r=r>zTracebackEntry.__init__s !)",r?c.t|j|Sr:)rr)r;rs r=with_repr_stylezTracebackEntry.with_repr_stylesdnnj99r?c4|jjdz SrG)r tb_linenorJs r=rzTracebackEntry.linenos~~''!++r?c:t|jd}|dS)NrH)limitr)r r)r; stack_summarys r=get_python_framesummaryz&TracebackEntry.get_python_framesummarys#4>>; Qr?r*cyr:rxrJs r=end_lineno_relativez"TracebackEntry.end_lineno_relativer?cyr:rxrJs r=colnozTracebackEntry.colnorr?cyr:rxrJs r= end_colnozTracebackEntry.end_colnorr?c|j}|jy|jdz |jjjz SrG)r end_linenor|rrK)r; frame_summarys r=rz"TracebackEntry.end_lineno_relativesC 88:M''/ ++a/$**//2M2MM Mr?c6|jjS)z>Starting byte offset of the expression in the traceback entry.)rrrJs r=rzTracebackEntry.colnos//177 7r?c6|jjS)z)r|rrUrrJs r=__repr__zTracebackEntry.__repr__s/!$**//"6"6!7qq8IKKr?c|jjj}|J|j|jS)z6_pytest._code.Source object for the current statement.)r|rrYrr)r;r[s r=rzTracebackEntry.statements8++!!!""4;;//r?cB|jjjS)zPath to the source code.)r|rrUrJs r=rUzTracebackEntry.pathszz###r?c.|jjS)zLocals of underlying frame.)r|rrJs r=localszTracebackEntry.localsszz"""r?cB|jjjSr:)r|rrKrJs r=getfirstlinesourcez!TracebackEntry.getfirstlinesourceszz***r?cp|jjj}|ydx}}|4|jjj}||j |d}|j } t |j||\}}}|||||< |||S#t$r|jdz}YwxYw)zReturn failing source code.N)astnoderH) r|rrYrUgetrr r SyntaxError)r;astcacher[keyrstartrXends r= getsourcezTracebackEntry.getsources ++ >g  **//&&C",,sD1'') (3 VWOGQ 8#7 ' eC   "++/C "s/BB54B5cd}|jj|jjfD] } |d}n|rt |r||S|S#t$rY.wxYw)aReturn True if the current frame has a var __tracebackhide__ resolving to True. If __tracebackhide__ is a callable, it gets called with the ExceptionInfo instance and can decide whether to hide the traceback. Mostly for internal use. F__tracebackhide__)r|rr Exceptioncallable)r;excinfotbh maybe_ns_dcts r=ishiddenzTracebackEntry.ishidden7svMR!ZZ00$**2F2FG L  "#67  8C=w<    sA AAc  |jjj} t|jj }d|jd|jdzd|d|d S#t $rt$rd}Yrrwrrsys version_inforrrr|rrrrUrrrr[rrrNrxr?r=rrs(,I 7;--4-  -:9: : ,,  '!              N  N  8  8  <  <..99L00 $$##+<@!8! !4i F2 O++r?rceZdZdZ d fd Z d d dZed dZed dZdfd Z ddZddZ xZ S) TracebackzQTraceback objects encapsulate and offer higher level access to Traceback entries.cxt|trdd}t| ||yt| |y)z@Initialize from given python traceback object and ExceptionInfo.c3NK|}|t||j}|yywr:)rtb_next)curcur_s r=fzTraceback.__init__..fms--0&(..<)r;tbr __class__s r=r>zTraceback.__init__fs4 b- ( ( G QrU # G R r?c|dntj|}|dntj|}|D]}|jj}|j} |t | |k7r6|&t | tr|d| jDvr^||j|k7rp|$|jjj|k7rt|jcS|S)aReturn a Traceback instance wrapping part of this Traceback. By providing any combination of path, lineno and firstlineno, the first frame to start the to-be-returned traceback is determined. This allows cutting the first part of a Traceback instance e.g. for formatting reasons (removing some uninteresting bits that deal with handling of the exception/traceback). Nc32K|]}t|ywr:)ri).0rTs r= z Traceback.cut..s$FSV$Fs) osfspathr|rrUrirr parentsrrKrr) r;rUrrK excludepathpath_ excludepath_xrcodepaths r=cutz Traceback.cutws  "))D/*2t +8N  *A77<>%'"5c":; ;7&s+ +r?c^ttrfd}n}tt||S)aReturn a Traceback instance with certain items removed. If the filter is an `ExceptionInfo`, removes all the ``TracebackEntry``s which are hidden (see ishidden() above). Otherwise, the filter is a function that gets a single argument, a ``TracebackEntry`` instance, and should return True when the item should be added to the ``Traceback``, False when not. c(|j Sr:)r)r excinfo_or_fns r=z"Traceback.filter..sqzz-88r?)r ExceptionInforfilter)r;rfns ` r=rzTraceback.filters+ m] 38BBD)**r?ci}t|D]\}}|jjjt |jjj |j f}|j|g}t|jj}|r|D] }||k(s |ccS|j|y)z~Return the index of the frame/TracebackEntry where recursion originates if appropriate, None if no recursion occurred.N) enumerater|rrUidr8r setdefaultdictrr)r;cacheientryrvalueslocotherlocs r=recursionindexzTraceback.recursionindexsCE!$ HAu ++""''EKK,<,<,@,@)A5<<OC%%c2.Fu{{++,C &!H3 ! MM#  r?)rz(TracebackType | Iterable[TracebackEntry]rcrd)NNNN) rUzos.PathLike[str] | str | NonerrrKrrzos.PathLike[str] | Nonercr)rrrcr)rrrcr)rzSupportsIndex | slicerczTracebackEntry | Traceback)rz?ExceptionInfo[BaseException] | Callable[[TracebackEntry], bool]rcrr) rprqrrrsr>rrrrr __classcell__rs@r=rrcs[! 4! !&/3!"&/3 "+"" " - "  "HDD 77, +V+  +(r?rTcT t|dg}|st |tr |j}n t|}dj|g|S#t$rQttjj dddd}tj dkrt ||rg}nYwxYw)N __notes__z urllib.error HTTPErrorrx)r+ r) getattrrrmodulesrrrr-messagerijoin)excinclude_subexception_msgnotesrrs r=stringify_exceptionrs ["- $ 38J(K++c( 99     CKKOONDA;PRS   g %*S)*DE   s A AB'&B'E)bound covariantceZdZUdZdZded<ded<ded<d ed < d#d d  d$dZe d% d&dZe d% d'dZ ed%d(dZ ed)dZ d*dZ e d+dZe d,dZe d-dZe d.dZe d/dZej&d0dZd.dZd1d2dZd3dZd4dZ d5 d6dZd7dZ d8 d9d Zd d d! d:d"Zy );rzJWraps sys.exc_info() objects and offers help for navigating the traceback.zAssertionError('assert r_assert_start_repr'tuple[type[E], E, TracebackType] | None_excinfori _striptextTraceback | None _tracebackNF _ispytestcDt|||_||_||_yr:)r'r&r'r))r;r striptext tracebackr+s r=r>zExceptionInfo.__init__s! y! ##r?c||jsJdt|||jf}|j||S)aEReturn an ExceptionInfo for an existing exception. The exception must have a non-``None`` ``__traceback__`` attribute, otherwise this function fails with an assertion error. This means that the exception must have been raised, or added a traceback with the :py:meth:`~BaseException.with_traceback()` method. :param exprinfo: A text string helping to determine if we should strip ``AssertionError`` from the output. Defaults to the exception message/``__str__()``. .. versionadded:: 7.4 zTExceptions passed to ExcInfo.from_exception(...) must have a non-None __traceback__.) __traceback__type from_exc_info)rA exceptionexprinfoexc_infos r=from_exceptionzExceptionInfo.from_exceptionsJ.&&  3 &OY 0G0GH  844r?cd}|Rt|dtr?t|ddd}|t|d}|r|j |j rd}|||dS)z@Like :func:`from_exception`, but using old-style exc_info tuple.rPNrHmsgzAssertionError: Tr*)rAssertionErrorrr% startswithr$)rAr5r4r's r=r2zExceptionInfo.from_exc_info$sl   8A; Gx{E48H#HQK0H//0F0FG/ 8Z488r?ctj}|dJd|dJd|dJd|d|d|df}tj||S)a=Return an ExceptionInfo matching the current traceback. .. warning:: Experimental API :param exprinfo: A text string helping to determine if we should strip ``AssertionError`` from the output. Defaults to the exception message/``__str__()``. rzno current exceptionrH)rr5rr2)rAr4tupr5s r= from_currentzExceptionInfo.from_current5s|lln1v!9#99!1v!9#99!1v!9#99!FCFCF+**8X>>r?c|ddS)z!Return an unfilled ExceptionInfo.NTr*rx)rAs r= for_laterzExceptionInfo.for_laterIs44((r?c8|jJd||_y)z< rHz tblen=r)r&rrpr%lenr.rJs r=rzExceptionInfo.__repr__~sS == >4>>**+1XdmmA6F-G,HPSTXTbTbPcOddeffr?c dfd |rSt|jtr9|jx}%|dt|jjdSt |j|j}dj |}|j}|r3|j|jr|t|jd}|S)aReturn the exception as a string. When 'tryshort' resolves to True, and the exception is an AssertionError, only the actual exception part of the exception representation is returned (so 'AssertionError: ' is removed from the beginning). ct|jdk7ryt|jdx}tr|S|S)NrHr)rN exceptionsrr-)ege_get_single_subexcs r=rTz1ExceptionInfo.exconly.._get_single_subexcsB2==!Q&r}}Q//!1CD)!,,Hr?Nz [single exception in ]rP)rR!BaseExceptionGroup[BaseException]rczBaseException | None) rr3r-r1rprrrstripr:r'rN)r;tryshortsubexclinestextrTs @r=exconlyzExceptionInfo.exconlys 1  !  4::'9:-djj99FZ5d4::6F6O6O5PPQR R%dii<wwu~{{} t/C023 r?c.t|j|S)zReturn True if the exception is an instance of exc. Consider using ``isinstance(excinfo.value, exc)`` instead. )rr3)r;rs r= errisinstancezExceptionInfo.errisinstances $**c**r?cJtdt|j dz dD]|}|j|}|j|r$|jj j j|j}}|jd}t||dz|cSy)NrHTrX) rangerNr.rr|rr8rQrr\ReprFileLocation)r;r r rUrr\s r= _getreprcrashzExceptionInfo._getreprcrashsrC//!3R8 CANN1%E>>$'${{//33??f,,,5'fqj'BB  C r?c $|dk(rhttt|j|j|j r|j dj nd|jSt||||||||} | j|S)aReturn str()able representation of this exception info. :param bool showlocals: Show locals per traceback entry. Ignored if ``style=="native"``. :param str style: long|short|line|no|native|value traceback style. :param bool abspath: If paths should be changed to absolute or left unchanged. :param tbfilter: A filter for traceback entries. * If false, don't hide any entries. * If true, hide internal entries and entries that contain a local variable ``__tracebackhide__ = True``. * If a callable, delegates the filtering to the callable. Ignored if ``style`` is ``"native"``. :param bool funcargs: Show fixtures ("funcargs" for legacy purposes) per traceback entry. :param bool truncate_locals: With ``showlocals==True``, make sure locals can be safely represented as strings. :param bool truncate_args: With ``showargs==True``, make sure args can be safely represented as strings. :param bool chain: If chained exceptions in Python 3 should be shown. .. versionchanged:: 3.9 Added the ``chain`` parameter. r2rN reprtraceback reprcrash) showlocalsstyleabspathtbfilterfuncargstruncate_locals truncate_argschain) ReprExceptionInfoReprTracebackNativer r1r3r.rrdFormattedExcinfo repr_excinfo) r;rirjrkrlrmrnrorpfmts r=getreprzExceptionInfo.getreprsb H $1$  7;~~q)334,,.  !+'  %%r?cd}t|j}d|d|}||k(r|dz }tj||sJ|y)zCheck whether the regular expression `regexp` matches the string representation of the exception using :func:`python:re.search`. If it matches `True` is returned, otherwise an `AssertionError` is raised. Tz/Regex pattern did not match. Expected regex: z Actual message: z* Did you mean to `re.escape()` the regex?)rr3research)r;regexprr3r8s r=matchzExceptionInfo.matchsf !#DJJ/!!' +!!&  + U? @ @Cyy',,'r?c |||kDry|jD]f}t|tr|j|||||dzry|||k7r5t||sB|"t |}t j ||sfyy)zFReturn `True` if a `BaseExceptionGroup` contains a matching exception.FrHT)rQrr-_group_containsrrxry)r; exc_groupexpected_exceptionr{ target_depth current_depthrr3s r=r}zExceptionInfo._group_containss  $=<+G'' C#12''+UL-RSBS (} /Lc#56 +C0yy.  r?)r{depthcd}t|jtsJ|d}| |dk\sJ||j|j|||S)aCheck whether a captured exception group contains a matching exception. :param Type[BaseException] | Tuple[Type[BaseException]] expected_exception: The expected exception type, or a tuple if one of multiple possible exception types are expected. :param str | re.Pattern[str] | None match: If specified, a string containing a regular expression, or a regular expression object, that is tested against the string representation of the exception and its `PEP-678 ` `__notes__` using :func:`re.search`. To match a literal string that may contain :ref:`special characters `, the pattern can first be escaped with :func:`re.escape`. :param Optional[int] depth: If `None`, will search for a matching exception at any nesting depth. If >= 1, will only match an exception if it's at the specified depth (depth = 1 being the exceptions contained within the topmost exception group). .. versionadded:: 8.0 .. warning:: This helper makes it easy to check for the presence of specific exceptions, but it is very bad for checking that the group does *not* contain *any other exceptions*. You should instead consider using :class:`pytest.RaisesGroup` z=Captured exception is not an instance of `BaseExceptionGroup`z!`depth` must be >= 1 if specifiedrH)rr3r-r})r;rr{rr8s r=group_containszExceptionInfo.group_contains0s\HN$**&89>3>91 5A:33.##DJJ0BE5QQr?)rPN) rr%r-rir.r(r+rorcrdr:)r3r r4 str | NonercExceptionInfo[E])r5 tuple[type[E], E, TracebackType]r4rrcr)r4rrcExceptionInfo[BaseException])rcr)r5rrcrd)rcztype[E])rcr )rcrrh)rcr)r3rrcrdrn)rXrorcri)rEXCEPTION_OR_MORErcro)rcReprFileLocation | None)Fr.FTFTTT)rirorjTracebackStylerkrorlz:bool | Callable[[ExceptionInfo[BaseException]], Traceback]rmrornrorororprorcz&ReprExceptionInfo | ExceptionChainRepr)rzzstr | re.Pattern[str]rcz Literal[True]rG) r~rVrrr{str | re.Pattern[str] | Nonerrrrgrcro)rrr{rrrrcro)rprqrrrsr$__annotations__r>rur6r2r>r@rCrwr1r3rrHr.setterrr\r^rdrvr{r}rrxr?r=rrsU#<<55O  &* $  $8 $ $$ $  $  $ $ 5  5  5 55: $9299  99 ??&))!       ""   g B+ ! &OS $"G&G&G& G& M G&  G&G&G&G& 0G&R0$( 4.,  !    D/3 (R-(R, (R  (R  (Rr?rrTracebackFilterceZdZUdZdZded<dZded<dZded <d Zd ed <d Z ded<d Z ded<dZ ded<d Z ded<d Z ded<d Zded<ej eddZded<d%dZd&dZd'dZ d( d)dZ d*dZ d+ d,dZd-dZ d. d/d Zd0d!Zd1d"Z d2d#Zd3d$Zy)4rsz>Presenting information about failing Functions and Generators.rr flow_markerr  fail_markerFrorir.rrjTrkrrlrmrnrorp)default_factoryinitrzdict[str | Path, ast.AST]rc" t|jt|dz }dt|t|j z zS#t$rt$r, t|d}n#t$rt$rYYywxYwYewxYw)NrHr`r)rirrNrrr)r;r[ss r= _getindentzFormattedExcinfo._getindentus F''F a89ACFS_,--!    r O$     s5&AB#A21B2BBBB Bc`|j|j}||j}|Sr:)rrdeindent)r;r r[s r=_getentrysourcez FormattedExcinfo._getentrysources+/  __&F r?c|jrig}|jjdD]=\}}|jr t |}n t |d}|j ||f?t |Sy)NT)r`)maxsize)rmr|rbror%r ReprFuncArgs)r;r argsargnameargvaluestr_reprs r= repr_argszFormattedExcinfo.repr_argsst ==D%*[[%8%8T%8%B 1!%%'1H'$?H Wh/0  1  % %r?Nc g}||dkr|t|z }||t|jk\s|dkr td}d}d} |r~|j| |j|j z|j |j |j||j|j ||||n|jd|D]} |j| | z|j|jdz|j|z|j |j |j||j||||||j|dzdD]} |j| | z|8|rdn|j|} |j |j|| d |S) z,Return formatted and marked up source lines.Nrr )raw_liner0rrrr rHrT)indentmarkall) rNrZr!rstripextendget_highlight_arrows_for_line raw_linesrr get_exconly) r;r[ line_indexrr/end_line_indexrrrZ space_prefixr0rs r= get_sourcezFormattedExcinfo.get_sources  *q. #f+ %J >Z3v||+<< QE]FJ  LL Z(@(F(F(HH I LL22#--j9j1779%-' 3  [j1 2 \D01 2 LL))E1FLL4LL M LL22#--j9j1%-' 3  Z!^%56 2 \D01 2  QT__V%z<10 = )risortrrnr%r# ReprLocals)r;rrZrkeysrNr3rs r= repr_localszFormattedExcinfo.repr_localss ??E#);CSVs]C;D; IIK =t >)LL!<= ++#+E?#-e#4LLD:S !;< =$e$ $+BJ>>*-D*41A7KK))%,,7JUHj+uM M g  S/55d;<UD$e< < T--ga-@AUD$e<