
i\c           @` s  d  Z  d d l m Z d d l m Z d d l m Z d d l Z d d l Z d d l m Z d d l	 Z	 d d l
 Z
 d d l Z d d l m Z d d l m Z d d	 l m Z d
 Z d Z e j d  Z d   Z d e j f d     YZ e
 j sd e j f d     YZ n  d   Z d   Z e d d d   Z d e j  f d     YZ! d e" f d     YZ# e j$ d    Z% d   Z& e j' d e(  d    Z) d e" f d     YZ* d e j  f d      YZ+ d S(!   s#    Access and control log capturing. i    (   t   absolute_import(   t   division(   t   print_functionN(   t   contextmanager(   t   dummy_context_manager(   t   create_terminal_writer(   t   Paths<   %(levelname)-8s %(name)s:%(filename)s:%(lineno)d %(message)ss   %H:%M:%Ss   \x1b\[[\d;]+mc         C` s   t  j d |   S(   Nt    (   t   _ANSI_ESCAPE_SEQt   sub(   t   text(    (    s.   lib/python2.7/site-packages/_pytest/logging.pyt   _remove_ansi_escape_sequences   s    t   ColoredLevelFormatterc           B` s   e  Z d  Z i d h e j 6d d h e j 6d h e j 6d h e j 6d h e j 6d h e j	 6e
   e j 6Z e j d  Z d   Z d   Z RS(	   sQ   
    Colorize the %(levelname)..s part of the log format passed to __init__.
    t   redt   boldt   yellowt   greent   purples   %\(levelname\)([+-]?\d*s)c         O` s   t  t |   j | |   t j r1 |  j |  _ n |  j j |  _ i  |  _ |  j	 j
 |  j  } | sh d  S| j   } xx |  j j   D]g \ } } | i t j |  d 6} d   | D }	 | j | |	  }
 |  j	 j |
 |  j  |  j | <q Wd  S(   Nt	   levelnamec         S` s   i  |  ] } t  |  q S(    (   t   True(   t   .0t   name(    (    s.   lib/python2.7/site-packages/_pytest/logging.pys
   <dictcomp>?   s   	 (   t   superR   t   __init__t   sixt   PY2t   _fmtt   _original_fmtt   _stylet   _level_to_fmt_mappingt   LEVELNAME_FMT_REGEXt   searcht   groupt   LOGLEVEL_COLOROPTSt   itemst   loggingt   getLevelNamet   markupR	   (   t   selft   terminalwritert   argst   kwargst   levelname_fmt_matcht   levelname_fmtt   levelt
   color_optst   formatted_levelnamet   color_kwargst   colorized_formatted_levelname(    (    s.   lib/python2.7/site-packages/_pytest/logging.pyR   ,   s"    			c         C` sR   |  j  j | j |  j  } t j r0 | |  _ n | |  j _ t t	 |   j
 |  S(   N(   R   t   gett   levelnoR   R   R   R   R   R   R   t   format(   R&   t   recordt   fmt(    (    s.   lib/python2.7/site-packages/_pytest/logging.pyR3   G   s
    	(   t   __name__t
   __module__t   __doc__R#   t   CRITICALt   ERRORt   WARNINGt   WARNt   INFOt   DEBUGt   sett   NOTSETR!   t   ret   compileR   R   R3   (    (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyR      s   	t   PercentStyleMultilinec           B` s&   e  Z d  Z e d    Z d   Z RS(   s   A 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         C` s   |  j    } | | d <| S(   Nt   message(   t   copy(   t   record_dictRD   t   tmp(    (    s.   lib/python2.7/site-packages/_pytest/logging.pyt   _update_messageZ   s    
c         C` s   d | j  k rv | j  j   } |  j |  j | j | d  } t |  j | d  } | | d <d d | j |  S|  j | j Sd  S(   Ns   
i    t    (   RD   t
   splitlinesR   RH   t   __dict__R   t   findt   join(   R&   R4   t   linest	   formattedt   indentation(    (    s.   lib/python2.7/site-packages/_pytest/logging.pyR3   `   s     
(   R6   R7   R8   t   staticmethodRH   R3   (    (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyRC   S   s   c         G` sL   xE | D]= } |  j  |  } | d  k r: |  j |  } n  | r | Sq Wd  S(   N(   t	   getoptiont   Nonet   getini(   t   configt   namesR   t   ret(    (    s.   lib/python2.7/site-packages/_pytest/logging.pyt   get_option_inin   s    c         ` s   j  d    d* d*    f d  } | d d d d d d t d	 t d
 d d d | d d d d	 d* d d | d d d d	 t d d | d d d d	 t d d  j d d	 t 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 | d  d d! d	 d* d d" | d# d d$ d	 d* d d% | d& d d' d	 t d d | d( d d) d	 t d d d* S(+   s%   Add options to control log capturing.R#   c      	   ` s=    j  | d | d | d d |    j |  d | | d  S(   Nt   defaultt   typet   helps   default value for t   dest(   t   addinit	   addoption(   t   optionR\   RY   RZ   R)   (   R    t   parser(    s.   lib/python2.7/site-packages/_pytest/logging.pyt   add_option_ini{   s    s   --no-print-logsR\   t	   log_printt   actiont   store_constt   constRY   RZ   t   boolR[   s-   disable printing caught logs on failed tests.s   --log-levelt	   log_levels(   logging level used by the logging modules   --log-formatt
   log_formats)   log format as used by the logging module.s   --log-date-formatt   log_date_formats.   log date format as used by the logging module.t   log_clisB   enable log display during test run (also known as "live logging").s   --log-cli-levelt   log_cli_levels   cli logging level.s   --log-cli-formatt   log_cli_formats   --log-cli-date-formatt   log_cli_date_formats
   --log-filet   log_files/   path to a file when logging will be written to.s   --log-file-levelt   log_file_levels   log file logging level.s   --log-file-formatt   log_file_formats   --log-file-date-formatt   log_file_date_formatN(   t   getgroupRS   t   FalseR   t   DEFAULT_LOG_FORMATt   DEFAULT_LOG_DATE_FORMATR]   (   R`   Ra   (    (   R    R`   s.   lib/python2.7/site-packages/_pytest/logging.pyt   pytest_addoptionw   s|    c         c` s   t  j   } | d k	 r( |  j |  n  | d k	 rD |  j |  n  |  | j k } | ri | j |   n  | d k	 r | j } | j t | |   n  z	 |  VWd | d k	 r | j |  n  | r | j	 |   n  Xd S(   sC   Context manager that prepares the whole logging machinery properly.N(
   R#   t	   getLoggerRS   t   setFormattert   setLevelt   handlerst
   addHandlerR,   t   mint   removeHandler(   t   handlert	   formatterR,   t   root_loggert   add_new_handlert
   orig_level(    (    s.   lib/python2.7/site-packages/_pytest/logging.pyt   catching_logs   s"    		t   LogCaptureHandlerc           B` s)   e  Z d  Z d   Z d   Z d   Z RS(   s;   A logging handler that stores log records and the log text.c         C` s)   t  j j |  t j j    g  |  _ d S(   s   Creates a new log handler.N(   R#   t   StreamHandlerR   t   pyt   iot   TextIOt   records(   R&   (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyR      s    c         C` s'   |  j  j |  t j j |  |  d S(   s;   Keep the log records in a list in addition to the log text.N(   R   t   appendR#   R   t   emit(   R&   R4   (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyR      s    c         C` s   g  |  _  t j j   |  _ d  S(   N(   R   R   R   R   t   stream(   R&   (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyt   reset   s    	(   R6   R7   R8   R   R   R   (    (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyR      s   		t   LogCaptureFixturec           B` s   e  Z d  Z d   Z d   Z e d    Z d   Z e d    Z e d    Z	 e d    Z
 e d    Z d	   Z d d
  Z e d d   Z RS(   s-   Provides access and control of log capturing.c         C` s   | |  _  i  |  _ d S(   s   Creates a new funcarg.N(   t   _itemt   _initial_log_levels(   R&   t   item(    (    s.   lib/python2.7/site-packages/_pytest/logging.pyR      s    	c         C` s@   x9 |  j  j   D]( \ } } t j |  } | j |  q Wd S(   sc   Finalizes the fixture.

        This restores the log levels changed by :meth:`set_level`.
        N(   R   R"   R#   Rw   Ry   (   R&   t   logger_nameR,   t   logger(    (    s.   lib/python2.7/site-packages/_pytest/logging.pyt	   _finalize  s    c         C` s
   |  j  j S(   s+   
        :rtype: LogCaptureHandler
        (   R   t   catch_log_handler(   R&   (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyR~     s    c         C` s*   |  j  j j |  } | r" | j Sg  Sd S(   s\  
        Get the logging records for one of the possible test phases.

        :param str when:
            Which test phase to obtain the records from. Valid values are: "setup", "call" and "teardown".

        :rtype: List[logging.LogRecord]
        :return: the list of captured records at the given stage

        .. versionadded:: 3.4
        N(   R   t   catch_log_handlersR1   R   (   R&   t   whenR~   (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyt   get_records  s    c         C` s   t  |  j j j    S(   s   Returns the formatted log text.(   R   R~   R   t   getvalue(   R&   (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyR
   %  s    c         C` s
   |  j  j S(   s    Returns the list of log records.(   R~   R   (   R&   (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyR   *  s    c         C` s/   g  |  j  D]! } | j | j | j   f ^ q
 S(   s   Returns a 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   R   R2   t
   getMessage(   R&   t   r(    (    s.   lib/python2.7/site-packages/_pytest/logging.pyt   record_tuples/  s    	c         C` s    g  |  j  D] } | j   ^ q
 S(   s  Returns 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&   R   (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyt   messages:  s    c         C` s   |  j  j   d S(   s8   Reset the list of log records and the captured log text.N(   R~   R   (   R&   (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyt   clearJ  s    c         C` s<   | } t  j |  } |  j j | | j  | j |  d S(   s  Sets the level for capturing of logs. The level will be restored to its previous value at the end of
        the test.

        :param int level: the logger to level.
        :param str logger: the logger to update the level. If not given, the root logger level is updated.

        .. 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.
        N(   R#   Rw   R   t
   setdefaultR,   Ry   (   R&   R,   R   R   (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyt	   set_levelN  s    c         c` sC   t  j |  } | j } | j |  z	 d VWd | j |  Xd S(   s9  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.

        :param int level: the logger to level.
        :param str logger: the logger to update the level. If not given, the root logger level is updated.
        N(   R#   Rw   R,   Ry   (   R&   R,   R   R   (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyt   at_level_  s    		N(   R6   R7   R8   R   R   t   propertyR~   R   R
   R   R   R   R   RS   R   R   R   (    (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyR      s   		
		c         c` s"   t  |  j  } | V| j   d S(   s  Access and control log capturing.

    Captured logs are available through the following properties/methods::

    * 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
    N(   R   t   nodeR   (   t   requestt   result(    (    s.   lib/python2.7/site-packages/_pytest/logging.pyt   caplogp  s    c         G` s   xI | D]= } |  j  |  } | d k r: |  j |  } n  | r Pq q Wd St | t j  rm | j   } n  y t t t	 | |   SWn, t
 k
 r t j d j | |    n Xd S(   s    Return the actual logging level.Nso   '{}' is not recognized as a logging level name for '{}'. Please consider passing the logging level num instead.(   RR   RS   RT   t
   isinstanceR   t   string_typest   uppert   intt   getattrR#   t
   ValueErrort   pytestt
   UsageErrorR3   (   RU   t   setting_namest   setting_nameRg   (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyt   get_actual_log_level  s    t   trylastc         C` s   |  j  j t |   d  d  S(   Ns   logging-plugin(   t   pluginmanagert   registert   LoggingPlugin(   RU   (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyt   pytest_configure  s    R   c           B` sy  e  Z d  Z d   Z d   Z d   Z d   Z d   Z e j	 d e
 d e
  d    Z e d	    Z e d
    Z e j	 d e
  d    Z e j	 d e
  d    Z e j	 d e
  d    Z e j	 d e
  d    Z e j	 d e
  d    Z e j	 d e
  d    Z e j	 d e
 d e
  d    Z e j	 d e
 d e
  d    Z e j	 d e
  d    Z RS(   sL   Attaches to the logging module and captures log messages for each test.
    c         C` sb  | |  _  |  j   r9 | j d  d k  r9 d | j _ n  t | d  |  _ |  j t | d  t | d   |  _ t	 | d  |  _
 t	 | d  |  _ t | d d  |  _ t | d	 d  |  _ t j |  j d
 |  j |  _ t | d  } | r't j | d d d d |  _ |  j j |  j  n	 d |  _ d |  _ d   |  _ |  j   r^|  j   n  d S(   s   Creates 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.
        t   verbosei   Rb   Rh   Ri   Rg   Ro   Rp   Rq   t   datefmtRn   t   modet   wt   encodings   UTF-8c           S` s   t    S(   N(   R   (    (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyt   <lambda>  R   N(   t   _configt   _log_cli_enabledRR   R_   R   RX   t
   print_logst   _create_formatterR   R   Rg   Ro   Rp   Rq   R#   t	   Formattert   log_file_formattert   FileHandlert   log_file_handlerRx   RS   t   log_cli_handlert   live_logs_contextt   _setup_cli_logging(   R&   RU   Rn   (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyR     s0    	!		c         C` s   t  |  j j d d  } | d k rT t j j |  rT t t |  j  | |  } n t j | |  } t	 j
 s t | j j  | _ n  | S(   Nt   colort   no(   R   R   R_   R   R   R   R   R#   R   R   R   RC   R   R   (   R&   Rh   Ri   R   R   (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyR     s    		c         ` s   |  j  } | j j d  } | d  k r+ d  S| j j d  } t | |   |  j t | d d  t | d d     t | d d    |  _     f d	   |  _	 d  S(
   Nt   terminalreportert   capturemanagerRl   Rh   Rm   Ri   Rk   Rg   c           ` s   t   d   d  S(   NR   R,   (   R   (    (   t   log_cli_formatterR   Rk   (    s.   lib/python2.7/site-packages/_pytest/logging.pyR     s   (
   R   R   t
   get_pluginRS   t   _LiveLoggingStreamHandlerR   RX   R   R   R   (   R&   RU   t   terminal_reportert   capture_manager(    (   R   R   Rk   s.   lib/python2.7/site-packages/_pytest/logging.pyR     s    		c         C` s   t  |  } | j   s0 t  |  j j |  } n  | j j   s[ | j j d t d t  n  t j	 t
 |  d d d d |  _ |  j j |  j  d S(   s   Public method, which can set filename parameter for
        Logging.FileHandler(). Also creates parent directory if
        it does not exist.

        .. warning::
            Please considered as an experimental API.
        t   exist_okt   parentsR   R   R   s   UTF-8N(   R   t   is_absoluteR   t   rootdirt   parentt   existst   mkdirR   R#   R   t   strR   Rx   R   (   R&   t   fname(    (    s.   lib/python2.7/site-packages/_pytest/logging.pyt   set_log_path  s    c         C` s(   |  j  j d  d k	 p' |  j  j d  S(   s   Return True if log_cli should be considered enabled, either explicitly
        or because --log-cli-level was given in the command-line.
        s   --log-cli-levelRj   N(   R   RR   RS   RT   (   R&   (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyR     s    	t   hookwrappert   tryfirstc      	   c` sn   |  j    \ |  j r) |  j j d  n  |  j d  k	 r_ t |  j d |  j 
 d  VWd  QXn d  VWd  QXd  S(   Nt
   collectionR,   (   R   R   t   set_whenR   RS   R   Ro   (   R&   (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyt   pytest_collection  s    	c      	   c` sX   |  j  | |  @ |  j d  k	 rI t |  j d |  j 
 d  VWd  QXn d  VWd  QXd  S(   NR,   (   t   _runtest_for_mainR   RS   R   Ro   (   R&   R   R   (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyt   _runtest_for!  s
    c      	   c` s   t  t   d |  j d |  j  } |  j r@ |  j j |  n  | d k rU d Vd St | d  sp i  | _ n  | | j | <| | _	 z	 d VWd | d k r | `	 | ` n  X|  j
 r | j j   j   } | j | d |  n  Wd QXd S(   s6   Implements the internals of pytest_runtest_xxx() hook.R   R,   NR   t   teardownt   log(   R   R   R   Rg   R   R   RS   t   hasattrR   R   R   R   R   t   stript   add_report_section(   R&   R   R   t   log_handlerR   (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyR   *  s(    			
	c         c` s"   |  j  | d  
 d  VWd  QXd  S(   Nt   setup(   R   (   R&   R   (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyt   pytest_runtest_setupG  s    c         c` s"   |  j  | d  
 d  VWd  QXd  S(   Nt   call(   R   (   R&   R   (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyt   pytest_runtest_callL  s    c         c` s"   |  j  | d  
 d  VWd  QXd  S(   NR   (   R   (   R&   R   (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyt   pytest_runtest_teardownQ  s    c         c` s;   |  j  r |  j  j   n  |  j d  d  
 d  VWd  QXd  S(   Nt   start(   R   R   R   RS   (   R&   (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyt   pytest_runtest_logstartV  s    	c         c` s"   |  j  d  d  
 d  VWd  QXd  S(   Nt   finish(   R   RS   (   R&   (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyt   pytest_runtest_logfinish]  s    c         c` s"   |  j  d  d  
 d  VWd  QXd  S(   Nt	   logreport(   R   RS   (   R&   (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyt   pytest_runtest_logreportb  s    c      	   c` s   |  j    q |  j r) |  j j d  n  |  j d  k	 rt z( t |  j d |  j 
 d  VWd  QXWd  |  j j   Xn d  VWd  QXd  S(   Nt   sessionfinishR,   (   R   R   R   R   RS   R   Ro   t   close(   R&   (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyt   pytest_sessionfinishg  s    	c      	   c` sn   |  j    \ |  j r) |  j j d  n  |  j d  k	 r_ t |  j d |  j 
 d  VWd  QXn d  VWd  QXd  S(   Nt   sessionstartR,   (   R   R   R   R   RS   R   Ro   (   R&   (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyt   pytest_sessionstarty  s    	c      	   c` sR   |  j    @ |  j d k	 rC t |  j d |  j 
 d VWd QXn d VWd QXd S(   s   Runs all collected test items.R,   N(   R   R   RS   R   Ro   (   R&   t   session(    (    s.   lib/python2.7/site-packages/_pytest/logging.pyt   pytest_runtestloop  s
    (   R6   R7   R8   R   R   R   R   R   R   t   hookimplR   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyR     s$   	/				!	!!R   c           B` s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   s  
    Custom 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.
    c         C` sC   t  j j |  d | | |  _ |  j   |  j d  t |  _ d S(   s   
        :param _pytest.terminal.TerminalReporter terminal_reporter:
        :param _pytest.capture.CaptureManager capture_manager:
        R   N(	   R#   R   R   R   R   R   RS   Rs   t   _test_outcome_written(   R&   R   R   (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyR     s
    	
c         C` s   t  |  _ d S(   sA   Reset the handler; should be called before the start of each testN(   Rs   t   _first_record_emitted(   R&   (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyR     s    c         C` s.   | |  _  t |  _ | d k r* t |  _ n  d S(   s7   Prepares for the given test phase (setup/call/teardown)R   N(   t   _whenRs   t   _section_name_shownR   (   R&   R   (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyR     s    		c      
   C` s   |  j  r |  j  j   n t   } |  |  j sM |  j j d  t |  _ n7 |  j d k r |  j s t |  _ |  j j d  q n  |  j	 r |  j r |  j j
 d |  j d d d t t |  _	 n  t j j |  |  Wd  QXd  S(	   Ns   
R   R   s	   live log t   sept   -R   (   R   R   (   R   t   global_and_fixture_disabledR   R   R   t   writeR   R   R   R   t   sectionR#   R   R   (   R&   R4   t   ctx_manager(    (    s.   lib/python2.7/site-packages/_pytest/logging.pyR     s    				#(   R6   R7   R8   R   R   R   R   (    (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyR     s
   			(,   R8   t
   __future__R    R   R   R#   RA   t
   contextlibR   R   R   R   t   _pytest.compatR   t   _pytest.configR   t   _pytest.pathlibR   Rt   Ru   RB   R   R   R   R   R   t   PercentStyleRC   RX   Rv   RS   R   R   R   t   objectR   t   fixtureR   R   R   R   R   R   R   (    (    (    s.   lib/python2.7/site-packages/_pytest/logging.pyt   <module>   s<   	4				Tw	