bgVddlZddlZddlmZddlmZddlmZGddeZ dS)N)StringIO) TemporaryFile)compareceZdZdZdZdZddededefdZd Zd Z d Z d Z d Z e defdZddededefdZdS) OutputCapturea A context manager for capturing output to the :any:`sys.stdout` and :any:`sys.stderr` streams. :param separate: If ``True``, ``stdout`` and ``stderr`` will be captured separately and their expected values must be passed to :meth:`~OutputCapture.compare`. :param fd: If ``True``, the underlying file descriptors will be captured, rather than just the attributes on :mod:`sys`. This allows you to capture things like subprocesses that write directly to the file descriptors, but is more invasive, so only use it when you need it. :param strip_whitespace: When ``True``, which is the default, leading and training whitespace is trimmed from both the expected and actual values when comparing. .. note:: If ``separate`` is passed as ``True``, :attr:`OutputCapture.captured` will be an empty string. NFTseparatefdstrip_whitespacec0||_||_||_dSN)rr r )selfrr r s k/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/testfixtures/outputcapture.py__init__zOutputCapture.__init__#s   0c"|jr:t|_t|_t|_n9t |_t |_t |_||Sr )r routputstdoutstderrrenabler s r __enter__zOutputCapture.__enter__(sb 7 %'//DK'//DK'//DKK"**DK"**DK"**DK  rc.|dSr )disable)r argss r__exit__zOutputCapture.__exit__4s rc*|jri|jtjf|jtjffD]@\}}t j||t j |AdS|jt_|jt_dS)z,Disable the output capture if it is enabled.N) r original_stdoutsysroriginal_stderrrosdup2filenoclose)r originalcurrents rrzOutputCapture.disable7s 7 .%sz2%sz2& # #!''.."2"2333""""  # #-CJ-CJJJrc0|j|jrktjtj|_tjtj|_n"tj|_tj|_|j r|jrtj |jtjtj |jtjdS|jt_|jt_dS|jrtj |j tjtj |j tjdS|j xt_t_dS)z,Enable the output capture if it is disabled.N) rr r duprrr"rrrr!rrs rrzOutputCapture.enableEsx   'w 2')vcj.?.?.A.A'B'B$')vcj.?.?.A.A'B'B$$'*z$'*z$ = 6w ) **,,cj.?.?.A.ABBB **,,cj.?.?.A.ABBBBB![ ![ w 6 **,,cj.?.?.A.ABBB **,,cj.?.?.A.ABBBBB*.+5 SZZZrc|jr;|d|S|S)Nr)r seekreaddecodegetvalue)r streams r_readzOutputCapture._read\sE 7 % KKNNN;;=='')) )??$$ $rreturnc6||jS)z?A property containing any output that has been captured so far.)r.rrs rcapturedzOutputCapture.capturedcszz$+&&&rexpectedrrci}i}d||jfd|||jfd|||jffD]E\}}}|jr(|}|}||kr |||<|||<Ft |dkr[tt| dt| dt||dS)a Compare the captured output to that expected. If the output is not the same, an :class:`AssertionError` will be raised. :param expected: A string containing the expected combined output of ``stdout`` and ``stderr``. :param stdout: A string containing the expected output to ``stdout``. :param stderr: A string containing the expected output to ``stderr``. r1rrr)r3actualN) r1r.rrr striplenrtuplevalues) r r3rrexpected_mappingactual_mappingprefix _expectedr1s rrzOutputCapture.comparehs,Xt}564::dk#:#:;64::dk#:#:;, 2 2 'FIx $ ,%OO-- #>>++H$$+4 ()1v&  A % % U#3#:#:#<#<==a@ !6!6!8!899!< > > > >).AAAAAAr)FFT)r2r2r2)__name__ __module__ __qualname____doc__rrboolrrrrrr.propertystrr1rrrrr s,OO11141SW1111    . . .666.%%%'#'''X'BBB#BCBBBBBBrr) r riortempfilertestfixtures.comparisonrobjectrrFrrrKs """"""++++++{B{B{B{B{BF{B{B{B{B{Br