
    9[g4                    2   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl	Z	dd	l	m
Z
 ddlZdd
lmZ ddlZddlmZ ddlZddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl m!Z! ddl"m#Z# ddl$m%Z% ddl$m&Z& ddl$m'Z' ddl$m(Z( ddl$m)Z) ddl*m+Z+ dd l,m-Z- dd!l.m/Z/ dd"l.m0Z0 dd#l1m2Z2 dd$l3m4Z4 dd%l5m6Z6 erejn                  e
   Z8nejn                  Z8d&Z9d'Z: ejv                  d(      Z< e4d)          Z= e4ee>eej                     f             Z?dGd*Z@ G d+ d,ej                        ZB G d- d.eB      ZC G d/ d0ej                        ZEdHd1ZFdId2ZG ed3ej                  4      ZI G d5 d6eeI         ZJ G d7 d)e8      ZKe G d8 d9             ZLe/dJd:       ZMdKd;ZN e(d<=      dLd>       ZO G d? d@      ZP G dA dBej                        ZR G dC dDe8      ZS G dE dFej                        ZUy)Mz!Access and control log capturing.    )annotations)contextmanager)nullcontext)datetime)	timedelta)timezoneN)StringIO)	LogRecord)Path)TracebackType)AbstractSet)Dict)final)	Generator)Generic)List)Literal)Mapping)TYPE_CHECKING)TypeVar)nodes)TerminalWriter)CaptureManager)
_strtobool)Config)create_terminal_writer)hookimpl)
UsageError)Parser)check_ispytest)fixture)FixtureRequest)Session)StashKey)TerminalReporterz<%(levelname)-8s %(name)s:%(filename)s:%(lineno)d %(message)sz%H:%M:%Sz\x1b\[[\d;]+mLogCaptureHandlerc                .    t         j                  d|       S )N )_ANSI_ESCAPE_SEQsub)texts    J/var/www/html/bid-api/venv/lib/python3.12/site-packages/_pytest/logging.py_remove_ansi_escape_sequencesr-   ;   s    D))    c                  &     e Zd ZdZdd fdZ xZS )DatetimeFormatterzA logging formatter which formats record with
    :func:`datetime.datetime.strftime` formatter instead of
    :func:`time.strftime` in case of microseconds in format string.
    c                &   |rd|v r{| j                  |j                        }t        t        |j                        |j
                        }t        |dd t        |j                  dz        |d}|j                  |      S t        | -  ||      S )Nz%f)secondsr      i  )microsecondtzinfo)	convertercreatedr   r   	tm_gmtofftm_zoner   intmsecsstrftimesuper
formatTime)selfrecorddatefmtcttzdt	__class__s         r,   r>   zDatetimeFormatter.formatTimeE   s}    tw/B)BLL92::FB 2a7FLL44G0HQSTB;;w''w!&'22r.   N)r@   r
   rA   
str | Nonereturnstr)__name__
__module____qualname____doc__r>   __classcell__rE   s   @r,   r0   r0   ?   s    

3 
3r.   r0   c                  ,    e Zd ZU dZej
                  dhej                  ddhej                  dhej                  dhej                  dhej                  dhej                   e       iZded<    ej                   d	      Zd fd
ZddZd fdZ xZS )ColoredLevelFormatterzfA logging formatter which colorizes the %(levelname)..s part of the
    log format passed to __init__.redboldyellowgreenpurplezMapping[int, AbstractSet[str]]LOGLEVEL_COLOROPTSz$%\(levelname\)([+-.]?\d*(?:\.\d+)?s)c                    t        |   |i | || _        | j                  j                  | _        i | _        | j                  j                         D ]  \  }} | j                  |g|   y rF   )
r=   __init___terminalwriter_style_fmt_original_fmt_level_to_fmt_mappingrW   itemsadd_color_level)r?   terminalwriterargskwargslevel
color_optsrE   s         r,   rY   zColoredLevelFormatter.__init__a   sk    $)&)-![[--57"!%!8!8!>!>!@E: D  44 "Ar.   c                   | j                   J | j                  j                  | j                         }|sy|j                         }|dt	        j
                  |      iz  }|D ci c]  }|d }} | j                  j                  |fi |}| j                  j                  || j                         | j                  |<   yc c}w )a  Add 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	levelnameT)
r\   LEVELNAME_FMT_REGEXsearchgrouplogginggetLevelNamerZ   markupr*   r^   )	r?   rd   re   levelname_fmt_matchlevelname_fmtformatted_levelnamenamecolor_kwargscolorized_formatted_levelnames	            r,   r`   z%ColoredLevelFormatter.add_color_levelj   s     yy$$$"66==diiH"+113+{G<P<PQV<W.XX 0::ztd
z:(C(<(<(C(C)
#/)
% -1,D,D,H,H)499-
""5)	 ;s   %
Cc                    | j                   j                  |j                  | j                        }|| j                  _        t        |   |      S rF   )r^   getlevelnor]   r[   r\   r=   format)r?   r@   fmtrE   s      r,   rw   zColoredLevelFormatter.format   s@    ((,,V^^T=O=OPw~f%%r.   )ra   r   rH   None)rd   r:   re   rI   rH   ry   r@   logging.LogRecordrH   rI   )rJ   rK   rL   rM   rk   CRITICALERRORWARNINGWARNINFODEBUGNOTSETsetrW   __annotations__recompilerh   rY   r`   rw   rN   rO   s   @r,   rQ   rQ   R   s    & 	5'v(xjwiz:6  %"**%LM5
<& &r.   rQ   c                  >     e Zd ZdZd fdZedd       ZddZ xZS )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.
    c                P    t         |   |       | j                  |      | _        y rF   )r=   rY   _get_auto_indent_auto_indent)r?   rx   auto_indentrE   s      r,   rY   zPercentStyleMultiline.__init__   s#     11+>r.   c                    | yt        | t              r| ryyt        | t              rt        |       S t        | t              r	 t        |       S y# t        $ r Y nw xY w	 t        |       ry	 y# t        $ r Y yw xY w)a  Determine 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).
        r   )
isinstanceboolr:   rI   
ValueErrorr   )auto_indent_options    r,   r   z&PercentStyleMultiline._get_auto_indent   s    @ %*D1!*C0)***C0-..   01 2
   s$   
A 	AA A. .	A:9A:c                   d|j                   v rt        |d      r| j                  |j                        }n| j                  }|r}|j                   j                         }| j                  i |j                  d|d   iz  }|dk  rt        |      j                  |d         }n|}||d<   dd|z  z   j                  |      S | j                  |j                  z  S )N
r   messager    )r   hasattrr   r   r   
splitlinesr\   __dict__r-   findjoin)r?   r@   r   lines	formattedindentations         r,   rw   zPercentStyleMultiline.format   s    6>>!v}-"33F4F4FG"//113 II(P6??(PIuQx(PP	?"?	"J"O"Oa#K
 #.K$as[0066u==yy6??**r.   )rx   rI   r   int | str | bool | NonerH   ry   )r   r   rH   r:   rz   )	rJ   rK   rL   rM   rY   staticmethodr   rw   rN   rO   s   @r,   r   r      s'    ? 3 3j+r.   r   c                f    |D ],  }| j                  |      }|| j                  |      }|s*|c S  y rF   )	getoptiongetini)confignamesrq   rets       r,   get_option_inir      s7    t$;--%CJ r.   c                     j                  d      d4 fd	} |ddddd        |d	d
t        d        |ddt        d        j                  dddd        |dddd        |dddd        |dddd        |dddd        |dd d!d!d"gd#$        |d%d&dd'        |d(d)dd        |d*d+dd        |d,d-dd.       j	                  d/d0g d1d23       y)5z%Add options to control log capturing.rk   Nc                `    j                  |||d| z           j                  | fd|i| y )NzDefault value for defaulttypehelpdest)addini	addoption)optionr   r   r   rc   rj   parsers        r,   add_option_iniz(pytest_addoption.<locals>.add_option_ini   s=    '3G&3P 	 	
 	4T4V4r.   z--log-level	log_levelLEVELzLevel 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.)r   r   metavarr   z--log-format
log_formatz%Log format used by the logging module)r   r   r   z--log-date-formatlog_date_formatz*Log date format used by the logging modulelog_cliFr   zAEnable log display during test run (also known as "live logging")r   --log-cli-levellog_cli_levelzCLI logging levelz--log-cli-formatlog_cli_formatz--log-cli-date-formatlog_cli_date_formatz
--log-filelog_filez.Path to a file when logging will be written toz--log-file-modelog_file_modewazLog file open mode)r   r   choicesr   z--log-file-levellog_file_levelzLog file logging levelz--log-file-formatlog_file_formatz--log-file-date-formatlog_file_date_formatz--log-auto-indentlog_auto_indentzfAuto-indent multiline messages passed to the logging module. Accepts true|on, false|off or an integer.z--log-disableappendlogger_disablez7Disable a logger by name. Can be passed multiple times.)actionr   r   r   )NN)getgroupDEFAULT_LOG_FORMATDEFAULT_LOG_DATE_FORMATr   r   )r   r   rj   s   ` @r,   pytest_addoptionr      sj   OOI&E5 B
 "4	 '9	 MMP	   DW 4	 "9	 =	 c
! %	 4	  #9	 u	 
OOF  r.   _HandlerType)boundc                  >    e Zd ZdZdZdddZd	dZ	 	 	 	 	 	 	 	 d
dZy)catching_logszCContext manager that prepares the whole logging machinery properly.)handlerrd   
orig_levelNc                     || _         || _        y rF   )r   rd   )r?   r   rd   s      r,   rY   zcatching_logs.__init__]  s    
r.   c                r   t        j                         }| j                  %| j                  j	                  | j                         |j                  | j                         | j                  @|j                  | _        |j	                  t        | j                  | j                               | j                  S rF   )rk   	getLoggerrd   r   setLevel
addHandlerr   min)r?   root_loggers     r,   	__enter__zcatching_logs.__enter__a  s    '')::!LL!!$**-t||,::!)//DO  T__djj!AB||r.   c                    t        j                         }| j                  |j                  | j                         |j                  | j                         y rF   )rk   r   rd   r   r   removeHandlerr   )r?   exc_typeexc_valexc_tbr   s        r,   __exit__zcatching_logs.__exit__k  s@     '')::!  1!!$,,/r.   rF   )r   r   rd   
int | NonerH   ry   )rH   r   )r   ztype[BaseException] | Noner   zBaseException | Noner   zTracebackType | NonerH   ry   )rJ   rK   rL   rM   	__slots__rY   r   r    r.   r,   r   r   X  s?    M2I	0,	0 &	0 %		0
 
	0r.   r   c                  H     e Zd ZdZd fdZd fdZddZddZddZ xZ	S )	r&   z;A logging handler that stores log records and the log text.c                B    t         |   t                      g | _        y)zCreate a new log handler.N)r=   rY   r	   records)r?   rE   s    r,   rY   zLogCaptureHandler.__init__z  s    $02r.   c                Z    | j                   j                  |       t        |   |       y)z;Keep the log records in a list in addition to the log text.N)r   r   r=   emit)r?   r@   rE   s     r,   r   zLogCaptureHandler.emit  s!    F#Vr.   c                0    g | _         t               | _        y rF   )r   r	   streamr?   s    r,   resetzLogCaptureHandler.reset  s    jr.   c                V    | j                   j                          t               | _        y rF   )r   clearr	   r   r   s    r,   r   zLogCaptureHandler.clear  s    jr.   c                &    t         j                  r y rF   )rk   raiseExceptionsr?   r@   s     r,   handleErrorzLogCaptureHandler.handleError  s    ""
  #r.   rH   ry   r@   r{   rH   ry   )
rJ   rK   rL   rM   rY   r   r   r   r   rN   rO   s   @r,   r&   r&   w  s    E3

!!r.   c                      e Zd ZdZddddZddZedd       Z	 	 	 	 ddZedd       Z	edd	       Z
edd
       Zedd       ZddZ	 	 	 	 	 	 ddZdddZeddd       Zedd       Zy)LogCaptureFixturez-Provides access and control of log capturing.F	_ispytestc               R    t        |       || _        d | _        i | _        d | _        y rF   )r    _item_initial_handler_level_initial_logger_levels_initial_disabled_logging_level)r?   itemr   s      r,   rY   zLogCaptureFixture.__init__  s)    y!
26#=?#;?,r.   c                \   | j                   %| j                  j                  | j                          | j                  j	                         D ]+  \  }}t        j                  |      }|j                  |       - | j                  't        j                  | j                         d| _        yy)zFinalize the fixture.

        This restores the log levels and the disabled logging levels changed by :meth:`set_level`.
        N)	r   r   r   r   r_   rk   r   r   disable)r?   logger_namerd   loggers       r,   	_finalizezLogCaptureFixture._finalize  s     &&2LL!!$"="=>"&"="="C"C"EK&&{3FOOE" #F //;OOD@@A37D0 <r.   c                <    | j                   j                  t           S )z,Get the logging handler used by the fixture.)r   stashcaplog_handler_keyr   s    r,   r   zLogCaptureFixture.handler  s     zz 233r.   c                \    | j                   j                  t           j                  |g       S )a5  Get 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
        )r   r  caplog_records_keyru   r?   whens     r,   get_recordszLogCaptureFixture.get_records  s'     zz 2377bAAr.   c                \    t        | j                  j                  j                               S )zThe formatted log text.)r-   r   r   getvaluer   s    r,   r+   zLogCaptureFixture.text  s"     -T\\-@-@-I-I-KLLr.   c                .    | j                   j                  S )zThe list of log records.)r   r   r   s    r,   r   zLogCaptureFixture.records  s     ||###r.   c                    | j                   D cg c])  }|j                  |j                  |j                         f+ c}S c c}w )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)
        )r   rq   rv   
getMessager?   rs     r,   record_tupleszLogCaptureFixture.record_tuples  s6     >B\\J\ALLN3\JJJs   .A c                \    | j                   D cg c]  }|j                          c}S c c}w )a  A 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
        )r   r  r  s     r,   messageszLogCaptureFixture.messages  s&    " )-51555s   )c                8    | j                   j                          y)z8Reset the list of log records and the captured log text.N)r   r   r   s    r,   r   zLogCaptureFixture.clear  s    r.   c                l   |j                   j                  }t        |t              rt	        j
                  |      }t        |t              s%t	        j                  t        j                         |S |j                  |      s2t        |dz
  t        j                        }t	        j                  |       |S )aP  Enable 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.
        
   )
managerr  r   rI   rk   rl   r:   r   isEnabledFormax)r?   rd   
logger_objoriginal_disable_leveldisable_levels        r,   _force_enable_loggingz'LogCaptureFixture._force_enable_logging  s    " '1&8&8&@&@eS!((/E%%OOGNN+ &% ((/  
GNN;MOOM*%%r.   Nc                l   t        j                  |      }| j                  j                  ||j                         |j                  |       | j                  | j                  j                  | _        | j                  j                  |       | j                  ||      }| j                  || _	        yy)a  Set 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 :func:`logging.disable`.

        :param level: The level.
        :param logger: The logger to update. If not given, the root logger.
        N)
rk   r   r   
setdefaultrd   r   r   r   r   r   )r?   rd   r  r  initial_disabled_logging_levels        r,   	set_levelzLogCaptureFixture.set_level  s     &&v.
##..vz7G7GHE"&&.*.,,*<*<D'e$)-)C)CE:)V&//73QD0 8r.   c              #    K   t        j                  |      }|j                  }|j                  |       | j                  j                  }| j                  j                  |       | j                  ||      }	 d |j                  |       | j                  j                  |       t        j                  |       y# |j                  |       | j                  j                  |       t        j                  |       w xY ww)au  Context manager that sets the level for capturing of logs. After
        the end of the 'with' statement the level is restored to its original
        value.

        Will enable the requested logging level if it was disabled via :func:`logging.disable`.

        :param level: The level.
        :param logger: The logger to update. If not given, the root logger.
        N)rk   r   rd   r   r   r   r  )r?   rd   r  r  r   handler_orig_levelr  s          r,   at_levelzLogCaptureFixture.at_level,  s      &&v.
%%
E"!\\//e$!%!;!;E:!N	4
+LL!!"45OO23 
+LL!!"45OO23s    A6D9B? =AD?ADDc              #     K   | j                   j                  |       	 d | j                   j                  |       y# | j                   j                  |       w xY ww)a!  Context manager that temporarily adds the given filter to the caplog's
        :meth:`handler` for the 'with' statement block, and removes that filter at the
        end of the block.

        :param filter_: A custom :class:`logging.Filter` object.

        .. versionadded:: 7.5
        N)r   	addFilterremoveFilter)r?   filter_s     r,   	filteringzLogCaptureFixture.filteringD  sF      	w'	/LL%%g.DLL%%g.s   A? AAA)r   z
nodes.Noder   r   rH   ry   r   )rH   r&   )r  z$Literal['setup', 'call', 'teardown']rH   list[logging.LogRecord])rH   rI   )rH   r-  )rH   zlist[tuple[str, int, str]])rH   	list[str])rd   	int | strr  zlogging.LoggerrH   r:   rF   )rd   r/  r  rG   rH   ry   )rd   r/  r  rG   rH   Generator[None])r+  zlogging.FilterrH   r0  )rJ   rK   rL   rM   rY   r  propertyr   r  r+   r   r  r  r   r   r$  r   r'  r,  r   r.   r,   r   r     s    7>C @8  4 4B8B	 B M M $ $ K K 6 6$ & &,: &	 &DR2 4 4. / /r.   r   c              #  b   K   t        | j                  d      }| |j                          yw)a  Access 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
    Tr   N)r   noder  )requestresults     r,   caplogr6  U  s)      w||t<F
L
s   -/c                    |D ]*  }| j                  |      }|| j                  |      }|s* n y t        |t              r|j	                         }	 t        t        t        ||            S # t        $ r}t        d| d| d      |d }~ww xY w)N'z1' is not recognized as a logging level name for 'z9'. Please consider passing the logging level num instead.)
r   r   r   rI   upperr:   getattrrk   r   r   )r   setting_namessetting_namer   es        r,   get_log_level_for_settingr>  f  s    %$$\2	l3I & )S!OO%	77Iy9:: 	{ ~ ))
 		s   A, ,	B5BBT)trylastc                N    | j                   j                  t        |       d       y )Nzlogging-plugin)pluginmanagerregisterLoggingPlugin)r   s    r,   pytest_configurerD  ~  s    
!!-"79IJr.   c                  l   e Zd ZdZddZddZd ZddZddZ e	dd      dd	       Z
 e	dd      dd
       Z e	d      dd       Ze	dd       Ze	dd       ZddZ e	d      dd       Z e	d      dd       Z e	d      dd       Ze	dd       Z e	dd      dd       Ze	dd       Zy) rC  zGAttaches to the logging module and captures log messages for each test.c                   || _         | j                  t        |d      t        |d      t        |d            | _        t	        |d      | _        t               | _        | j                  j                  | j                         t               | _	        | j                  j                  | j                         t	        |dd      | _
        t        |d      xs t        j                  }|t        j                  k7  rpt        j                  j                  t        j                  j                  |            }t        j                  j!                  |      st        j"                  |       t        |d      xs d| _        t'        || j$                  d	
      | _        t        |dd      }t        |dd      }t+        ||      }| j(                  j                  |       t	        |dd      | _        | j/                         rL|j0                  j3                  d      }|J |j0                  j3                  d      }t5        ||      | _        nt9               | _        | j                  t        |dd      t        |dd      t        |d            }	| j6                  j                  |	       | j;                  |j<                  j>                         y)zCreate a new plugin to capture log messages.

        The formatter can be safely shared across all handlers so
        create a single one for the entire test session here.
        r   r   r   r   r   r   r   r   UTF-8modeencodingr   r   )rA   r   terminalreporterNcapturemanagerr   r   )loggers_to_disable) _config_create_formatterr   	formatterr>  r   r&   caplog_handlersetFormatterreport_handlerr   osdevnullpathdirnameabspathisdirmakedirsr   _FileHandlerlog_file_handlerr0   r   _log_cli_enabledrA  
get_plugin_LiveLoggingStreamHandlerlog_cli_handler_LiveLoggingNullHandler_disable_loggersr   r   )
r?   r   r   	directoryr   r   log_file_formatterterminal_reportercapture_managerlog_cli_formatters
             r,   rY   zLoggingPlugin.__init__  sq     //6<06#456#45

 36;G/1((8/1((8 8$k
 "&*5Crzz!(ABI77==+I&+FODK ,4--!
 )1BLQ-*,= 
 /%9
 	**+=> 7O[
   " & 4 4 ? ?@R S$000$22==>NOO **;_M   $;#<D  226#3\B6#8:KL6#45

 	))*;<1M1MNr.   c                P    |sy |D ]  }t        j                  |      }d|_          y )NT)rk   r   disabled)r?   rM  rq   r  s       r,   rb  zLoggingPlugin._disable_loggers  s)    !&D&&t,F"FO 'r.   c                6   t        | j                  j                  dd      }|dk7  r@t        j                  j                  |      r!t        t        | j                        ||      }nt        ||      }t        |j                  j                  |      |_	        |S )Ncolorno)r   )r:  rN  r   rQ   rh   ri   r   r0   r   r[   r\   )r?   r   r   r   rk  rP  s         r,   rO  zLoggingPlugin._create_formatter  s    ++Wd;D=2FFMM
 ,A&t||4j/,I **oFI0!!{
	 r.   c                p   t        |      }|j                         s| j                  j                  |z  }|j                  j                         s|j                  j                  dd       |j                  | j                  d      }| j                  j                  |      }|r|j                          yy)zSet the filename parameter for Logging.FileHandler().

        Creates parent directory if it does not exist.

        .. warning::
            This is an experimental API.
        T)exist_okparentsrG  rH  N)r   is_absoluterN  rootpathparentexistsmkdiropenr   r\  	setStreamclose)r?   fnamefpathr   
old_streams        r,   set_log_pathzLoggingPlugin.set_log_path  s     U  "LL))E1E||""$LLd; $)::43E3EPW:#X**44V<
 r.   c                    | j                   j                  d      duxs | j                   j                  d      }|sy| j                   j                  j	                  d      }|yy)z'Return whether live logging is enabled.r   Nr   FrK  T)rN  r   r   rA  r^  )r?   enabledre  s      r,   r]  zLoggingPlugin._log_cli_enabled  sk    ,,((
 8,,Y7 	  LL66AABTU$r.   T)wrappertryfirstc              #  8  K   | j                   j                  d       t        | j                   | j                        5  t        | j                  | j
                        5  d cd d d        cd d d        S # 1 sw Y   nxY w	 d d d        y # 1 sw Y   y xY ww)Nsessionstartrd   r`  set_whenr   r   r\  r   r   s    r,   pytest_sessionstartz!LoggingPlugin.pytest_sessionstart  sq     %%n54//t7I7IJt44D<O<OP QP KJPPP KJJ:   =B"B!A8%	B.
B8B	=B	BBBc              #  8  K   | j                   j                  d       t        | j                   | j                        5  t        | j                  | j
                        5  d cd d d        cd d d        S # 1 sw Y   nxY w	 d d d        y # 1 sw Y   y xY ww)N
collectionr  r  r   s    r,   pytest_collectionzLoggingPlugin.pytest_collection  sq     %%l34//t7I7IJt44D<O<OP QP KJPPP KJJr  )r~  c              #    K   |j                   j                  j                  rd S | j                         r8| j                  j                         dk  rd| j                  j                  _        t        | j                  | j                        5  t        | j                  | j                        5  d cd d d        cd d d        S # 1 sw Y   nxY w	 d d d        y # 1 sw Y   y xY ww)N   r  )r   r   collectonlyr]  rN  get_verbosityverboser   r`  r   r\  r   )r?   sessions     r,   pytest_runtestloopz LoggingPlugin.pytest_runtestloop  s     >>  ,,N  "t||'A'A'Ca'G*+DLL'4//t7I7IJt44D<O<OP QP KJPPP KJJs<   BC+"C2C	6	C?
C+	C	C	C+C($C+c                n    | j                   j                          | j                   j                  d       y )Nstart)r`  r   r  r   s    r,   pytest_runtest_logstartz%LoggingPlugin.pytest_runtest_logstart%  s(    ""$%%g.r.   c                :    | j                   j                  d       y )N	logreportr`  r  r   s    r,   pytest_runtest_logreportz&LoggingPlugin.pytest_runtest_logreport*  s    %%k2r.   c           	   #    K   t        | j                  | j                        5 }t        | j                  | j                        5 }|j	                          |j	                          |j
                  |j                  t           |<   ||j                  t        <   	 d |j                  j                         j                         }|j                  |d|       	 ddd       ddd       y# |j                  j                         j                         }|j                  |d|       w xY w# 1 sw Y   RxY w# 1 sw Y   yxY ww)z:Implement the internals of the pytest_runtest_xxx() hooks.r  Nlog)r   rQ  r   rS  r   r   r  r	  r  r   r  stripadd_report_section)r?   r   r  rQ  rS  r  s         r,   _runtest_forzLoggingPlugin._runtest_for.  s    ..
 ]..
   "  "3A3I3IDJJ)*40-;DJJ)*:$++446<<>''eS9

 
 %++446<<>''eS9
 

 
sM   "E"D8AD,C,;D,D8#	E,=D))D,,D5	1D88E=Ec              #     K   | j                   j                  d       i }||j                  t        <   | j	                  |d      E d {    y 7 w)Nsetup)r`  r  r  r	  r  )r?   r   emptys      r,   pytest_runtest_setupz"LoggingPlugin.pytest_runtest_setupB  sD     %%g.46).

%&$$T7333s   AAA	Ac              #  z   K   | j                   j                  d       | j                  |d      E d {    y 7 w)Ncall)r`  r  r  r?   r   s     r,   pytest_runtest_callz!LoggingPlugin.pytest_runtest_callJ  s0     %%f-$$T6222s   1;9;c              #    K   | j                   j                  d       	 | j                  |d      E d {    |j                  t        = |j                  t
        = y 7 '# |j                  t        = |j                  t
        = w xY ww)Nteardown)r`  r  r  r  r	  r  r  s     r,   pytest_runtest_teardownz%LoggingPlugin.pytest_runtest_teardownP  so     %%j1	/((z:::

-.

-. ;

-.

-.s+   BA AA #BA $BBc                :    | j                   j                  d       y )Nfinishr  r   s    r,   pytest_runtest_logfinishz&LoggingPlugin.pytest_runtest_logfinishZ  s    %%h/r.   c              #  8  K   | j                   j                  d       t        | j                   | j                        5  t        | j                  | j
                        5  d cd d d        cd d d        S # 1 sw Y   nxY w	 d d d        y # 1 sw Y   y xY ww)Nsessionfinishr  r  r   s    r,   pytest_sessionfinishz"LoggingPlugin.pytest_sessionfinish^  sq     %%o64//t7I7IJt44D<O<OP QP KJPPP KJJr  c                8    | j                   j                          y rF   )r\  rw  r   s    r,   pytest_unconfigurez LoggingPlugin.pytest_unconfiguref  s     	##%r.   Nr   r   rH   ry   )rM  r.  rH   ry   )rx  rI   rH   ry   )rH   r   )rH   r0  )r  r#   rH   zGenerator[None, object, object]r   )r   
nodes.Itemr  rI   rH   r0  )r   r  rH   r0  )rJ   rK   rL   rM   rY   rb  rO  r{  r]  r   r  r  r  r  r  r  r  r  r  r  r  r  r   r.   r,   rC  rC    s+   QAOF#$, dT* + dT* + d
 
 / / 3 3:( d4 4 d3 3
 d/ / 0 0 dT* + & &r.   rC  c                      e Zd ZdZddZy)r[  z)A logging FileHandler with pytest tweaks.c                     y rF   r   r   s     r,   r   z_FileHandler.handleErrorp      r.   Nr   )rJ   rK   rL   rM   r   r   r.   r,   r[  r[  m  s
    3r.   r[  c                  d     e Zd ZU dZdZded<   	 	 	 	 	 	 d
 fdZddZddZd fdZ	dd	Z
 xZS )r_  a  A 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.
    Nr%   r   c                    t         |   |       || _        | j                          | j	                  d        d| _        y )N)r   F)r=   rY   rf  r   r  _test_outcome_written)r?   re  rf  rE   s      r,   rY   z"_LiveLoggingStreamHandler.__init__  s;    
 	 12.

d%*"r.   c                    d| _         y)zBReset the handler; should be called before the start of each test.FN)_first_record_emittedr   s    r,   r   z_LiveLoggingStreamHandler.reset  s
    %*"r.   c                :    || _         d| _        |dk(  rd| _        yy)z7Prepare for the given test phase (setup/call/teardown).Fr  N)_when_section_name_shownr  r
  s     r,   r  z"_LiveLoggingStreamHandler.set_when  s%    
#( 7?).D& r.   c                   | j                   r| j                   j                         n	t               }|5  | j                  s#| j                  j                  d       d| _        n<| j                  dv r.| j                  s"d| _        | j                  j                  d       | j                  s>| j                  r2| j                  j                  d| j                  z   dd       d| _        t        | -  |       d d d        y # 1 sw Y   y xY w)Nr   T)r  r  z	live log -)seprS   )rf  global_and_fixture_disabledr   r  r   writer  r  r  sectionr=   r   )r?   r@   ctx_managerrE   s      r,   r   z_LiveLoggingStreamHandler.emit  s     ##   <<> 	
 --!!$'-1*551115D.KK%%d+++

##K$**$<#D#Q+/(GL  [[s   CDDc                     y rF   r   r   s     r,   r   z%_LiveLoggingStreamHandler.handleError  r  r.   )re  r%   rf  zCaptureManager | NonerH   ry   r   )r  rG   rH   ry   r   )rJ   rK   rL   rM   r   r   rY   r   r  r   r   rN   rO   s   @r,   r_  r_  u  sJ      $F#	++	+ /	+ 
		++/!&r.   r_  c                  (    e Zd ZdZddZddZddZy)	ra  z5A logging handler used when live logging is disabled.c                     y rF   r   r   s    r,   r   z_LiveLoggingNullHandler.reset      r.   c                     y rF   r   r
  s     r,   r  z _LiveLoggingNullHandler.set_when  r  r.   c                     y rF   r   r   s     r,   r   z#_LiveLoggingNullHandler.handleError  r  r.   Nr   )r  rI   rH   ry   r   )rJ   rK   rL   rM   r   r  r   r   r.   r,   ra  ra    s    ?r.   ra  )r+   rI   rH   rI   )r   r   r   rI   )r   r   rH   ry   )r4  r"   rH   zGenerator[LogCaptureFixture])r   r   r;  rI   rH   r   r  )VrM   
__future__r   
contextlibr   r   r   r   r   ior	   rk   r
   rT  pathlibr   r   typesr   typingr   r   r   r   r   r   r   r   r   r   _pytestr   _pytest._ior   _pytest.capturer   _pytest.configr   r   r   r   r   _pytest.config.argparsingr   _pytest.deprecatedr    _pytest.fixturesr!   r"   _pytest.mainr#   _pytest.stashr$   _pytest.terminalr%   StreamHandlerlogging_StreamHandlerr   r   r   r)   r  rI   r	  r-   	Formatterr0   rQ   PercentStyler   r   r   Handlerr   r   r&   r   r6  r>  rD  rC  FileHandlerr[  r_  NullHandlerra  r   r.   r,   <module>r     s   ' " % "    	    	  	              & * % ! 1 # % , - $ +   " - #11(;#11S $ 2::./ 2X124 AXd3W->->(?#?@AC *3)) 3&9&- 9&xV+G00 V+raH ~W__=0GL) 0>- < |/ |/ |/~ 	 	 0 
$K Kg& g&T7&& 8 5 8vg11 r.   