
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 Z d d l Z d d l	 Z	 d d l
 Z
 d d l Z d d l Z d d l m Z d d l m Z e j d d k  r d d	 l m Z n  d
 e
 j j f d     YZ d6 Z d7 d8 d9 d: f Z g  e D]= \ Z Z e e j k  rd e j e  e j e  f ^ qZ g  e D] Z e j e  ^ qae Z e j d d j  e   Z! [ [ [ e j d  Z" d   Z# d   Z$ i  Z% i d d g d 6e% d  <i d! d" d# g d 6e% d$ <e% d  j&   e% d% <e$ e% d% e% d$  e% d  e% d& <d' e' f d(     YZ( d)   Z) e j* d*    Z+ e j* d+    Z, d,   Z- e j* d- d.  d/    Z. d0   Z/ d1   Z0 d2   Z1 d3   Z2 d4 e' f d5     YZ3 d S(;   s'  
    report test results in JUnit-XML format,
    for use with Jenkins and build integration servers.


Based on initial code from Ross Lawley.

Output conforms to https://github.com/jenkinsci/xunit-plugin/blob/master/
src/main/resources/org/jenkinsci/plugins/xunit/types/model/xsd/junit-10.xsd
i    (   t   absolute_import(   t   division(   t   print_functionN(   t   nodes(   t   filename_argi   (   t   opent   Junitc           B` s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyR   "   s   i	   i
   i   i    i~   i   i  i   i  i   i u   %s-%su   [^%s]u    s   \.py$c         C` s1   d   } t  j j t j | t  j j |     S(   Nc         S` s2   t  |  j    } | d k r& d | Sd | Sd  S(   Ni   u   #x%02Xu   #x%04X(   t   ordt   group(   t   matchobjt   i(    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyt   repl<   s    (   t   pyt   xmlt   rawt   illegal_xml_ret   subt   escape(   t   argR   (    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyt   bin_xml_escape;   s    	c         C` s   i  } xi |  j    D][ \ } } xL | j    D]> \ } } t | t  s\ t t |    n  | | | | <q, Wq W|  j |  d  S(   N(   t   itemst
   isinstancet   listt	   TypeErrort   typet   update(   t   leftt   rightt   resultt   klt   vlt   krt   vr(    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyt   merge_familyF   s    t	   classnamet   namet   testcaset   _baset   filet   linet   urlt   _base_legacyt   xunit1t   xunit2t   _NodeReporterc           B` s   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d d  Z
 d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z RS(   c         C` sa   | |  _  | |  _ |  j j |  _ |  j j |  _ d |  _ g  |  _ g  |  _ d  |  _ i  |  _	 d  S(   Ni    (
   t   idR   t	   add_statst   familyt   durationt
   propertiesR   t   NoneR&   t   attrs(   t   selft   nodeidR   (    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyt   __init__]   s    						c         C` s-   |  j  j t |  j  |  j j |  d  S(   N(   R   R0   R   R   R   t   append(   R6   t   node(    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyR9   h   s    c         C` s&   |  j  j t |  t |  f  d  S(   N(   R3   R9   t   strR   (   R6   R%   t   value(    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyt   add_propertyl   s    c         C` s   t  |  |  j t |  <d  S(   N(   R   R5   R;   (   R6   R%   R<   (    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyt   add_attributeo   s    c         C` sH   |  j  rD t j  g  |  j  D]$ \ } } t j d | d |  ^ q  Sd S(   sB   Return a Junit node containing custom properties, if any.
        R%   R<   t    (   R3   R   t   property(   R6   R%   R<   (    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyt   make_properties_noder   s
    	2c         C` sV  |  j  s t  t | j  } |  j } | d  } |  j j rW | j d |  j j  n  i d j |  d 6t	 | d  d 6| j
 d d 6} | j
 d d  k	 r | j
 d | d <n  t | d	  r | j | d	 <n  | |  _ |  j j |  |  j d
 k r d  Si  } xB |  j j   D]1 } | t |  j d k r|  j | | | <qqW| |  _ d  S(   Nii    t   .R$   R%   R(   i   R)   R*   R,   R&   (   R&   t   AssertionErrort   mangle_test_addressR7   R5   R   t   prefixt   insertt   joinR   t   locationR4   t   hasattrR*   R   R1   t   keyst   families(   R6   t
   testreportt   namest   existing_attrst
   classnamesR5   t
   temp_attrst   key(    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyt   record_testreport~   s.    	
	c         C` sW   t  j d d |  j |  j  } | j |  j    x |  j D] } | j |  q< W| S(   Nt   times   %.3f(   R   R&   R2   R5   R9   RA   R   (   R6   R&   R:   (    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyt   to_xml   s
    c         C` s/   t  |  } | | d | } |  j |  d  S(   Nt   message(   R   R9   (   R6   t   kindRU   t   dataR:   (    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyt   _add_simple   s    c         C` s  |  j  j r | j r d  S| j } | j } | j } | sA | r | r |  j  j d k r | r d j d j d d  | d d j d d  | g  } q | } n | } | r t	 t
 d  } |  j | t |    q n  | s | r| rG|  j  j d k rG| r>d j d	 j d d  | d d j d d  | g  } qM| } n | } | rt	 t
 d  } |  j | t |    qn  d  S(
   Ns
   system-outs   
s    Captured Stdout iP   t   -R?   s    Captured Log s
   system-errs    Captured Stderr (   R   t   log_passing_testst   passedt	   capstdoutt   caplogt	   capstderrt   loggingRG   t   centert   getattrR   R9   R   (   R6   t   reportt   content_outt   content_logt   content_errt   contentt   tag(    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyt   write_captured_output   sB    					c         C` s   |  j  d  d  S(   NR[   (   R0   (   R6   Rb   (    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyt   append_pass   s    c         C` s   t  | d  r% |  j t j d  n t  | j d  rI | j j j } n0 t | j t j	  rj | j } n t
 | j  } t |  } t j d |  } | j t | j   |  j |  d  S(   Nt   wasxfails%   xfail-marked test passes unexpectedlyt	   reprcrashRU   (   RI   RX   R   t   skippedt   longreprRk   RU   R   t   sixt   string_typesR;   R   t   failureR9   (   R6   Rb   RU   t   fail(    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyt   append_failure   s    c         C` s)   |  j  t j t | j  d d  d  S(   NRU   s   collection failure(   R9   R   t   errorR   Rm   (   R6   Rb   (    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyt   append_collect_error   s    c         C` s   |  j  t j d | j  d  S(   Ns   collection skipped(   RX   R   Rl   Rm   (   R6   Rb   (    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyt   append_collect_skipped   s    c         C` s;   | j  d k r d } n d } |  j t j | | j  d  S(   Nt   teardowns   test teardown failures   test setup failure(   t   whenRX   R   Rs   Rm   (   R6   Rb   t   msg(    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyt   append_error   s    	c         C` s   t  | d  r_ | j } | j d  r4 | d } n  |  j t j d d d d t |   n| | j \ } } } | j d  r | d	 } n  d
 | | | f } |  j t j t |  d d d t |   |  j |  d  S(   NRj   s   reason: i   R?   R   s   pytest.xfailRU   s	   Skipped: i	   s	   %s:%s: %ss   pytest.skip(	   RI   Rj   t
   startswithR9   R   Rl   R   Rm   Rh   (   R6   Rb   t   xfailreasont   filenamet   linenot
   skipreasont   details(    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyt   append_skipped  s"    	c         ` s;   |  j    j d d    |  j j     f d   |  _  d  S(   Nt   indenti    c           ` s   t  j j    S(   N(   R   R   R   (    (   RW   (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyt   <lambda>  R?   (   RT   t   unicodet   __dict__t   clear(   R6   (    (   RW   s/   lib/python2.7/site-packages/_pytest/junitxml.pyt   finalize  s    N(   R   R   R8   R9   R=   R>   RA   RR   RT   R4   RX   Rh   Ri   Rr   Rt   Ru   Ry   R   R   (    (    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyR.   \   s    								5						c         C` sr   d d l  m } t |  j d d	  } | d	 k	 rn | j d
 k rn |  j j | d j d | d | j    n  d	 S(   s[   Emits a PytestWarning about the given fixture being incompatible with newer xunit revisionsi    (   t   PytestWarningt   _xmlR,   t   legacysV   {fixture_name} is incompatible with junit_family '{family}' (use 'legacy' or 'xunit1')t   fixture_nameR1   N(   R,   R   (	   t   _pytest.warning_typesR   Ra   t   configR4   R1   R:   t   warnt   format(   t   requestR   R   R   (    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyt!   _warn_incompatibility_with_xunit2   s    		c         ` s    t    d    f d   } | S(   sr  Add an extra properties the calling test.
    User properties become part of the test report and are available to the
    configured reporters, like JUnit XML.
    The fixture is callable with ``(name, value)``, with value being automatically
    xml-encoded.

    Example::

        def test_function(record_property):
            record_property("example_key", 1)
    t   record_propertyc         ` s     j  j j |  | f  d  S(   N(   R:   t   user_propertiesR9   (   R%   R<   (   R   (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyt   append_property>  s    (   R   (   R   R   (    (   R   s/   lib/python2.7/site-packages/_pytest/junitxml.pyR   /  s    c         C` s   d d l  m } |  j j | d   t |  d  d   } | } t |  j d d  } | d k	 r | j |  j j	  } | j
 } n  | S(   s   Add extra xml attributes to the tag for the calling test.
    The fixture is callable with ``(name, value)``, with value being
    automatically xml-encoded
    i    (   t   PytestExperimentalApiWarnings/   record_xml_attribute is an experimental featuret   record_xml_attributec         S` s   d  S(   N(    (   R%   R<   (    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyt   add_attr_noopS  s    R   N(   R   R   R:   R   R   Ra   R   R4   t   node_reporterR7   R>   (   R   R   R   t	   attr_funcR   R   (    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyR   D  s    		c         C` sL   t  } t | t j  sH d } t | j d |  d t |  j    n  d S(   sb   Used by record_testsuite_property to check that the given parameter name is of the proper
    types5   {param} parameter needs to be a string, but {g} givent   paramt   gN(   t   TrueR   Rn   Ro   R   R   R   R   (   R   t   vt   __tracebackhide__Rx   (    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyt   _check_record_param_type`  s    t   scopet   sessionc         C` s@   t  } d   } t |  j d d  } | d k	 r< | j } n  | S(   sR  
    Records a new ``<property>`` tag as child of the root ``<testsuite>``. This is suitable to
    writing global information regarding the entire test suite, and is compatible with ``xunit2`` JUnit family.

    This is a ``session``-scoped fixture which is called with ``(name, value)``. Example:

    .. code-block:: python

        def test_foo(record_testsuite_property):
            record_testsuite_property("ARCH", "PPC")
            record_testsuite_property("STORAGE_TYPE", "CEPH")

    ``name`` must be a string, ``value`` will be converted to a string and properly xml-escaped.
    c         S` s   t  } t d |   d S(   sC   noop function in case --junitxml was not passed in the command-lineR%   N(   R   R   (   R%   R<   R   (    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyt   record_func|  s    R   N(   R   Ra   R   R4   t   add_global_property(   R   R   R   R   (    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyt   record_testsuite_propertyi  s    	c         C` s   |  j  d  } | j d d d d d d d d	 d
 t j t d d d d  d d | j d d d d d d d d  d d |  j d d d d |  j d d d d |  j d d d
 d d t |  j d d d d |  j d d  d d! d  S("   Ns   terminal reportings
   --junitxmls   --junit-xmlt   actiont   storet   destt   xmlpatht   metavart   pathR   t   optnamet   defaultt   helps1   create junit-xml style report file at given path.s   --junitprefixs   --junit-prefixR;   s0   prepend prefix to classnames in junit-xml outputt   junit_suite_names    Test suite name for JUnit reportt   pytestt   junit_loggingsL   Write captured log messages to JUnit report: one of no|system-out|system-errt   not   junit_log_passing_testss;   Capture log information for passing tests to JUnit report: t   boolt   junit_duration_reports*   Duration time to report: one of total|callt   totalt   junit_familys0   Emit XML for schema: one of legacy|xunit1|xunit2R,   (   t   getgroupt	   addoptiont	   functoolst   partialR   R4   t   addiniR   (   t   parserR
   (    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyt   pytest_addoption  sH    c      	   C` s   |  j  j } | r t |  d  r t | |  j  j |  j d  |  j d  |  j d  |  j d  |  j d   |  _ |  j j |  j  n  d  S(   Nt
   slaveinputR   R   R   R   R   (	   t   optionR   RI   t   LogXMLt   junitprefixt   getiniR   t   pluginmanagert   register(   R   R   (    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyt   pytest_configure  s    	c         C` s5   t  |  d d   } | r1 |  ` |  j j |  n  d  S(   NR   (   Ra   R4   R   R   t
   unregister(   R   R   (    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyt   pytest_unconfigure  s    c         C` s   |  j  d  \ } } } | j d  } y | j d  Wn t k
 rK n X| d j t j d  | d <t j d | d  | d <| d c | | 7<| S(   Nt   [s   ::s   ()i    RB   R?   i(	   t	   partitiont   splitt   removet
   ValueErrort   replaceR   t   SEPt
   _py_ext_reR   (   t   addressR   t   possible_open_brackett   paramsRM   (    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyRD     s    R   c           B` s   e  Z d  d d d e d  Z d   Z d   Z d   Z d   Z d	   Z d
   Z	 d   Z
 d   Z d   Z d   Z d   Z d   Z d   Z RS(   R   R   R   R,   c         C` s   t  j j t  j j |   } t  j j t  j j |   |  _ | |  _ | |  _ | |  _	 | |  _
 | |  _ | |  _ t j d d d d g d  |  _ i  |  _ g  |  _ g  |  _ g  |  _ d |  _ |  j d k r d |  _ n  d  S(   NRs   R[   Rp   Rl   i    R   R,   (   t   osR   t
   expandusert
   expandvarst   normpatht   abspatht   logfileRE   t
   suite_nameR_   RZ   t   report_durationR1   t   dictt   fromkeyst   statst   node_reporterst   node_reporters_orderedt   global_propertiest   open_reportst   cnt_double_fail_tests(   R6   R   RE   R   R_   R   R1   RZ   (    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyR8     s     
!						!					c         C` sY   t  | d |  } t  | d d   } |  j j | | f  } | d  k	 rU | j   n  d  S(   NR7   R:   (   Ra   R4   R   t   popR   (   R6   Rb   R7   t	   slavenodet   reporter(    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyR     s
    c         C` sz   t  | d |  } t  | d d   } | | f } | |  j k rJ |  j | St | |   } | |  j | <|  j j |  | S(   NR7   R:   (   Ra   R4   R   R.   R   R9   (   R6   Rb   R7   R   RQ   R   (    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyR     s    c         C` s)   | |  j  k r% |  j  | c d 7<n  d  S(   Ni   (   R   (   R6   RQ   (    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyR0     s    c         C` s    |  j  |  } | j |  | S(   N(   R   RR   (   R6   Rb   R   (    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyt   _opentestcase  s    c         ` s  d }   j r@   j d k rB|  j    } | j    qBn  j r  j d k r t   d d   t   d d   t     f d   |  j D d  } | r |  j	 |  |  j
 d 7_
 q n  |  j    }   j d k r
| j    |  j j    qB| j    n(   j rB|  j    } | j    n  |  j      j d k r|  j    } | j    x'   j D] \ } } | j | |  qW|  j	    t   d d   t   d d   t     f d   |  j D d  } | r|  j j |  qn  d S(	   s  handle a setup/call/teardown report, generating the appropriate
        xml tags as necessary.

        note: due to plugins like xdist, this hook may be called in interlaced
        order with reports from other nodes. for example:

        usual call order:
            -> setup node1
            -> call node1
            -> teardown node1
            -> setup node2
            -> call node2
            -> teardown node2

        possible call order in xdist:
            -> setup node1
            -> call node1
            -> setup node2
            -> call node2
            -> teardown node2
            -> teardown node1
        t   callRv   t	   worker_idt
   item_indexc         3` sW   |  ]M } | j    j  k r t | d  d   k r t | d d   k r | Vq d S(   R   R   N(   R7   Ra   R4   (   t   .0t   rep(   Rb   t	   report_iit
   report_wid(    s/   lib/python2.7/site-packages/_pytest/junitxml.pys	   <genexpr>B  s   i   c         3` sW   |  ]M } | j    j  k r t | d  d   k r t | d d   k r | Vq d S(   R   R   N(   R7   Ra   R4   (   R   R   (   Rb   R   R   (    s/   lib/python2.7/site-packages/_pytest/junitxml.pys	   <genexpr>h  s   N(   R4   R[   Rw   R   Ri   t   failedRa   t   nextR   R   R   Rr   R9   Ry   Rl   R   t   update_testcase_durationRh   R   R=   R   (   R6   Rb   t   close_reportR   t   propnamet	   propvalue(    (   Rb   R   R   s/   lib/python2.7/site-packages/_pytest/junitxml.pyt   pytest_runtest_logreport  sN    		
		
	c         C` sR   |  j  d k s! | j |  j  k rN |  j |  } | j t | d d  7_ n  d S(   s   accumulates total duration for nodeid from given report and updates
        the Junit.testcase with the new total if already created.
        R   R2   g        N(   R   Rw   R   R2   Ra   (   R6   Rb   R   (    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyR   u  s    !c         C` sE   | j  sA |  j |  } | j r1 | j |  qA | j |  n  d  S(   N(   R[   R   R   Rt   Ru   (   R6   Rb   R   (    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyt   pytest_collectreport}  s
    		c         C` sB   |  j  d  } | j j d d d d  | j t j d |  d  S(   Nt   internalR$   R   R%   s   internal error(   R   R5   R   RX   R   Rs   (   R6   t   excreprR   (    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyt   pytest_internalerror  s    c         C` s   t  j    |  _ d  S(   N(   RS   t   suite_start_time(   R6   (    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyt   pytest_sessionstart  s    c         C` sK  t  j j t  j j |  j   } t  j j |  sC t  j |  n  t |  j d d d } t j   } | |  j	 } |  j
 d |  j
 d |  j
 d |  j
 d |  j } | j d  | j t j |  j   g  |  j D] } | j   ^ q d	 |  j d
 |  j
 d d |  j
 d d |  j
 d d | d d | j d d   | j   d  S(   Nt   wt   encodings   utf-8R[   Rp   Rl   Rs   s&   <?xml version="1.0" encoding="utf-8"?>R%   t   errorst   failurest   testsRS   s   %.3fR   i    (   R   R   t   dirnameR   R   t   isdirt   makedirsR   RS   R   R   R   t   writeR   t	   testsuitet   _get_global_properties_nodeR   RT   R   R   t   close(   R6   R   R   t   suite_stop_timet   suite_time_deltat   numtestst   x(    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyt   pytest_sessionfinish  s(    !5	"	
c         C` s   | j  d d |  j  d  S(   NRY   s   generated xml file: %s(   t	   write_sepR   (   R6   t   terminalreporter(    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyt   pytest_terminal_summary  s    c         C` s3   t  } t d |  |  j j | t |  f  d  S(   NR%   (   R   R   R   R9   R   (   R6   R%   R<   R   (    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyR     s    c         C` sH   |  j  rD t j g  |  j  D]$ \ } } t j d | d |  ^ q  Sd S(   sB   Return a Junit node containing custom properties, if any.
        R%   R<   R?   (   R   R   R3   R@   (   R6   R%   R<   (    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyR    s
    	2(   R   R   R   R8   R   R   R0   R   R   R   R   R   R   R
  R  R   R  (    (    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyR     s$   					V							(   i	   i
   i   (   i    i~   (   i   i  (   i   i  (   i   i (4   t   __doc__t
   __future__R    R   R   R   R   t   ret   sysRS   R   Rn   R   t   _pytestR   t   _pytest.configR   t   version_infot   codecsR   R   t	   NamespaceR   t   _legal_charst   _legal_rangest   lowt   hight
   maxunicodet   unichrt   _legal_xml_reR	  t   compileRG   R   R   R   R#   RK   t   copyt   objectR.   R   t   fixtureR   R   R   R   R   R   R   RD   R   (    (    (    s/   lib/python2.7/site-packages/_pytest/junitxml.pyt   <module>   s\   	7&		
				/			