bgdZddlZddlZddlZddlZddlmZddlmZddlmZddlm Z ddlm Z ddlm Z dd lm Z dd l mZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddl m!Z!ddl"m#Z#ddl"m$Z$ddl"m%Z%ddl"m&Z&ddl"m'Z'ddl(m)Z)ddl*m+Z+dd l,m-Z-dd!l,m.Z.dd"l/m0Z0dd#l1m2Z2dd$l3m4Z4erej5e Z6dd%l7m8Z8nej5Z6d&Z9d'Z:ej;d(Z<e2d)Z=e2ee>eej fZ?d*e>d+e>fd,Z@Gd-d.ejAZBGd/d0eBZCGd1d2ejDZEd3e$d4e>fd5ZFd6e)d+dfd7ZGed8ejH9ZIGd:d;ZJGd<d)e6ZKe!Gd=d>ZLe-d?e.d+eeLddffd@ZMd3e$dAe>d+eeNfdBZOe&dCDd3e$d+dfdEZPGdFdGZQGdHdIejRZSGdJdKe6ZTGdLdMejUZVdS)Nz!Access and control log capturing.N)contextmanager) nullcontext)datetime) timedelta)timezone)StringIO) LogRecord)Path) AbstractSet)Dict) Generator)List)Mapping)Optional)Tuple) TYPE_CHECKING)TypeVar)Union)nodes)TerminalWriter)CaptureManager)final) _strtobool)Config)create_terminal_writer)hookimpl) UsageError)Parser)check_ispytest)fixture)FixtureRequest)Session)StashKey)TerminalReporter)Literalz<%(levelname)-8s %(name)s:%(filename)s:%(lineno)d %(message)sz%H:%M:%Sz \x1b\[[\d;]+mLogCaptureHandlertextreturnc8td|S)N)_ANSI_ESCAPE_SEQsub)r's `/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/_pytest/logging.py_remove_ansi_escape_sequencesr.8s   D ) ))c.eZdZdZddedeffd ZxZS)DatetimeFormatterzA logging formatter which formats record with :func:`datetime.datetime.strftime` formatter instead of :func:`time.strftime` in case of microseconds in format string. Nrecordr(cV|rd|vr||j}tt|j|j}t |ddt|jdz|d}| |St ||S)Nz%f)secondsri) microsecondtzinfo) convertercreatedrr tm_gmtofftm_zonerroundmsecsstrftimesuper formatTime)selfr2datefmtcttzdt __class__s r-r@zDatetimeFormatter.formatTimeBs  (tw//B)BL9992:FFB2ac7flT6I0J0JSUVVVB;;w'' 'ww!!&'222r/N)__name__ __module__ __qualname____doc__r strr@ __classcell__rFs@r-r1r1<sZ 3 3 3S 3 3 3 3 3 3 3 3 3 3r/r1c*eZdZUdZejdhejddhejdhejdhej dhej dhej e iZ eeeefed<ejdZd ed d ffd Zd eded d fdZdejd effd ZxZS)ColoredLevelFormatterzfA logging formatter which colorizes the %(levelname)..s part of the log format passed to __init__.redboldyellowgreenpurpleLOGLEVEL_COLOROPTSz$%\(levelname\)([+-.]?\d*(?:\.\d+)?s)terminalwriterr(Nctj|i|||_|jj|_i|_|jD]\}}|j |g|RdSrG) r?__init___terminalwriter_style_fmt _original_fmt_level_to_fmt_mappingrVitemsadd_color_level)rArWargskwargslevel color_optsrFs r-rYzColoredLevelFormatter.__init__]s$)&)))-![-57"!%!8!>!>!@!@ 5 5 E: D  4 4 4 4 4 4 5 5r/rcrdcF|jJ|j|j}|sdS|}|dt j|iz}d|D}|jj|fi|}|j||j|j |<dS)aAdd or update color opts for a log level. :param level: Log level to apply a style to, e.g. ``logging.INFO``. :param color_opts: ANSI escape sequence color options. Capitalized colors indicates background color, i.e. ``'green', 'Yellow', 'bold'`` will give bold green text on yellow background. .. warning:: This is an experimental API. N levelnameci|]}|dS)T).0names r- z9ColoredLevelFormatter.add_color_level..}s:::td:::r/) r\LEVELNAME_FMT_REGEXsearchgrouplogging getLevelNamerZmarkupr,r^)rArcrdlevelname_fmt_match levelname_fmtformatted_levelname color_kwargscolorized_formatted_levelnames r-r`z%ColoredLevelFormatter.add_color_levelfsy$$$"6==diHH"  F+1133 +{G&W.&3&&&&&&&&&&r/rPceZdZdZdedeeeedfddffd Ze deeeedfdefdZ d e j defd Z xZS) PercentStyleMultilinezA logging style with special support for multiline messages. If the message of a record consists of multiple lines, this style formats the message as if each line were logged separately. r{ auto_indentNr(c~t||||_dSrG)r?rY_get_auto_indent _auto_indent)rAr{rrFs r-rYzPercentStyleMultiline.__init__s7  11+>>r/auto_indent_optionc>|dSt|tr|rdSdSt|trt|St|trD t|S#t$rYnwxYw t |rdSn#t$rYdSwxYwdS)aDetermine the current auto indentation setting. Specify auto indent behavior (on/off/fixed) by passing in extra={"auto_indent": [value]} to the call to logging.log() or using a --log-auto-indent [value] command line or the log_auto_indent [value] config option. Default behavior is auto-indent off. Using the string "True" or "on" or the boolean True as the value turns auto indent on, using the string "False" or "off" or the boolean False or the int 0 turns it off, and specifying a positive integer fixes the indentation position to the value specified. Any other values for the option are invalid, and will silently be converted to the default. :param None|bool|int|str auto_indent_option: User specified option for indentation from command line, config or extra kwarg. Accepts int, bool or str. str option accepts the same range of values as boolean config options, as well as positive integers represented in str form. :returns: Indentation value, which can be -1 (automatically determine indentation) or 0 (auto-indent turned off) or >0 (explicitly set indentation position). Nr) isinstanceboolrrL ValueErrorr)rs r-rz&PercentStyleMultiline._get_auto_indentsB  %1 *D 1 1 ! rq *C 0 0 )** * *C 0 0  -...     0112   qq qs$A)) A65A6:B BBr2cd|jvrt|dr||j}n|j}|r|j}|ji|jd|diz}|dkr)t| |d}n|}||d<dd|zz |S|j|jzS)N rmessager ) rhasattrrrr splitlinesr\__dict__r.findjoin)rAr2rlines formatted indentations r-rzzPercentStyleMultiline.formats 6> ! !v}-- 0"33F4FGG "/  >1133 I(P6?(PIuQx(P(PP ??"? "J"J"O"Oa##KK #.K$as[0066u===y6?**r/)rHrIrJrKrLrrrrY staticmethodrror rzrMrNs@r-rrs ?C?eCdD4H.I?d??????4U3T43G-H4S444\4l+W.+3++++++++r/rconfignamesct|D]4}||}|||}|r|cS5dSrG) getoptiongetini)rrrjrets r-get_option_inirsZt$$ ;--%%C  JJJ  r/parsercdd.fd }|ddddd|d d td |d dtd dddd|dddd |dddd |dddd |dddd |dd dd! |d"d#td |d$d%td |d&d'dd( d)d*gd+d,-dS)/z%Add options to control log capturing.roNc`|||d|zj|fd|i|dS)NzDefault value for defaulttypehelpdest)addini addoption)optionrrrrbrnrs r-add_option_iniz(pytest_addoption..add_option_inisT '3G&3P     44T4V44444r/z --log-level log_levelLEVELzLevel of messages to catch/display. Not set by default, so it depends on the root/parent log handler's effective level, where it is "WARNING" by default.)rrmetavarrz --log-format log_formatz%Log format used by the logging module)rrrz--log-date-formatlog_date_formatz*Log date format used by the logging modulelog_cliFrzAEnable log display during test run (also known as "live logging")r--log-cli-level log_cli_levelzCLI logging levelz--log-cli-formatlog_cli_formatz--log-cli-date-formatlog_cli_date_formatz --log-filelog_filez.Path to a file when logging will be written toz--log-file-levellog_file_levelzLog file logging levelz--log-file-formatlog_file_formatz--log-file-date-formatlog_file_date_formatz--log-auto-indentlog_auto_indentzfAuto-indent multiline messages passed to the logging module. Accepts true|on, false|off or an integer.z --log-disableappendlogger_disablez7Disable a logger by name. Can be passed multiple times.)actionrrr)NN)getgroupDEFAULT_LOG_FORMATDEFAULT_LOG_DATE_FORMATrr)rrrns` @r-pytest_addoptionrsH OOI & &E5555555 N  B    N " 4  N ' 9   MM  P  NDWN  4  N " 9  N  =  N  %  N " 4  N #' 9  N  u   OO  F r/ _HandlerType)boundcDeZdZdZdZd dedeeddfdZdZ d Z dS) catching_logszCContext manager that prepares the whole logging machinery properly.)handlerrc orig_levelNrrcr(c"||_||_dSrG)rrc)rArrcs r-rYzcatching_logs.__init__Ts  r/c6tj}|j|j|j||j|j9|j|_|t|j|j|jSrG)ro getLoggerrcrsetLevel addHandlerrmin)rA root_loggers r- __enter__zcatching_logs.__enter__Xs')) : ! L ! !$* - - -t|,,, : !)/DO  T_dj!A!A B B B|r/ctj}|j||j||jdSrG)rorrcrr removeHandlerr)rArvalue tracebackrs r-__exit__zcatching_logs.__exit__bsJ')) : !   1 1 1!!$,/////r/rG) rHrIrJrK __slots__rrrrYrrrhr/r-rrOsoMM2I Xc]d00000r/rcleZdZdZd fd Zdejddffd Zd dZd dZ dejddfd Z xZ S) r&z;A logging handler that stores log records and the log text.r(Ncpttg|_dS)zCreate a new log handler.N)r?rYrrecords)rArFs r-rYzLogCaptureHandler.__init__ls* $$$02 r/r2c~|j|t|dS)z;Keep the log records in a list in addition to the log text.N)rrr?emit)rAr2rFs r-rzLogCaptureHandler.emitqs5 F###  Vr/c:g|_t|_dSrG)rrstreamrAs r-resetzLogCaptureHandler.resetvs jj r/c^|jt|_dSrG)rclearrrrs r-rzLogCaptureHandler.clearzs% jj r/c tjrdSrG)roraiseExceptionsrAr2s r- handleErrorzLogCaptureHandler.handleError~s  "     r/r(N) rHrIrJrKrYror rrrrrMrNs@r-r&r&isEE333333 7, !!!!!!!!'"3r/c eZdZdZdddejdeddfdZdd Ze de fd Z d d de e jfd Ze defdZe de e jfdZe de eeeeffdZe de efdZddZdeeefde jdefdZddeeefdeeddfdZe ddeeefdeededfdZdS)LogCaptureFixturez-Provides access and control of log capturing.F _ispytestitemrr(Nc\t|||_d|_i|_d|_dSrG)r_item_initial_handler_level_initial_logger_levels_initial_disabled_logging_level)rArrs r-rYzLogCaptureFixture.__init__s5y!!! 59#@B#>B,,,r/c4|j|j|j|jD].\}}t j|}||/|j"t j|jd|_dSdS)zFinalize the fixture. This restores the log levels and the disabled logging levels changed by :meth:`set_level`. N) rrrrr_rorrdisable)rA logger_namercloggers r- _finalizezLogCaptureFixture._finalizes  & 2 L ! !$"= > > >"&"="C"C"E"E # # K&{33F OOE " " " "  / ; OD@ A A A37D 0 0 0 < ;r/c0|jjtS)z,Get the logging handler used by the fixture.)rstashcaplog_handler_keyrs r-rzLogCaptureFixture.handlersz 233r/whenz$Literal['setup', 'call', 'teardown']cX|jjt|gS)a5Get the logging records for one of the possible test phases. :param when: Which test phase to obtain the records from. Valid values are: "setup", "call" and "teardown". :returns: The list of captured records at the given stage. .. versionadded:: 3.4 )rrcaplog_records_keyrxrArs r- get_recordszLogCaptureFixture.get_recordss%z 2377bAAAr/cXt|jjS)zThe formatted log text.)r.rrgetvaluers r-r'zLogCaptureFixture.texts#-T\-@-I-I-K-KLLLr/c|jjS)zThe list of log records.)rrrs r-rzLogCaptureFixture.recordss|##r/c$d|jDS)zA list of a stripped down version of log records intended for use in assertion comparison. The format of the tuple is: (logger_name, log_level, message) cPg|]#}|j|j|f$Srh)rjry getMessagerirs r- z3LogCaptureFixture.record_tuples..s+JJJALLNN3JJJr/rrs r- record_tupleszLogCaptureFixture.record_tuplessKJT\JJJJr/c$d|jDS)aA list of format-interpolated log messages. Unlike 'records', which contains the format string and parameters for interpolation, log messages in this list are all interpolated. Unlike 'text', which contains the output from the handler, log messages in this list are unadorned with levels, timestamps, etc, making exact comparisons more reliable. Note that traceback or stack info (from :func:`logging.exception` or the `exc_info` or `stack_info` arguments to the logging functions) is not included, as this is added by the formatter in the handler. .. versionadded:: 3.7 c6g|]}|Srh)r r s r-r z.LogCaptureFixture.messages..s 5551 555r/rrs r-messageszLogCaptureFixture.messagess"65 5555r/c8|jdS)z8Reset the list of log records and the captured log text.N)rrrs r-rzLogCaptureFixture.clears r/rc logger_objcd|jj}t|trt j|}t|t st jtjnF||s1t|dz tj}t j||S)aPEnable the desired logging level if the global level was disabled via ``logging.disabled``. Only enables logging levels greater than or equal to the requested ``level``. Does nothing if the desired ``level`` wasn't disabled. :param level: The logger level caplog should capture. All logging is enabled if a non-standard logging level string is supplied. Valid level strings are in :data:`logging._nameToLevel`. :param logger_obj: The logger object to check. :return: The original disabled logging level. ) managerrrrLrorprr isEnabledFormax)rArcroriginal_disable_level disable_levels r-_force_enable_loggingz'LogCaptureFixture._force_enable_loggings"'1&8&@ eS ! ! 0(//E%%% + OGN + + + +((// +  GN;;M OM * * *%%r/rcHtj|}|j||j|||j|jj|_|j||||}|j ||_ dSdS)aSet the threshold level of a logger for the duration of a test. Logging messages which are less severe than this level will not be captured. .. versionchanged:: 3.4 The levels of the loggers changed by this function will be restored to their initial values at the end of the test. Will enable the requested logging level if it was disabled via :meth:`logging.disable`. :param level: The level. :param logger: The logger to update. If not given, the root logger. N) rorr setdefaultrcrrrrr)rArcrrinitial_disabled_logging_levels r- set_levelzLogCaptureFixture.set_levels&v..  #..vz7GHHHE"""  & .*.,*rrG) rHrIrJrKrNoderrYrpropertyr&rrror rrLr'rrrrrrrLoggerrrr rr r$rhr/r-rrsk77>CCCCUZCtCCCCC8888 4*444X4 B: B g  B B B BMcMMMXM$g/0$$$X$KtE#sC-$89KKKXK6$s)666X6$ &38_ &29. &  & & & &DRRuS#XR RQURRRR2>B4438_4.6sm4 # $444^444r/rrequestc#fKt|jd}|V|dS)aAccess and control log capturing. Captured logs are available through the following properties/methods:: * caplog.messages -> list of format-interpolated log messages * caplog.text -> string containing formatted log output * caplog.records -> list of logging.LogRecord instances * caplog.record_tuples -> list of (logger_name, level, message) tuples * caplog.clear() -> clear captured records and formatted log output string TrN)rnoder)r(results r-caplogr,9s=w|t < < >>7 O[    " " = & 4 ? ?@R S S $2==>NOOO**;_MM  $;#<#N) r is_absoluterDrootpathparentexistsmkdiropenrR setStreamclose)rArcfpathr old_streams r- set_log_pathzLoggingPlugin.set_log_pathsU   "" 2L)E1E|""$$ < L  d  ; ; ;$)::3:#I#I*44V<<            r/c|jddup|jd}|sdS|jjd}|dSdS)z'Return whether live logging is enabled.rNrFrAT)rDrrr6rT)rAenabledr[s r-rSzLoggingPlugin._log_cli_enabledsx,((   8,,Y77  5 L6AABTUU  $5tr/T) hookwrappertryfirstr!c#K|jdt|j|j5t|j|j5dVdddn #1swxYwYddddS#1swxYwYdS)N sessionstartrcrVset_whenrrrRrrs r-pytest_sessionstartz!LoggingPlugin.pytest_sessionstarts %%n555 4/t7I J J J  t4D ,  EEE F  " " ,t|'='=i'H'H1'L'L*+DL  ' 4/t7I J J J  t4D/.X$ ' i@P6Q     ///X/333X366369EU;V6666&X$44 BR8S444 4X$3 3yAQ7R333 3 X$+EJ+9EU;V+++ +000X0X$...i0@&A/.&&&X&&&r/r8c,eZdZdZdejddfdZdS)rQz)A logging FileHandler with pytest tweaks.r2r(NcdSrGrhrs r-rz_FileHandler.handleErrorK r/)rHrIrJrKror rrhr/r-rQrQHs?33 '"3       r/rQceZdZUdZdZeed<dedeeddffd Z ddZ d ee ddfd Z d e jddffd Zd e jddfd ZxZS)rUaA logging StreamHandler used by the live logging feature: it will write a newline before the first log message in each test. During live logging we must also explicitly disable stdout/stderr capturing otherwise it will get captured and won't appear in the terminal. Nrr[r\r(ct|||_||dd|_dS)N)rF)r?rYr\rrz_test_outcome_written)rAr[r\rFs r-rYz"_LiveLoggingStreamHandler.__init__]sV  1222.  d%*"""r/cd|_dS)zBReset the handler; should be called before the start of each test.FN)_first_record_emittedrs r-rz_LiveLoggingStreamHandler.reseths%*"""r/rc@||_d|_|dkr d|_dSdS)z7Prepare for the given test phase (setup/call/teardown).FrN)_when_section_name_shownrrs r-rzz"_LiveLoggingStreamHandler.set_whenls/ #( 7??).D & & & ?r/r2c|jr|jn t}|5|js"|jdd|_n1|jdvr(|js!d|_|jd|js3|jr,|j d|jzddd|_t |ddddS#1swxYwYdS)NrT)rrz live log -)seprR) r\global_and_fixture_disabledrrrwriterrrsectionr?r)rAr2 ctx_managerrFs r-rz_LiveLoggingStreamHandler.emitssU# D < < > > >   ! !- , !!$'''-1**5551,15D.K%%d++++ 0  0 ##K$*$<#D#QQQ+/( GGLL  ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !sB6C55C9<C9cdSrGrhrs r-rz%_LiveLoggingStreamHandler.handleErrorrr/r)rHrIrJrKrr$rrrrYrrLrzror rrrMrNs@r-rUrUPs  $F ### ++ +".1 +  + + + + + +++++/Xc]/t////!7,!!!!!!!& '"3         r/rUcDeZdZdZd dZdeddfdZdejddfdZ dS) rWz5A logging handler used when live logging is disabled.r(NcdSrGrhrs r-rz_LiveLoggingNullHandler.reset r/rcdSrGrhrs r-rzz _LiveLoggingNullHandler.set_whenrr/r2cdSrGrhrs r-rz#_LiveLoggingNullHandler.handleErrorrr/r) rHrIrJrKrrLrzror rrhr/r-rWrWsu??     S T     '"3       r/rW)WrKiororJr contextlibrrrrrrr pathlibr typingr r r rrrrrrr_pytestr _pytest._ior_pytest.capturer_pytest.compatr_pytest.configrrrrr_pytest.config.argparsingr_pytest.deprecatedr_pytest.fixturesr r! _pytest.mainr" _pytest.stashr#_pytest.terminalr$ StreamHandlerlogging_StreamHandlertyping_extensionsr%rrrr+rrLrr. Formatterr1rP PercentStylerrrHandlerrrr&rr,rr3r9r8 FileHandlerrQrU NullHandlerrWrhr/r-rs.''  %%%%%%"""""" &&&&&&****** %%%%%%!!!!!!111111######%%%%%%,,,,,,------$$$$$$++++++ """"""------2#1(;)))))))#1S$2:.//2X1244AXd3W->(?#?@ACC******33333)333$:&:&:&:&:&-:&:&:&zW+W+W+W+W+G0W+W+W+t63ZVZZZZZzw~W_=== 000000004-<n4n4n4n4n4n4n4n4b  N y1BD$1N'O      fchsm0 $KVKKKKK^&^&^&^&^&^&^&^&B     7&   8 8 8 8 8 58 8 8 v      g1      r/