ó
…¾^Yc           @   sq   d  Z  d d l Z d d l m Z d d l m Z m Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ	 d	 „  Z
 d S(
   s    Results of coverage measurement.iÿÿÿÿN(   t   iitems(   t   format_linest
   SimpleReprt   Analysisc           B   sz   e  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(   s(   The results of analyzing a FileReporter.c            s§  | ˆ  _  | ˆ  _ ˆ  j j ˆ  _ ˆ  j j ƒ  ˆ  _ ˆ  j j ƒ  ˆ  _ ˆ  j  j ˆ  j ƒ p] g  } ˆ  j j | ƒ } ˆ  j | ˆ  _ ˆ  j  j	 ƒ  r&t
 ˆ  j j ƒ  ƒ ˆ  _ ˆ  j j ƒ  ˆ  _ ˆ  j j ƒ  ˆ  _ ˆ  j ƒ  } ˆ  j ƒ  } t ‡  f d †  t | ƒ Dƒ ƒ } t d „  t | ƒ Dƒ ƒ } n, g  ˆ  _ i  ˆ  _ t ƒ  ˆ  _ d } } } t d d d t ˆ  j ƒ d t ˆ  j ƒ d t ˆ  j ƒ d	 | d
 | d | ƒ ˆ  _ d  S(   Nc         3   s0   |  ]& \ } } | ˆ  j  k r t | ƒ Vq d  S(   N(   t   missingt   len(   t   .0t   kt   v(   t   self(    s2   /tmp/pip-build-hU8Cw8/coverage/coverage/results.pys	   <genexpr>!   s    c         s   s!   |  ] \ } } t  | ƒ Vq d  S(   N(   R   (   R   R   R   (    (    s2   /tmp/pip-build-hU8Cw8/coverage/coverage/results.pys	   <genexpr>"   s    i    t   n_filesi   t   n_statementst
   n_excludedt	   n_missingt
   n_branchest   n_partial_branchest   n_missing_branches(   t   datat   file_reportert   filenamet   linest
   statementst   excluded_linest   excludedt   translate_linesR   t   has_arcst   sortedt   arcst   _arc_possibilitiest   exit_countst   no_branch_linest	   no_brancht   total_branchest   missing_branch_arcst   sumR    t   sett   NumbersR   t   numbers(   R	   R   R   t   executedR   t   mbaR   R   (    (   R	   s2   /tmp/pip-build-hU8Cw8/coverage/coverage/results.pyt   __init__   s8    		"		c         C   s   t  |  j |  j ƒ S(   sh   The missing line numbers, formatted nicely.

        Returns a string like "1-2, 5-11, 13-14".

        (   R   R   R   (   R	   (    (    s2   /tmp/pip-build-hU8Cw8/coverage/coverage/results.pyt   missing_formatted3   s    c         C   s   |  j  j ƒ  S(   s"   Were arcs measured in this result?(   R   R   (   R	   (    (    s2   /tmp/pip-build-hU8Cw8/coverage/coverage/results.pyR   ;   s    c         C   s   |  j  S(   s.   Returns a sorted list of the arcs in the code.(   R   (   R	   (    (    s2   /tmp/pip-build-hU8Cw8/coverage/coverage/results.pyt   arc_possibilities?   s    c         C   s7   |  j  j |  j ƒ p g  } |  j j | ƒ } t | ƒ S(   s@   Returns a sorted list of the arcs actually executed in the code.(   R   R   R   R   t   translate_arcsR   (   R	   R&   (    (    s2   /tmp/pip-build-hU8Cw8/coverage/coverage/results.pyt   arcs_executedC   s    c            s;   ˆ j  ƒ  } ˆ j ƒ  ‰  ‡  ‡ f d †  | Dƒ } t | ƒ S(   s;   Returns a sorted list of the arcs in the code not executed.c         3   s4   |  ]* } | ˆ  k r | d  ˆ j  k r | Vq d S(   i    N(   R   (   R   t   p(   R&   R	   (    s2   /tmp/pip-build-hU8Cw8/coverage/coverage/results.pys	   <genexpr>N   s    (   R*   R,   R   (   R	   t   possibleR   (    (   R&   R	   s2   /tmp/pip-build-hU8Cw8/coverage/coverage/results.pyt   arcs_missingI   s    c         C   s    |  j  ƒ  } |  j } t t | ƒ ƒ } g  } xc | D][ \ } } xL t | ƒ D]> } | | k rM | j d | | d k r} | n d f ƒ qM qM Wq4 Wd j | ƒ S(   sä   The missing branch arcs, formatted nicely.

        Returns a string like "1->2, 1->3, 16->20". Omits any mention of
        branches from missing lines, so if line 17 is missing, then 17->18
        won't be included.

        s   %d->%si    t   exits   , (   R!   R   R   R    t   appendt   join(   R	   R   R   t
   line_exitst   pairst   linet   exitst   ex(    (    s2   /tmp/pip-build-hU8Cw8/coverage/coverage/results.pyt   arcs_missing_formattedT   s    	4c            s8   |  j  ƒ  ‰  |  j ƒ  } ‡  f d †  | Dƒ } t | ƒ S(   sA   Returns a sorted list of the executed arcs missing from the code.c         3   sU   |  ]K } | ˆ  k r | d  | d k r | d  d  k sI | d d  k r | Vq d S(   i    i   N(    (   R   t   e(   R.   (    s2   /tmp/pip-build-hU8Cw8/coverage/coverage/results.pys	   <genexpr>p   s    (   R*   R,   R   (   R	   R&   t   unpredicted(    (   R.   s2   /tmp/pip-build-hU8Cw8/coverage/coverage/results.pyt   arcs_unpredictedf   s    c         C   s2   g  t  |  j ƒ D] \ } } | d k r | ^ q S(   s<   Returns a list of line numbers that have more than one exit.i   (   R    R   (   R	   t   l1t   count(    (    s2   /tmp/pip-build-hU8Cw8/coverage/coverage/results.pyt   branch_linesw   s    c         C   s   t  d „  |  j j ƒ  Dƒ ƒ S(   s"   How many total branches are there?c         s   s!   |  ] } | d  k r | Vq d S(   i   N(    (   R   R=   (    (    s2   /tmp/pip-build-hU8Cw8/coverage/coverage/results.pys	   <genexpr>}   s    (   R"   R   t   values(   R	   (    (    s2   /tmp/pip-build-hU8Cw8/coverage/coverage/results.pyR    {   s    c         C   sh   |  j  ƒ  } t |  j ƒ  ƒ } t j t ƒ } x4 | D], \ } } | | k r4 | | j | ƒ q4 q4 W| S(   sg   Return arcs that weren't executed from branch lines.

        Returns {l1:[l2a,l2b,...], ...}

        (   R/   R#   R>   t   collectionst   defaultdictt   listR1   (   R	   R   R>   R'   R<   t   l2(    (    s2   /tmp/pip-build-hU8Cw8/coverage/coverage/results.pyR!      s    c         C   s|   |  j  ƒ  } i  } xc |  j ƒ  D]U } |  j | } y t | | ƒ } Wn t k
 r_ d } n X| | | f | | <q W| S(   s   Get stats about branches.

        Returns a dict mapping line numbers to a tuple:
        (total_exits, taken_exits).
        i    (   R!   R>   R   R   t   KeyError(   R	   t   missing_arcst   statst   lnumR6   R   (    (    s2   /tmp/pip-build-hU8Cw8/coverage/coverage/results.pyt   branch_stats   s    
(   t   __name__t
   __module__t   __doc__R(   R)   R   R*   R,   R/   R8   R;   R>   R    R!   RH   (    (    (    s2   /tmp/pip-build-hU8Cw8/coverage/coverage/results.pyR      s   	$										R$   c           B   sÂ   e  Z d  Z d Z d Z d Z d d d d d d d d „ Z d „  Z e d „  ƒ Z	 e
 d „  ƒ Z e
 d „  ƒ Z e
 d	 „  ƒ Z e
 d
 „  ƒ Z e d „  ƒ Z e
 d „  ƒ Z d „  Z d „  Z RS(   sœ   The numerical results of measuring coverage.

    This holds the basic statistics from `Analysis`, and is used to roll
    up statistics across files.

    i    g      ð?g     ÀX@c         C   sC   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ d  S(   N(   R
   R   R   R   R   R   R   (   R	   R
   R   R   R   R   R   R   (    (    s2   /tmp/pip-build-hU8Cw8/coverage/coverage/results.pyR(   ­   s    						c         C   s.   |  j  |  j |  j |  j |  j |  j |  j g S(   s:   Return a list for __init__(*args) to recreate this object.(   R
   R   R   R   R   R   R   (   R	   (    (    s2   /tmp/pip-build-hU8Cw8/coverage/coverage/results.pyt	   init_args¸   s    c         C   sP   d | k o d k  n s" t  ‚ | |  _ d d | |  _ d |  j |  _ d S(   s<   Set the number of decimal places used to report percentages.i    i
   g      ð?g      Y@N(   t   AssertionErrort
   _precisiont   _near0t   _near100(   t   clst	   precision(    (    s2   /tmp/pip-build-hU8Cw8/coverage/coverage/results.pyt   set_precision¿   s    "	c         C   s   |  j  |  j S(   s*   Returns the number of executed statements.(   R   R   (   R	   (    (    s2   /tmp/pip-build-hU8Cw8/coverage/coverage/results.pyt
   n_executedÇ   s    c         C   s   |  j  |  j S(   s(   Returns the number of executed branches.(   R   R   (   R	   (    (    s2   /tmp/pip-build-hU8Cw8/coverage/coverage/results.pyt   n_executed_branchesÌ   s    c         C   s9   |  j  d k r/ |  j \ } } d | | } n d } | S(   s/   Returns a single percentage value for coverage.i    g      Y@(   R   t   ratio_covered(   R	   t	   numeratort   denominatort   pc_cov(    (    s2   /tmp/pip-build-hU8Cw8/coverage/coverage/results.pyt
   pc_coveredÑ   s
    c         C   s‚   |  j  } d | k  o# |  j k  n r4 |  j } n= |  j | k  oN d k  n r_ |  j } n t | |  j ƒ } d |  j | f S(   s  Returns the percent covered, as a string, without a percent sign.

        Note that "0" is only returned when the value is truly zero, and "100"
        is only returned when the value is truly 100.  Rounding can never
        result in either "0" or "100".

        i    id   s   %.*f(   RZ   RO   RP   t   roundRN   (   R	   t   pc(    (    s2   /tmp/pip-build-hU8Cw8/coverage/coverage/results.pyt   pc_covered_strÛ   s    		c         C   s-   d } |  j  d k r) | d |  j  7} n  | S(   s/   How many characters wide can pc_covered_str be?i   i    i   (   RN   (   RQ   t   width(    (    s2   /tmp/pip-build-hU8Cw8/coverage/coverage/results.pyt   pc_str_widthí   s    c         C   s*   |  j  |  j } |  j |  j } | | f S(   s:   Return a numerator and denominator for the coverage ratio.(   RT   RU   R   R   (   R	   RW   RX   (    (    s2   /tmp/pip-build-hU8Cw8/coverage/coverage/results.pyRV   õ   s    c         C   s’   t  ƒ  } |  j | j | _ |  j | j | _ |  j | j | _ |  j | j | _ |  j | j | _ |  j | j | _ |  j | j | _ | S(   N(   R$   R
   R   R   R   R   R   R   (   R	   t   othert   nums(    (    s2   /tmp/pip-build-hU8Cw8/coverage/coverage/results.pyt   __add__ü   s    	c         C   s   | d k r |  St  S(   Ni    (   t   NotImplemented(   R	   R`   (    (    s2   /tmp/pip-build-hU8Cw8/coverage/coverage/results.pyt   __radd__  s    (   RI   RJ   RK   RN   RO   RP   R(   RL   t   classmethodRS   t   propertyRT   RU   RZ   R]   R_   RV   Rb   Rd   (    (    (    s2   /tmp/pip-build-hU8Cw8/coverage/coverage/results.pyR$       s    
	
	c         C   sN   | rJ d |  k  o d k  n r+ d }  n t  |  ƒ }  |  | k  rJ t Sn  t S(   sÚ   Determine if a total should fail due to fail-under.

    `total` is a float, the coverage measurement total. `fail_under` is the
    fail_under setting to compare with.

    Returns True if the total should fail.

    ic   id   (   R[   t   Truet   False(   t   totalt
   fail_under(    (    s2   /tmp/pip-build-hU8Cw8/coverage/coverage/results.pyt   should_fail_under  s    
	(   RK   R@   t   coverage.backwardR    t   coverage.miscR   R   t   objectR   R$   Rk   (    (    (    s2   /tmp/pip-build-hU8Cw8/coverage/coverage/results.pyt   <module>   s   ”r