U e-@s^dZddlZddlZddlZddlZddlmZddlmZm Z e e Z GdddeZ dS)aIf 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)srctolistcsreZdZdZdZdZdZdZdZdZ iZ fddZ fddZ d d Z d d Zd dZddZdddZZS)CoveragezL Activate a coverage report using Ned Batchelder's coverage module. FNcs$tt||||jdd|ddddd|jdd |d d d d |jdd d|ddd|jddd|ddd|jdd d|ddd|jdd |dddd |jd d|d!d"d#d$d%d&|jd'd |d(d)d*d |jd+d |d,d-d.d |jd/d|d0d1d2d3d4d&d5S)6z. Add options to command line. z--cover-packageappendZNOSE_COVER_PACKAGEZPACKAGEcover_packageszBRestrict coverage output to selected packages [NOSE_COVER_PACKAGE])actiondefaultmetavardesthelpz --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-percentagestorecover_min_percentageZNOSE_COVER_MIN_PERCENTAGEzLMinimum percentage of coverage for tests to pass [NOSE_COVER_MIN_PERCENTAGE]z--cover-inclusivecover_inclusiveZNOSE_COVER_INCLUSIVEzInclude 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_DIRZcovercover_html_dirZDIRz(Produce HTML coverage information in dir)r r r r r z--cover-branchesZNOSE_COVER_BRANCHEScover_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.xmlcover_xml_fileFILEz(Produce XML coverage information in fileN)superroptions add_optionget)selfparserenv __class__@/opt/hc_python/lib/python3.8/site-packages/nose/plugins/cover.pyr#sl  zCoverage.optionscs"z|jdWntk r$YnXtt||||jrzddl}t|dsZt dWn&t k rt dd|_YdSX||_ |j |_|j|_g|_|jrt|jttfr|j}n|jg}dd |DD]}|j|q|j|_|jrt d |jd|_|jr(|j|_t d |j|j|_d|_ |j!rPt"|j!#d |_$|j%rn|j&|_ t d |j |jrd|jd<|jd|j|j'|jd|_(d|j(_)|j'|j(_*|j(+dt dtt,j-.dd|_/|jrt d|j(0|j(1|j(j*s|j(2|j(3dS)z# Configure plugin. activerNcoveragez Unable to import coverage modulez8Coverage not available: unable to import coverage moduleFcSsg|] }t|qSr#)r).0xr#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_databranchZ data_suffixsourcez)#pragma[: ]+[nN][oO] [cC][oO][vV][eE][rR]zCoverage beginz1Clearing previously collected coverage statistics)4statuspopKeyErrorrr configureenabledr&hasattr ImportErrorlogerrorconfr coverEraser coverTests coverPackagesr isinstancelisttupleextendrcoverInclusiveinfo coverHtmlDirrrdebugrZ coverBranches coverXmlFilerintrstripcoverMinPercentagerrZworker coverInstanceZ _warn_no_data is_workerexcludesysmoduleskeys skipModulescombineZeraseloadstart)rrr6r&rpkgsr!r#r$r0]sv            zCoverage.configurecOs |jjr|j|jdS)z7 Begin recording coverage information. N)rFrGrNrOrargskwargsr#r#r$ beforeTests zCoverage.beforeTestcOs |jjr|j|jdS)z6 Stop recording coverage information. N)rFrGstopsaverQr#r#r$ afterTests zCoverage.afterTestc stdjjjfddttj D}td|jj ||dddl }j rtdzj |j Wn8|jjk r}ztd t|W5d}~XYnXjr(td zj|jWn:|jjk r&}ztd t|W5d}~XYnXjrt}jj ||dd }d }t||}|dkrzt||}|rt|d} | jkrtdjtdn tddS)z. Output code coverage report. zCoverage reportcs g|]\}}||r|qSr#)wantModuleCoverage)r'namemodulerr#r$r)s z#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.)r4rArFrUrMrVr;rIrJitemsreportr&r@Z html_reportmiscZCoverageExceptionwarningstrrBZ xml_reportrEioStringIOresearchgetvaluerCgroupsr5exit) rstreamrJr&efZmultiPackageReZsinglePackageRem percentager#r[r$r_sL        $ $   zCoverage.reportcCst|dstd|dSt|j}|r2|dsBtd|dS|jr|jD]@}tdt ||rN|j s||j j |sNtd|dSqN||jkrtd |dS|j j |r|j std |dS|j S) N__file__zno coverage of %s: no __file__F.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)r2r4rArroendswithr9refindallescaper8r6Z testMatchrfrL)rrYrZZ module_filepackager#r#r$rXs2         zCoverage.wantModuleCoveragecCs@|jr<|dr<|r8|jr8|jD]}||r dSq ndSdS)zdIf inclusive coverage enabled, return true for all source files in wanted packages. rpTN)r>rqr9 startswith)rr\rtZwantr#r#r$wantFiles     zCoverage.wantFile)N)__name__ __module__ __qualname____doc__r8r9rFr7rEZscorer-rr0rTrWr_rXrv __classcell__r#r#r!r$rs : B  6r)rzloggingrerIrcZnose.plugins.baserZ nose.utilrr getLoggerrwr4rr#r#r#r$s