ó
J9•Qc           @   s…   d  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	 e j
 e ƒ Z d e f d „  ƒ  YZ d S(   s°  If you have Ned Batchelder's coverage_ module installed, you may activate a
coverage report with the ``--with-coverage`` switch or NOSE_WITH_COVERAGE
environment variable. The coverage report will cover any python source module
imported after the start of the test run, excluding modules that match
testMatch. If you want to include those modules too, use the ``--cover-tests``
switch, or set the NOSE_COVER_TESTS environment variable to a true value. To
restrict the coverage report to modules from a particular package or packages,
use the ``--cover-package`` switch or the NOSE_COVER_PACKAGE environment
variable.

.. _coverage: http://www.nedbatchelder.com/code/modules/coverage.html
iÿÿÿÿN(   t   Plugin(   t   srct   tolistt   Coveragec           B   sq   e  Z d  Z e Z d Z d Z e Z d Z	 d Z
 i  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z RS(	   sL   
    Activate a coverage report using Ned Batchelder's coverage module.
    iÈ   c         C   s  t  t |  ƒ j | | ƒ | j d d d d | j d ƒ d d d d	 d
 d ƒ| j d d d d | j d ƒ d d d
 d ƒ| j d d d d d d | j d ƒ d
 d ƒ| j d d d d d d | j d ƒ d
 d ƒ| j d d d d d d | j d ƒ d
 d ƒ| j d d d d | j d ƒ d d  d
 d! ƒ| j d" d d d | j d# d$ ƒ d d% d d& d
 d' ƒ| j d( d d d | j d) ƒ d d* d
 d+ ƒ| j d, d d d | j d- ƒ d d. d
 d/ ƒ| j d0 d d d | j d1 d2 ƒ d d3 d d4 d
 d5 ƒd6 S(7   s.   
        Add options to command line.
        s   --cover-packaget   actiont   appendt   defaultt   NOSE_COVER_PACKAGEt   metavart   PACKAGEt   destt   cover_packagest   helpsB   Restrict coverage output to selected packages [NOSE_COVER_PACKAGE]s   --cover-eraset
   store_truet   NOSE_COVER_ERASEt   cover_erases9   Erase previously collected coverage statistics before runs   --cover-testst   cover_testst   NOSE_COVER_TESTSs:   Include test modules in coverage report [NOSE_COVER_TESTS]s   --cover-min-percentaget   storet   cover_min_percentaget   NOSE_COVER_MIN_PERCENTAGEsK   Minimum percentage of coverage for teststo pass [NOSE_COVER_MIN_PERCENTAGE]s   --cover-inclusivet   cover_inclusivet   NOSE_COVER_INCLUSIVEs»   Include all python files under working directory in coverage report.  Useful for discovering holes in test coverage if not all files are imported by the test suite. [NOSE_COVER_INCLUSIVE]s   --cover-htmlt   NOSE_COVER_HTMLt
   cover_htmls!   Produce HTML coverage informations   --cover-html-dirt   NOSE_COVER_HTML_DIRt   covert   cover_html_dirt   DIRs(   Produce HTML coverage information in dirs   --cover-branchest   NOSE_COVER_BRANCHESt   cover_branchess@   Include branch coverage in coverage report [NOSE_COVER_BRANCHES]s   --cover-xmlt   NOSE_COVER_XMLt	   cover_xmls    Produce XML coverage informations   --cover-xml-filet   NOSE_COVER_XML_FILEs   coverage.xmlt   cover_xml_filet   FILEs(   Produce XML coverage information in fileN(   t   superR   t   optionst
   add_optiont   get(   t   selft   parsert   env(    (    s6   /sys/lib/python2.7/site-packages/nose/plugins/cover.pyR%   #   sX    c         C   sZ  y |  j  j d ƒ Wn t k
 r' n Xt t |  ƒ j | | ƒ | j rN d S|  j r³ y. d d l } t	 | d ƒ s„ t
 d ƒ ‚ n  Wq³ t
 k
 r¯ t j d ƒ t |  _ d SXn  | |  _ | j |  _ | j |  _ g  |  _ | j rSt | j t t f ƒ r
| j } n | j g } x: g  | D] } t | ƒ ^ q D] } |  j j | ƒ q6Wn  | j |  _ |  j r~t j d |  j ƒ n  d |  _ | j r²| j  |  _ t j! d |  j ƒ n  | j" |  _# d |  _$ | j% rît& | j% j' d	 ƒ ƒ |  _( n  | j) r| j* |  _$ t j! d
 |  j$ ƒ n  |  j rVt+ |  j  d <| j d t d |  j# d d ƒ |  _, n  d S(   s#   
        Configure plugin.
        t   activeNiÿÿÿÿt   coverages    Unable to import coverage modules8   Coverage not available: unable to import coverage modules.   Coverage report will include only packages: %ss#   Will put HTML coverage report in %st   %s"   Will put XML coverage report in %st	   auto_datat   brancht   data_suffix(-   t   statust   popt   KeyErrorR$   R   t	   configuret   workert   enabledR,   t   hasattrt   ImportErrort   logt   errort   Falset   confR   t
   coverEraseR   t
   coverTestst   coverPackagesR   t
   isinstancet   listt   tupleR   t   extendR   t   coverInclusivet   infot   Nonet   coverHtmlDirR   R   t   debugR   t   coverBranchest   coverXmlFileR   t   intt   rstript   coverMinPercentageR    R"   t   Truet   coverInstance(   R(   R%   R<   R,   R   t   xt   pkgs(    (    s6   /sys/lib/python2.7/site-packages/nose/plugins/cover.pyR4   ]   sZ    						&								c         C   s   t  j d ƒ t j j ƒ  |  _ |  j rS t  j d ƒ |  j j ƒ  |  j j	 ƒ  n  |  j j
 d ƒ |  j j ƒ  |  j j ƒ  d S(   s7   
        Begin recording coverage information.
        s   Coverage begins1   Clearing previously collected coverage statisticss)   #pragma[: ]+[nN][oO] [cC][oO][vV][eE][rR]N(   R9   RH   t   syst   modulest   keyst   skipModulesR=   RO   t   combinet   eraset   excludet   loadt   start(   R(   (    (    s6   /sys/lib/python2.7/site-packages/nose/plugins/cover.pyt   begin‘   s    	c   
      C   sÎ  t  j d ƒ |  j j ƒ  |  j j ƒ  |  j j ƒ  g  t j j ƒ  D]$ \ } } |  j	 | | ƒ rD | ^ qD } t  j d | ƒ |  j j
 | d | ƒ|  j rÃ t  j d ƒ |  j j | |  j ƒ n  |  j rò t  j d ƒ |  j j | |  j ƒ n  |  j rÊt j ƒ  } |  j j
 | d | ƒd } d } t j | | j ƒ  ƒ } | d k rht j | | j ƒ  ƒ } n  | rºt | j ƒ  d ƒ }	 |	 |  j k  rÇt  j d	 |  j ƒ t j d
 ƒ qÇqÊt  j d ƒ n  d S(   s.   
        Output code coverage report.
        s   Coverage reports&   Coverage report will cover modules: %st   files   Generating HTML coverage reports   Generating XML coverage reports@   -------\s\w+\s+\d+\s+\d+(?:\s+\d+\s+\d+)?\s+(\d+)%\s+\d*\s{0,1}$sM   -------\s[\w./]+\s+\d+\s+\d+(?:\s+\d+\s+\d+)?\s+(\d+)%(?:\s+[-\d, ]+)\s{0,1}$i    s3   TOTAL Coverage did not reach minimum required: %d%%i   sG   No total percentage was found in coverage output, something went wrong.N(   R9   RH   RO   t   stopRV   t   saveRR   RS   t   itemst   wantModuleCoveraget   reportRG   t   html_reportRJ   t
   xml_reportRM   t   StringIOt   ret   searcht   getvalueRF   RK   t   groupsR:   t   exit(
   R(   t   streamt   namet   moduleRS   t   ft   multiPackageRet   singlePackageRet   mt
   percentage(    (    s6   /sys/lib/python2.7/site-packages/nose/plugins/cover.pyRa   Ÿ   s<    				c         C   s-  t  | d ƒ s# t j d | ƒ t St | j ƒ } | sI | j d ƒ r] t j d | ƒ t S|  j rÏ xf |  j D]X } t j	 d t j
 | ƒ | ƒ rp |  j s´ |  j j j | ƒ rp t j d | ƒ t Sqp Wn  | |  j k rò t j d | ƒ t S|  j j j | ƒ r%|  j r%t j d | ƒ t S|  j S(	   Nt   __file__s   no coverage of %s: no __file__s   .pys$   no coverage of %s: not a python files   ^%s\bs   coverage for %ss0   no coverage for %s: loaded before coverage starts   no coverage for %s: is a test(   R7   R9   RH   R;   R   Rr   t   endswithR?   Re   t   findallt   escapeR>   R<   t	   testMatchRf   RN   RU   (   R(   Rk   Rl   t   module_filet   package(    (    s6   /sys/lib/python2.7/site-packages/nose/plugins/cover.pyR`   Ì   s,    			c         C   s_   |  j  r[ | j d ƒ r[ | rQ |  j rQ x+ |  j D] } | j | ƒ r1 t Sq1 WqX t Sq[ n  d S(   sd   If inclusive coverage enabled, return true for all source files
        in wanted packages.
        s   .pyN(   RD   Rs   R?   t
   startswithRN   RF   (   R(   R\   Rx   t   want(    (    s6   /sys/lib/python2.7/site-packages/nose/plugins/cover.pyt   wantFileç   s    	
N(   t   __name__t
   __module__t   __doc__R;   R>   RF   R?   RO   R=   RM   t   scoreR1   R%   R4   R[   Ra   R`   R{   (    (    (    s6   /sys/lib/python2.7/site-packages/nose/plugins/cover.pyR      s   	:	4		-	(   R~   t   loggingRe   RR   Rd   t   nose.plugins.baseR    t	   nose.utilR   R   t	   getLoggerR|   R9   R   (    (    (    s6   /sys/lib/python2.7/site-packages/nose/plugins/cover.pyt   <module>   s   