Ϫf!"HdZddlmZddlZddlZddlmZddlm Z m Z ddlm Z m Z m Z mZddlmZmZmZddlmZdd lmZdd lmZdd lmZdd lmZd dlmZmZd dl m!Z!d dl"m#Z#ddZ$GddZ%GddejLZ'ddZ(GddejRZ*y)z+ Test cases for L{twisted.logger._format}. ) annotationsN) getsourcefile)BytesIO TextIOWrapper) Formatter LogRecord StreamHandler getLogger)ListOptionalTuple)BrokenMethodImplementation) verifyObject) currentframe)Failure)unittest) ILogObserverLogEvent)LogLevel)STDLibLogObserverctd}ttj|jd|j dzfS)z Retrive the file name and line number immediately after where this function is called. @return: the file name and line number __name__)rrsysmodules f_globalsf_lineno)callers A/usr/lib/python3/dist-packages/twisted/logger/test/test_stdlib.pynextLiner!s?!_Fckk&"2"2:">?@! c(eZdZdZddZddZddZy)StdlibLoggingContainerzF Continer for a test configuration of stdlib logging objects. ctd|_|jj|_|jj t j t|_|jj|jt\|_ |_ |jj|jy)N) r rootLoggergetEffectiveLevel originalLevelsetLevel py_loggingDEBUGBufferedHandlerbufferedHandler addHandlerhandlerAndBytesIO streamHandleroutputselfs r __init__zStdlibLoggingContainer.__init__.s#B-!__>>@   !1!12.0 ""4#7#78*;*='DK ""4#5#56r"cJ|jj|j|jj|j|jj|j |j j |jj y)z# Close the logger. N)r'r*r) removeHandlerr.r1closer2r3s r r8zStdlibLoggingContainer.close:sn   !3!34 %%d&:&:; %%d&8&89   " r"cT|jjjdS)zd Get the output to the underlying stream as text. @return: the output text utf-8)r2getvaluedecoder3s r outputAsTextz#StdlibLoggingContainer.outputAsTextDs" {{##%,,W55r"NreturnNone)r?str)r __module__ __qualname____doc__r5r8r=r"r r$r$)s 76r"r$cheZdZdZddZddZddZddZddZddZ ddZ dd Z dd Z dd Z dd Zy )STDLibLogObserverTestsz) Tests for L{STDLibLogObserver}. ct} tt|y#t$r}|j |Yd}~yd}~wwxYw)z= L{STDLibLogObserver} is an L{ILogObserver}. N)rrrrfail)r4observeres r test_interfacez%STDLibLogObserverTests.test_interfaceRs8%&  x 0)  IIaLL s A<AcPt}|j|j|S)zj Create a logging object we can use to test with. @return: a stdlib-style logger )r$ addCleanupr8)r4loggers r py_loggerz STDLibLogObserverTests.py_logger\s! ()  % r"c|j}ttjdz}|D] }|| |jj|j fS)z Send one or more events to Python's logging module, and capture the emitted L{LogRecord}s and output stream as a string. @param events: events @return: a tuple: (records, output) r) stackDepth)rPrdefaultStackDepthr.recordsr=)r4eventsplrJevents r logEventzSTDLibLogObserverTests.logEventfse^^ $)::  E UO !!))2??+<<.failing_func Er"Hi mommerr log_failurerin failing_funcZeroDivisionErrorNr>)rrrrXr[r\assertInr4rfailurerWrTr2s r test_failurez#STDLibLogObserverTests.test_failures   NdH--. Wq) h' '0 )62! iG sBBBcTd d} |tdd}|j |\}}|j t |d|jd||jd||jd|y#t$rt}|jYwxYw) z A cleaned Failure object has a fake traceback object; make sure that logging such a failure still results in the exception details being logged. cddz yrrErEr"r rz@STDLibLogObserverTests.test_cleanedFailure..failing_funcrr"rrrrrrNr>)rr cleanFailurerrXr[r\rrs r test_cleanedFailurez*STDLibLogObserverTests.test_cleanedFailures  # N dH--. Wq) h' '0 )62! #iG  " #sB#B'&B'Nr>)r?r$)rUrr?zTuple[List[LogRecord], str])rrBrCrDrLrPrXr_rur}rrrrrrEr"r rGrGMsA=,5!JF /" .J23*3r"rGct}tj}t|dd}t |}t |}|j |||fS)z Construct a 2-tuple of C{(StreamHandler, BytesIO)} for testing interaction with the 'logging' module. @return: handler and io object r: )encodingnewline)rr+ BASIC_FORMATrrr setFormatter)r2templatestream formatterhandlers r r0r0sPYF&&H 6GT BF(#IF#G # F?r"c eZdZdZddZddZy)r-zN A L{py_logging.Handler} that remembers all logged records in a list. cPtjj|g|_y)z5 Initialize this L{BufferedHandler}. N)r+Handlerr5rTr3s r r5zBufferedHandler.__init__s ##D)(* r"c:|jj|y)z& Remember the record. N)rTrn)r4records r emitzBufferedHandler.emit!s F#r"Nr>)rrr?r@)rrBrCrDr5rrEr"r r-r-s+$r"r-)r?zTuple[Optional[str], int])r?z,tuple[StreamHandler[TextIOWrapper], BytesIO])+rD __future__rloggingr+rinspectriorrrrr r typingr r r zope.interface.exceptionsrzope.interface.verifyrtwisted.python.compatrtwisted.python.failurer twisted.trialr _interfacesrr_levelsr_stdlibrr!r$TestCaserGr0rr-rEr"r rs{# !%BB((@..*"0' !6!6Hu3X..u3p  $j(($r"