bg3UdZddlmZddlmZmZmZddlmZddl m Z ddl m Z ddl mZmZmZGd d eZejZe ed <ejZe ed <ejZe ed <ejZe ed<ejZe ed<dS)z1 Tools for helping to test Twisted applications. )pformat)UnionSequenceCallable)TestCase) NamedConstant)compare)globalLogPublisher formatEventLogLevelceZdZdZdeffdeeeeffdZ dZ dZ dZ dd d e fd ZddededefdZddefdZedefdZdS) LogCapturea5 A helper for capturing stuff logged using Twisted's loggers. :param fields: A sequence of field names that :meth:`~LogCapture.check` will use to build "actual" events to compare against the expected events passed in. If items are strings, they will be treated as keys info the Twisted logging event. If they are callable, they will be called with the event as their only parameter. If only one field is specified, "actual" events will just be that one field; otherwise they will be a tuple of the specified fields. log_levelfieldsc"g|_||_dSN)eventsr)selfrs e/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/testfixtures/twisted.py__init__zLogCapture.__init__s  c:|j|dSr)rappend)revents r__call__zLogCapture.__call__ s 5!!!!!rcBtj|_|gt_dS)zStart capturing.N)r _observersoriginal_observersrs rinstallzLogCapture.install#s"4"?)-%%%rc(|jt_dS)zStop capturing.N)rr rr s r uninstallzLogCapture.uninstall(s(,(?%%%rT) order_mattersr$c b g}|jD]R t fd|jD}t|dkr|d}||S|rt ||dSt |}g}g}|D]e} ||}|||A#t$r||YbwxYw|r?tdt|dt|dt|dS) aE Check captured events against those supplied. Please see the ``fields`` parameter to the constructor to see how "actual" events are built. :param order_matters: This defaults to ``True``. If ``False``, the order of expected logging versus actual logging will be ignored. c3vK|]3}t|r |n|V4dSr)callableget).0fieldrs r z#LogCapture.check..7s[!6!6 %2:%!VueiiPUFVFV!6!6!6!6!6!6rr r)expectedactualz.entries not as expected: expected and found: z expected but not found: z other entries: N) rtuplerlenrr listindexpop ValueErrorAssertionErrorr) rr$r,r- actual_eventmatched unmatchedentryr1rs @rcheckzLogCapture.check,s[ ( (E !6!6!6!6)-!6!6!666L<  A%%+A MM, ' ' ' '  O Xf 5 5 5 5 5 5H~~HGI 8 88$NN511ENN8<<#6#67777",,,$$U+++++, O$n W%%%%wx'8'8'8'8'):L:L:L &NOOO O Os C  C+*C+valuer,r1 attributec t|tt|j|d|dS)ai Check the string representation of an attribute of a logged ``Failure`` is as expected. :param expected: The expected string representation. :param index: The index into :attr:`events` where the failure should have been logged. :param attribute: The attribute of the failure of which to find the string representation. log_failure)r-N)r strgetattrr)rr,r1r<s rcheck_failure_textzLogCapture.check_failure_textQs< WT[-? -NPY%Z%Z![![\\\\\\rr start_indexc\|j|dD]}|d}|r|dS)z A debugging tool that raises the first failure encountered in captured logging. :param start_index: The index into :attr:`events` from where to start looking for failures. Nr>)rr()rrBrfailures rraise_logged_failurezLogCapture.raise_logged_failure[sK [.  Eii ..G     rtestcasec r|di|}|||j|S)a] Instantiate, install and add a cleanup for a :class:`LogCapture`. :param testcase: This must be an instance of :class:`twisted.trial.unittest.TestCase`. :param kw: Any other parameters are passed directly to the :class:`LogCapture` constructor. :return: The :class:`LogCapture` instantiated by this method. )r! addCleanupr#)clsrFkwcaptures rmakezLogCapture.makefsA#))))G-...rN)r:r;)r)__name__ __module__ __qualname____doc__r rrr?rrrr!r#boolr9intrArE classmethodrrMrHrrrrs7  BMk@[xc8m(<= """/// @@@6:#O#O#Od#O#O#O#OJ]]3]s]C]]]]       H   [   rrDEBUGINFOWARNERRORCRITICALN)rQpprintrtypingrrrunittestr constantlyrr twisted.loggerr r r objectrdebugrU__annotations__inforVwarnrWerrorrXcriticalrYrHrrrgs0,,,,,,,,,,$$$$$$DDDDDDDDDDddddddddP ~}%%%mm###mm###~}%%%"+-+++++r