'L iݏ dZddlmZddlZddlZddlmZddlmZddlmZddl Z ddl Z ddl m Z ddl Z ddl Z ddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZerddlmZddl 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/ed Z0dVd!Z1dWd"Z2dWd#Z3dXd$Z4e"d%&dYd'Z5Gd(d)e jlZ7Gd*d+e jlZ8Gd,d-e8Z9Gd.d/eZ:Gd0d1ejveeZZ?Gd8d9eZCGd>d?eZFe jdDk\sereGdEdFeeeZHn"GdGdFejdFdHdIgeeZHGdJdKeeZJdZdLZKGdMdNZLGdOdPeeZMe(d[dQZNe(d[dRZOe(d\dSZPe(d[dTZQe(d\dUZRy)]z+Per-test stdout/stderr capturing mechanism.) annotationsN) Generator)Iterable)IteratorUnsupportedOperation) TemporaryFile) TracebackType)Any)AnyStr)BinaryIO)cast)Final)final)Generic)Literal) NamedTuple)TextIO) TYPE_CHECKING)Self)Config)hookimpl)Parser)check_ispytest)fixture) SubRequest) Collector)File)Item) CollectReportfdsysnotee-sysc|jd}|jddddgdd|jd d d d d y)Ngeneralz --capturestorer"methodr!z3Per-test capturing method: one of fd|sys|no|tee-sys)actiondefaultmetavarchoiceshelpz-s store_constr$capturezShortcut for --capture=no)r*constdestr.)getgroup addoption _addoption)parsergroups U/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/_pytest/capture.pypytest_addoptionr91sW OOI &E OO. B     ( cltjjdr ddl}yy#t$rYywxYw)a Ensure colorama is imported so that it attaches to the correct stdio handles on Windows. colorama uses the terminal on import time. So if something does the first import of colorama while I/O capture is active, colorama will fail in various ways. win32rN)r#platform startswithcolorama ImportError)r?s r8_colorama_workaroundrADs7 ||w'  (   s ' 33c, ddl}y#t$rYywxYw)aEnsure readline is imported early so it attaches to the correct stdio handles. This isn't a problem with the default GNU readline implementation, but in some configurations, Python uses libedit instead (on macOS, and for prebuilt binaries such as used by uv). In theory this is only needed if readline.backend == "libedit", but the workaround consists of importing readline here, so we already worked around the issue by the time we could check if we need to. rN)readliner@rCs r8_readline_workaroundrESs     s  ctjjdrttdrytdsytjdrjj n j}t |tjsyfd}|tjdt_ |tjdt_ |tjdt_ y) aWorkaround for Windows Unicode console handling. Python 3.6 implemented Unicode console handling for Windows. This works by reading/writing to the raw console handle using ``{Read,Write}ConsoleW``. The problem is that we are going to ``dup2`` over the stdio file descriptors when doing ``FDCapture`` and this will ``CloseHandle`` the handles used by Python to write to the console. Though there is still some weirdness and the console handle seems to only be closed randomly and not on the first call to ``CloseHandle``, or maybe it gets reopened with the same handle value when we suspend capturing. The workaround in this case will reopen stdio with a different fd which also means a different handle by replicating the logic in "Py_lifecycle.c:initstdio/create_stdio". :param stream: In practice ``sys.stdout`` or ``sys.stderr``, but given here as parameter for unittesting purposes. See https://github.com/pytest-dev/py/issues/103. r<pypy_version_infoNbufferrawc$tjds |ddk(rd}nd}tjt t j |j|||j|j|j|jS)NrIrw) hasattrrHio TextIOWrapperopenosdupfilenoencodingerrorsnewlinesline_buffering)fmode bufferingstreams r8 _reopen_stdioz3_windowsconsoleio_workaround.._reopen_stdiosqv}}e,aCII  #T9 5 JJ HH JJ     r:rbwb) r#r=r>rMrHrI isinstancerN_WindowsConsoleIOstdinstdoutstderr)r[ raw_stdoutr\s` r8_windowsconsoleio_workaroundreds0 << " "7 +wsrz)formatrrMrrrr)r class_names r8rzSysCaptureBase.reprysI9@@  II T6 " 6tDII D9 KK LL   r:cdj|jj|jt |dxrt |j xsd|j|jSr) rrrrrMrrrrrs r8__repr__zSysCaptureBase.__repr__sS9@@ NN # # II T6 " 6tDII D9 KK LL   r:c|j|vs1Jdj||jdj|yNz+cannot {} in state {!r}: expected one of {}z, rrjoinropstatess r8 _assert_statezSysCaptureBase._assert_state={{f$ 9 @ @DKK6!2  $r:c|jddtt|j|jd|_y)Nrrstarted)r$setattrr#rrrrs r8rzSysCaptureBase.starts. 7$45TYY - r:c|jdd|jdk(rytt|j|j |`|j jd|_y)Nrrr( suspendedr)r$rr)r#rrrrrs r8rzSysCaptureBase.donesR 6#RS ;;& TYY * I  r:c|jddtt|j|jd|_yNrr(r,r,)r$r)r#rrrrs r8rzSysCaptureBase.suspends. 9&>?TYY *! r:c|jdd|jdk(rytt|j|j d|_yNrr/r()r$rr)r#rrrs r8rzSysCaptureBase.resumes= 8%=> ;;) # TYY - r:r)r"rrz TextIO | Nonerrrr)rrrrrr"rr#ztuple[str, ...]rrr) rrrrrrr$rrrrr}r:r8r r jsU04 $EJ $ $ - $>B $  $    "  r:r c eZdZdZddZddZy)SysCaptureBinaryr:c|jdd|jjd|jjj }|jjd|jj |SNrr/rr$rrrHrrrress r8rzSysCaptureBinary.snapd 6#;< !ll!!&&( !  r:c|jdd|jj|jjj ||jjjyNrr/)r$rrrHrtrs r8rzSysCaptureBinary.writeorgsO :'?@  t$  r:Nrbytesrr>rrrrrrrrr}r:r8r4r4sL!r:r4c eZdZdZddZddZy) SysCapturerc|jddt|jtsJ|jj }|jj d|jj |Sr6)r$r_rrrrrr8s r8rzSysCapture.snaps` 6#;<$,, 222ll##% !  r:c|jdd|jj||jjyr<)r$rrtrrs r8rzSysCapture.writeorgs1 :'?@  r:Nrr r@r}r:r8rBrBsLr:rBcDeZdZd dZd dZd dZd dZd dZd dZd dZ y) FDCaptureBasec||_ tj|d|_tj||_ |dk(r8t tj d|_ t||_ d |_yttddddd|_ |t vr#t||j|_ d |_yt#||_ d |_y#t$r[tj tj tj|_tj|j|YwxYw) Nrutf-8)rT)rZrrT)rTrUrrr)targetfdrQfstattargetfd_invalidrrPdevnullO_RDWRdup2rR targetfd_saverrB syscapturer|r rrr)rrIs r8rzFDCaptureBase.__init__s   ) HHX  %)D !VVH- q= W=DL0:80DDO$ '*  " DL<'",Xt||"D$ #,H"5# E 513 BII0ND ! GGD))8 4 5sCA EEc d|jjd|jd|jd|jd|j d S)N< z oldfd= _state=z tmpfile=>)rrrIrOrrrs r8rzFDCaptureBase.__repr__sR''($--@R@R?STkk_Idll-=Q @ r:c|j|vs1Jdj||jdj|yrrr!s r8r$zFDCaptureBase._assert_stater%r:c|jddtj|jj |j |j jd|_y)z4Start capturing on targetfd using memorized tmpfile.rr'r(N) r$rQrNrrSrIrPrrrs r8rzFDCaptureBase.startsI 7$45  ##%t}}5  r:c|jdd|jdk(rytj|j|j tj |j|jW|j|j k7rtj |j tj |j|jj|jj d|_y)z_Stop capturing, restore streams, return original capture file, seeked to position zero.rr+N) r$rrQrNrOrIrrKrPrrrs r8rzFDCaptureBase.dones 6#RS ;;&  ""DMM2 ##$  ,$$ 5' HHT** +   r:c|jdd|jdk(ry|jjt j |j |jd|_yr.)r$rrPrrQrNrOrIrs r8rzFDCaptureBase.suspendsQ 9&>? ;;+ %  ! ""DMM2! r:c|jdd|jdk(ry|jjt j |j j|jd|_yr1) r$rrPrrQrNrrSrIrs r8rzFDCaptureBase.resume&sX 8%=> ;;) #     ##%t}}5 r:N)rIrrrrr2r) rrrrrr$rrrrr}r:r8rFrFs&'$R    " r:rFc$eZdZdZdZddZddZy)FDCaptureBinaryzWCapture IO to/from a given OS-level file descriptor. snap() produces `bytes`. r:c|jdd|jjd|jjj }|jjd|jj |Sr6r7r8s r8rzFDCaptureBinary.snap7r:r:ch|jddtj|j|y)"Write to original file descriptor.rr/N)r$rQrtrOrs r8rzFDCaptureBinary.writeorg?s' :'?@ ##T*r:Nr=r?rrr__doc__rrrr}r:r8r\r\/s L+r:r\c$eZdZdZdZddZddZy) FDCapturezTCapture IO to/from a given OS-level file descriptor. snap() produces text. rc|jdd|jjd|jj}|jjd|jj |Sr6)r$rrrrr8s r8rzFDCapture.snapMs^ 6#;< !ll! !  r:c|jddtj|j|j dy)r_rr/rHN)r$rQrtrOencoders r8rzFDCapture.writeorgUs0 :'?@ ##T[[%9:r:Nrr r`r}r:r8rcrcEs L;r:rc) c&eZdZUdZded<ded<y) CaptureResultOThe result of :method:`caplog.readouterr() `.r rxryN)rrrrarr}r:r8rjrjbs]   r:rjceZdZdZdZy)rjrkr}N)rrrrarr}r:r8rjrjks  ^ r:rxrycneZdZdZdZ d dZd dZddZddZdddZ ddZ dd Z dd Z dd Z y) MultiCaptureNFc.||_||_||_yrin_rxry)rrqrxrys r8rzMultiCapture.__init__xs 03/2/2r:c d|jd|jd|jd|jd|jd S)Nzs"   ! ! * * , !r:cR|jr|jjyyr)r_resumers r8rzCaptureManager.resume_fixtureBs"   ! ! ) ) + !r:c#K|jxr|jj}|r|j|jxr|jj }|r|j  d|r|j |r|jyy#|r|j |r|jwwxYww)zLContext manager to temporarily disable global and current fixture capturing.N)r _is_startedrrrrqrr)r do_fixture do_globals r8global_and_fixture_disabledz*CaptureManager.global_and_fixture_disabledHs**Rt/D/D/P/P/R   "**Rt/E/E/P/P/R   ' ' ) & **,##%**,##%sA5C 8B"<&C "'C  C c#K|j|j d|j|jd|j \}}|j |d||j |d|y#|j|jd|j \}}|j |d||j |d|wxYww)NFrrbrc)rrrrqrsadd_report_section)rwhenitemrxrys r8 item_capturezCaptureManager.item_captureYs ""$  9   # # %  ' 'E ' 2//1HC  # #D(C 8  # #D(C 8  # # %  ' 'E ' 2//1HC  # #D(C 8  # #D(C 8s!C$BAC$AC!!C$Trfc#PKt|trx|j d}|j|j \}}|r|j j d|f|r|j j d|f|Sd}|S#|jwxYww)NzCaptured stdoutzCaptured stderr)r_rrrqrssectionsappend)r collectorreprxrys r8pytest_make_collect_reportz)CaptureManager.pytest_make_collect_reportis i &  & & ( .++-//1HC ##%6$<= ##%6$<= C ++-s!B&BA)B&B##B&c#bK|jd|5dcdddS#1swYyxYww)Nsetuprrrs r8pytest_runtest_setupz#CaptureManager.pytest_runtest_setup|s-   w -    /# /,/c#bK|jd|5dcdddS#1swYyxYww)Ncallrrs r8pytest_runtest_callz"CaptureManager.pytest_runtest_calls-   vt ,    rc#bK|jd|5dcdddS#1swYyxYww)Nteardownrrs r8pytest_runtest_teardownz&CaptureManager.pytest_runtest_teardowns-   z4 0    r)tryfirstc$|jyrrors r8pytest_keyboard_interruptz(CaptureManager.pytest_keyboard_interrupt ""$r:c$|jyrrrs r8pytest_internalerrorz#CaptureManager.pytest_internalerrorrr:N)r)_CaptureMethodrrr)rz str | boolrrrr)rzCaptureResult[str])rzCaptureFixture[Any]rrrGenerator[None])rrrrrr)rrrz-Generator[None, CollectReport, CollectReport])rrrr) rrrrarrrrrprorrqrrrsrrrrrr contextlibcontextmanagerrrrrrrrrrr}r:r8rlrls7$A  $1 * 6 >) 3 0%+ * -, &&  9 9d" 6$dddt%%t%%r:rlceZdZdZddd d dZddZddZddZdd Zdd Z dd Z e jdd Z y)CaptureFixturez|Object returned by the :fixture:`capsys`, :fixture:`capsysbinary`, :fixture:`capfd` and :fixture:`capfdbinary` fixtures.NFconfig _ispytestct|||_||_|r|ni|_d|_|jj |_|jj |_yr)r captureclassr_config_capturer _captured_out _captured_err)rrrrrs r8rzCaptureFixture.__init__sU y!7C !'vR 59 %)%6%6%C%C%)%6%6%C%Cr:c |jbtd|jdi|j|jdi|j|_|jj yy)Nrp)r)r)rrnrrrurs r8rzCaptureFixture._starts` == (%D%%84<<8%D%%84<<8DM MM ) ) + !r:c|ji|jj\}}|xj|z c_|xj|z c_|jj d|_yyr)rryrrrrxs r8rzCaptureFixture.closes` == $}}779HC   # %    # %  MM ( ( * DM %r:c|j|j}}|j'|jj\}}||z }||z }|jj |_|jj |_t ||S)zRead and return the captured output so far, resetting the internal buffer. :returns: The captured content as a namedtuple with ``out`` and ``err`` string attributes. )rrrrwrrrj)r captured_out captured_errrxrys r8rwzCaptureFixture.readouterrs&*%7%79K9Kl == $}}//1HC C L C L!..;;!..;;\<88r:cR|j|jjyy)z1Suspend this fixture's own capturing temporarily.N)rr|rs r8rzCaptureFixture._suspends! == $ MM + + - %r:cR|j|jjyy)z0Resume this fixture's own capturing temporarily.N)rr~rs r8rzCaptureFixture._resumes! == $ MM * * , %r:cP|j|jjSy)z5Whether actively capturing -- not disabled or closed.F)rrrs r8rzCaptureFixture._is_starteds" == $==++- -r:c#K|jjjjd}|j 5ddddy#1swYyxYww)z>Temporarily disable capturing while inside the ``with`` block.riN)rrrk getpluginr)r capmanagers r8disabledzCaptureFixture.disabledsP&*\\%8%8%F%F%P%P &  3 3 5     sAAA AAA) rztype[CaptureBase[AnyStr]]rrrzdict[str, Any] | Nonerrrrrrrr)rrrrarrrrwrrrrrrr}r:r8rrs=)- D/DD & D  D D ,!9". -  r:rc#K|jjjd}tt|d}|j ||j ||j|jyw)aEnable text capturing of writes to ``sys.stdout`` and ``sys.stderr``. The captured output is made available via ``capsys.readouterr()`` method calls, which return a ``(out, err)`` namedtuple. ``out`` and ``err`` will be ``text`` objects. Returns an instance of :class:`CaptureFixture[str] `. Example: .. code-block:: python def test_output(capsys): print("hello") captured = capsys.readouterr() assert captured.out == "hello\n" riTrN) rrkrrrBrrrrrrwrs r8capsysrsi&%^^99CCDTUF$ZDIO '  A>Bc#K|jjjd}tt|t dd}|j ||j||j|jyw)aEnable simultaneous text capturing and pass-through of writes to ``sys.stdout`` and ``sys.stderr`` as defined by ``--capture=``. The captured output is made available via ``capteesys.readouterr()`` method calls, which return a ``(out, err)`` namedtuple. ``out`` and ``err`` will be ``text`` objects. The output is also passed-through, allowing it to be "live-printed", reported, or both as defined by ``--capture=``. Returns an instance of :class:`CaptureFixture[str] `. Example: .. code-block:: python def test_output(capteesys): print("hello") captured = capteesys.readouterr() assert captured.out == "hello\n" riTrrN) rrkrrrBdictrrrrrs r8 capteesysrst0%^^99CCDTUF$GDTNdO '  sB B c#K|jjjd}tt|d}|j ||j ||j|jyw)a'Enable bytes capturing of writes to ``sys.stdout`` and ``sys.stderr``. The captured output is made available via ``capsysbinary.readouterr()`` method calls, which return a ``(out, err)`` namedtuple. ``out`` and ``err`` will be ``bytes`` objects. Returns an instance of :class:`CaptureFixture[bytes] `. Example: .. code-block:: python def test_output(capsysbinary): print("hello") captured = capsysbinary.readouterr() assert captured.out == b"hello\n" riTrN) rrkrrr4rrrrrs r8 capsysbinaryr&sj&%^^99CCDTUF$%5w$OO '  rc#K|jjjd}tt|d}|j ||j ||j|jyw)aEnable text capturing of writes to file descriptors ``1`` and ``2``. The captured output is made available via ``capfd.readouterr()`` method calls, which return a ``(out, err)`` namedtuple. ``out`` and ``err`` will be ``text`` objects. Returns an instance of :class:`CaptureFixture[str] `. Example: .. code-block:: python def test_system_echo(capfd): os.system('echo "hello"') captured = capfd.readouterr() assert captured.out == "hello\n" riTrN) rrkrrrcrrrrrs r8capfdrBsi&%^^99CCDTUF$Y4HO '  rc#K|jjjd}tt|d}|j ||j ||j|jyw)a-Enable bytes capturing of writes to file descriptors ``1`` and ``2``. The captured output is made available via ``capfd.readouterr()`` method calls, which return a ``(out, err)`` namedtuple. ``out`` and ``err`` will be ``byte`` objects. Returns an instance of :class:`CaptureFixture[bytes] `. Example: .. code-block:: python def test_system_echo(capfdbinary): os.system('echo "hello"') captured = capfdbinary.readouterr() assert captured.out == b"hello\n" riTrN) rrkrrr\rrrrrs r8 capfdbinaryr^si(%^^99CCDTUF$_gNO '  r)r6rrrr)r[rrr)rurrr)r)rrzMultiCapture[str])rrrzGenerator[CaptureFixture[str]])rrrz Generator[CaptureFixture[bytes]])Sra __future__rr collectionscollections.abcrrrrrNrrQr#tempfiler typesr typingr r r rrrrrrrrtyping_extensionsr_pytest.configrr_pytest.config.argparsingr_pytest.deprecatedr_pytest.fixturesrr _pytest.nodesrrr_pytest.reportsr rr9rArErerzrOr|rrrABCrrrrr r>r4rBrFr\rc version_inforj namedtuplernrrlrrrrrrr}r:r8rs1" %$$ # " &!#,-$'#)56&  "41n $<<"""<"6  6$9$JJ`$#''76?$@xH5  C  2@ [(@ F!~e,!$$"\ K'\ ~+mE*+,; c";6w-  GFO  ?Q'76?Q'h >"x%x%vMWV_Mf  6  D  6  6  r: