ó
…¾^Yc           @   sÓ   d  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	 m
 Z
 m Z d d l m Z d d l m Z d d l m Z e e ƒ Z d Z d	 „  Z d
 e f d „  ƒ  YZ d S(   s   XML reporting for coverage.pyiÿÿÿÿN(   t   env(   t   __url__t   __version__t   files(   t   iitems(   t   isolate_module(   t   ReportersQ   https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtdc         C   s&   | d k r d Sd t  |  ƒ | Sd S(   s0   Return the fraction of `hit`/`num`, as a string.i    t   1s   %.4gN(   t   float(   t   hitt   num(    (    s4   /tmp/pip-build-hU8Cw8/coverage/coverage/xmlreport.pyt   rate   s    t   XmlReporterc           B   s,   e  Z d  Z d „  Z d d „ Z d „  Z RS(   s<   A reporter for writing Cobertura-style XML coverage results.c         C   s›   t  t |  ƒ j | | ƒ t ƒ  |  _ | j rs xB | j D]4 } t j j | ƒ r8 |  j j	 t
 j | ƒ ƒ q8 q8 Wn  i  |  _ d  |  _ | j j ƒ  |  _ d  S(   N(   t   superR   t   __init__t   sett   source_pathst   sourcet   ost   patht   existst   addR   t   canonical_filenamet   packagest   Nonet   xml_outt   datat   has_arcs(   t   selft   coveraget   configt   src(    (    s4   /tmp/pip-build-hU8Cw8/coverage/coverage/xmlreport.pyR   #   s    	#		c         C   s  | p t  j } t j j j ƒ  } | j d d d ƒ |  _ |  j j	 } | j
 d t ƒ | j
 d t t t j ƒ  d ƒ ƒ ƒ | j |  j j d t ƒ ƒ | j |  j j d t ƒ ƒ |  j |  j | ƒ |  j j d ƒ } | j | ƒ xU t |  j ƒ D]D } |  j j d ƒ } | j | ƒ |  j j | ƒ } | j | ƒ q÷ Wd \ }	 }
 d \ } } |  j j d
 ƒ } | j | ƒ xGt t |  j ƒ ƒ D]0\ } } | \ } } } } } |  j j d ƒ } | j | ƒ |  j j d ƒ } | j | ƒ x- t t | ƒ ƒ D] \ } } | j | ƒ qþW| j
 d | j t j d ƒ ƒ | j
 d t | | ƒ ƒ |  j rnt | | ƒ } n d } | j
 d | ƒ | j
 d d ƒ |	 | 7}	 |
 | 7}
 | | 7} | | 7} qŒW| j
 d t |	 ƒ ƒ | j
 d t |
 ƒ ƒ | j
 d t |
 |	 ƒ ƒ |  j rV| j
 d t | ƒ ƒ | j
 d t | ƒ ƒ | j
 d t | | ƒ ƒ n0 | j
 d d ƒ | j
 d d ƒ | j
 d d ƒ | j
 d d ƒ |  j j  ƒ  } t! j" rÀ| j# d ƒ } n  | j$ | ƒ |	 | } | d	 k rìd } n d |
 | | } | S(   s¯   Generate a Cobertura-compatible XML report for `morfs`.

        `morfs` is a list of modules or file names.

        `outfile` is a file object to write the XML to.

        R   t   versiont	   timestampiè  s    Generated by coverage.py: %s s    Based on %s t   sourcesR   i    R   t   packaget   classest   namet   .s	   line-ratet   0s   branch-ratet
   complexitys   lines-valids   lines-covereds   branches-valids   branches-coveredt   utf8g        g      Y@N(   i    i    (   i    i    (%   t   syst   stdoutt   xmlt   domt   minidomt   getDOMImplementationt   createDocumentR   R   t   documentElementt   setAttributeR   t   strt   intt   timet   appendChildt   createCommentR   t   DTD_URLt   report_filest   xml_filet   createElementt   sortedR   t   createTextNodeR   R   t   replaceR   t   sepR   R   t   toprettyxmlR    t   PY2t   encodet   write(   R   t   morfst   outfilet   implt	   xcoveraget   xsourcesR   t   xsourcet   txtt   lnum_tott	   lhits_tott   bnum_tott	   bhits_tott	   xpackagest   pkg_namet   pkg_datat
   class_eltst   lhitst   lnumt   bhitst   bnumt   xpackaget   xclassest   _t	   class_eltt   branch_ratet   outt   denomt   pct(    (    s4   /tmp/pip-build-hU8Cw8/coverage/coverage/xmlreport.pyt   report/   sx    	&"	


		
	c         C   s  | j  j d d ƒ } xT |  j D]= } | j | j d d ƒ d ƒ r | t | ƒ d } Pq q W| j ƒ  } t j j | ƒ p d } d j	 | j
 d ƒ |  j j  ƒ } | j d d ƒ } | | j  k rñ |  j j | j  t | ƒ  j d ƒ ƒ n  |  j j | i  d d d d g ƒ } |  j j d ƒ }	 |	 j |  j j d	 ƒ ƒ |  j j d
 ƒ }
 |	 j |
 ƒ |	 j d t j j | | ƒ ƒ |	 j d | j d d ƒ ƒ |	 j d d ƒ | j ƒ  } | j ƒ  } x.t | j ƒ D]} |  j j d ƒ } | j d t | ƒ ƒ | j d t t | | j k ƒ ƒ ƒ |  j râ| | k r‚| | \ } } | j d d ƒ | j d d d | | | | f ƒ n  | | k râg  | | D]$ } | d k  r±d n	 t | ƒ ^ q™} | j d d j	 | ƒ ƒ qân  |
 j | ƒ qÒWt | j ƒ } | t | j ƒ } |  j rct d „  | j ƒ  Dƒ ƒ } t d „  | j ƒ  Dƒ ƒ } | | } n d } d } |	 j d t  | | ƒ ƒ |  j r£t  | | ƒ } n d } |	 j d | ƒ |	 | d | <| d c | 7<| d c | 7<| d  c | 7<| d! c | 7<d" S(#   s(   Add to the XML report for a single file.s   \t   /i   u   .R&   s   \/i    t   classt   methodst   linesR%   t   filenameR(   R'   t   linet   numbert   hitst   brancht   trues   condition-coverages   %d%% (%d/%d)id   t   exits   missing-branchest   ,c         s   s   |  ] \ } } | Vq d  S(   N(    (   t   .0t   tt   k(    (    s4   /tmp/pip-build-hU8Cw8/coverage/coverage/xmlreport.pys	   <genexpr>É   s    c         s   s   |  ] \ } } | | Vq d  S(   N(    (   Rl   Rm   Rn   (    (    s4   /tmp/pip-build-hU8Cw8/coverage/coverage/xmlreport.pys	   <genexpr>Ê   s    g        s	   line-rates   branch-ratei   i   i   N(!   Rd   R>   R   t
   startswitht   lent   relative_filenameR   R   t   dirnamet   joint   splitR   t   xml_package_depthR   t   rstripR   t
   setdefaultR   R;   R6   R2   t   relpatht   branch_statst   missing_branch_arcsR<   t
   statementsR3   R4   t   missingR   t   sumt   valuesR   (   R   t   frt   analysisRd   t   source_patht   rel_nameRr   t   package_nameR#   t   xclasst   xlinesRy   Rz   Re   t   xlinet   totalt   takent   bt   annlinest   class_linest
   class_hitst   class_branchest   missing_branchest   class_br_hitsR[   (    (    s4   /tmp/pip-build-hU8Cw8/coverage/coverage/xmlreport.pyR:   Œ   sl    "*$%	5		N(   t   __name__t
   __module__t   __doc__R   R   R_   R:   (    (    (    s4   /tmp/pip-build-hU8Cw8/coverage/coverage/xmlreport.pyR       s   	](   R’   R   t   os.pathR*   R5   t   xml.dom.minidomR,   R   R    R   R   R   t   coverage.backwardR   t   coverage.miscR   t   coverage.reportR   R8   R   R   (    (    (    s4   /tmp/pip-build-hU8Cw8/coverage/coverage/xmlreport.pyt   <module>   s   	