B t `-ã@s^dZddlZddlZddlZddlZddlmZddlmZm Z e  e ¡Z Gdd„deƒZ dS)a°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 éN)ÚPlugin)ÚsrcÚtolistcsreZdZdZdZdZdZdZdZdZ iZ ‡fdd„Z ‡fdd„Z d d „Z d d „Zd d„Zdd„Zddd„Z‡ZS)ÚCoveragezL Activate a coverage report using Ned Batchelder's coverage module. FNéÈcs$tt|ƒ ||¡|jdd| d¡dddd|jdd | d ¡d d d |jdd d| d¡dd|jddd| d¡dd|jdd d| d¡dd|jdd | d¡ddd |jd d| d!d"¡d#d$d%d&|jd'd | d(¡d)d*d |jd+d | d,¡d-d.d |jd/d| d0d1¡d2d3d4d&d5S)6z. Add options to command line. z--cover-packageÚappendZNOSE_COVER_PACKAGEZPACKAGEÚcover_packageszBRestrict coverage output to selected packages [NOSE_COVER_PACKAGE])ÚactionÚdefaultÚmetavarÚdestÚhelpz --cover-eraseÚ store_trueZNOSE_COVER_ERASEÚ cover_erasez9Erase previously collected coverage statistics before run)r r r r z --cover-testsÚ cover_testsZNOSE_COVER_TESTSz:Include test modules in coverage report [NOSE_COVER_TESTS])r r r r z--cover-min-percentageÚstoreÚcover_min_percentageZNOSE_COVER_MIN_PERCENTAGEzLMinimum percentage of coverage for tests to pass [NOSE_COVER_MIN_PERCENTAGE]z--cover-inclusiveÚcover_inclusiveZNOSE_COVER_INCLUSIVEz»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]z --cover-htmlZNOSE_COVER_HTMLÚ cover_htmlz!Produce HTML coverage informationz--cover-html-dirZNOSE_COVER_HTML_DIRZcoverÚcover_html_dirZDIRz(Produce HTML coverage information in dir)r r r r r z--cover-branchesZNOSE_COVER_BRANCHESÚcover_branchesz@Include branch coverage in coverage report [NOSE_COVER_BRANCHES]z --cover-xmlZNOSE_COVER_XMLÚ cover_xmlz Produce XML coverage informationz--cover-xml-fileZNOSE_COVER_XML_FILEz coverage.xmlÚcover_xml_fileÚFILEz(Produce XML coverage information in fileN)ÚsuperrÚoptionsÚ add_optionÚget)ÚselfÚparserÚenv)Ú __class__©ú6/tmp/pip-unpacked-wheel-cjhnoqsi/nose/plugins/cover.pyr#sX  zCoverage.optionscs$y|j d¡Wntk r$YnXtt|ƒ ||¡|jr‚yddl}t|dƒsZt dƒ‚Wn$t k r€t   d¡d|_dSX||_ |j |_|j|_g|_|jrèt|jttfƒr¼|j}n|jg}x"dd „|DƒD]}|j |¡qÔW|j|_|jrt  d |j¡d|_|jr*|j|_t  d |j¡|j|_d|_ |j!rRt"|j! #d ¡ƒ|_$|j%rp|j&|_ t  d |j ¡|jr d|jd<|jd|j|j'|jd|_(d|j(_)|j'|j(_*|j( +d¡t  d¡tt,j- .¡ƒdd…|_/|jrt  d¡|j( 0¡|j( 1¡|j(j*s |j( 2¡|j( 3¡dS)z# Configure plugin. ÚactiverNÚcoveragez Unable to import coverage modulez8Coverage not available: unable to import coverage moduleFcSsg|] }t|ƒ‘qSr")r)Ú.0Úxr"r"r#ú ysz&Coverage.configure..z.Coverage report will include only packages: %sz#Will put HTML coverage report in %sú%z"Will put XML coverage report in %sT)Z auto_dataÚbranchZ data_suffixÚsourcez)#pragma[: ]+[nN][oO] [cC][oO][vV][eE][rR]zCoverage beginz1Clearing previously collected coverage statistics)4ÚstatusÚpopÚKeyErrorrrÚ configureZenabledr%ÚhasattrÚ ImportErrorÚlogÚerrorÚconfrÚ coverEraserÚ coverTestsÚ coverPackagesrÚ isinstanceÚlistÚtupleÚextendrÚcoverInclusiveÚinfoÚ coverHtmlDirrrÚdebugrZ coverBranchesÚ coverXmlFilerÚintÚrstripÚcoverMinPercentagerrZworkerÚ coverInstanceZ _warn_no_dataÚ is_workerÚexcludeÚsysÚmodulesÚkeysÚ skipModulesÚcombineZeraseÚloadÚstart)rrr4r%rÚpkgs)r!r"r#r/]sp             zCoverage.configurecOs |jjr|j ¡|j ¡dS)z7 Begin recording coverage information. N)rDrErLrM)rÚargsÚkwargsr"r"r#Ú beforeTestŸs zCoverage.beforeTestcOs |jjr|j ¡|j ¡dS)z6 Stop recording coverage information. N)rDrEÚstopÚsave)rrOrPr"r"r#Ú afterTest¨s zCoverage.afterTestc sÆt d¡ˆj ¡ˆj ¡ˆj ¡‡fdd„ttj  ¡ƒDƒ}t d|¡ˆjj ||dddl }ˆj rÆt d¡yˆj  |ˆj ¡Wn8|jjk rÄ}zt d t|ƒ¡Wdd}~XYnXˆjr(t d ¡yˆj |ˆj¡Wn:|jjk r&}zt d t|ƒ¡Wdd}~XYnXˆjrÂt ¡}ˆjj ||dd }d }t || ¡¡}|dkrzt || ¡¡}|r¸t| ¡dƒ} | ˆjkrÂt dˆj¡t d¡n t d¡dS)z. Output code coverage report. zCoverage reportcs g|]\}}ˆ ||¡r|‘qSr")ÚwantModuleCoverage)r&ÚnameÚmodule)rr"r#r(ºsz#Coverage.report..z&Coverage report will cover modules: %s)ÚfilerNzGenerating HTML coverage reportz"Failed to generate HTML report: %szGenerating XML coverage reportz!Failed to generate XML report: %sz@-------\s\w+\s+\d+\s+\d+(?:\s+\d+\s+\d+)?\s+(\d+)%\s+\d*\s{0,1}$zM-------\s[\w./]+\s+\d+\s+\d+(?:\s+\d+\s+\d+)?\s+(\d+)%(?:\s+[-\d, ]+)\s{0,1}$z3TOTAL Coverage did not reach minimum required: %d%%ézGNo total percentage was found in coverage output, something went wrong.)r2r?rDrRrKrSr9rGrHÚitemsÚreportr%r>Z html_reportÚmiscZCoverageExceptionÚwarningÚstrr@Z xml_reportrCÚioÚStringIOÚreÚsearchÚgetvaluerAÚgroupsr3Úexit) rÚstreamrHr%ÚeÚfZmultiPackageReZsinglePackageReÚmÚ percentager")rr#r[²sH       $ $    zCoverage.reportcCsØt|dƒst d|¡dSt|jƒ}|r2| d¡sBt d|¡dS|jr’xH|jD]>}t dt  |¡|¡rP|j s~|j j   |¡sPt d|¡dSqPW||jkr¬t d |¡dS|j j   |¡rÐ|j sÐt d |¡dS|j S) NÚ__file__zno coverage of %s: no __file__Fz.pyz$no coverage of %s: not a python filez^%s\bzcoverage for %sTz0no coverage for %s: loaded before coverage startzno coverage for %s: is a test)r0r2r?rrkÚendswithr7raÚfindallÚescaper6r4Z testMatchrbrJ)rrVrWZ module_fileÚpackager"r"r#rUès,        zCoverage.wantModuleCoveragecCsB|jr>| d¡r>|r:|jr:x"|jD]}| |¡r"dSq"WndSdS)zdIf inclusive coverage enabled, return true for all source files in wanted packages. z.pyTN)r<rlr7Ú startswith)rrXroZwantr"r"r#ÚwantFiles     zCoverage.wantFile)N)Ú__name__Ú __module__Ú __qualname__Ú__doc__r6r7rDr5rCZscorer,rr/rQrTr[rUrqÚ __classcell__r"r")r!r#rs : B  6r)ruÚloggingrarGr_Znose.plugins.baserZ nose.utilrrÚ getLoggerrrr2rr"r"r"r#Ú s