U VF@sdZddlmZddlZddlZddlZddlZeeZ Gdddej Z Gdddej Z zddl mZd Ze ZWnek rd Ze ZYnXdS) asetuptools/distutils commands to run testr via setup.py Currently provides 'testr' which runs tests using testr. You can pass --coverage which will also export PYTHON='coverage run --source ' and automatically combine the coverage from each testr backend test runner after the run completes. To use, just use setuptools/distribute and depend on testr, and it should be picked up automatically (as the commands are exported in the testrepository package metadata. )cmdNc@s\eZdZdZdddddddgZd d d gZd d ZddZddZddZ ddZ ddZ dS) TestrRealRun unit tests using testr)coverageNzGReplace PYTHON with coverage and merge coverage from each testr worker.)z testr-args=tzRun 'testr' with these args)zomit=oz(Files to omit from coverage calculations)zcoverage-package-name=Nz"Use this name for coverage package)slowestNz-Show slowest test times after tests complete.)z no-parallelNzRun testr serially)z log-level=lzLog level (default: info)rr no_parallelcGs2td|ttjdgt|tjtjtj S)Nz _run_testr called with args = %rr) loggerdebugcommandsZrun_argvsysargvliststdinstdoutstderr)selfargsr/testr_command.py _run_testrCs  zTestrReal._run_testrcCs.d|_d|_d|_d|_d|_d|_d|_dS)Ninfo) testr_argsromitrcoverage_package_namer log_levelrrrrinitialize_optionsHszTestrReal.initialize_optionscCsptt|jtj|_tj|jdtd|jdkr@g|_n |j |_|j r^d|j |_ td|j dS)N)levelzfinalize_options calledz --omit=%sz$finalize_options: self.__dict__ = %r) getattrloggingrupperINFOZ basicConfigr r rsplitr__dict__rrrrfinalize_optionsQs    zTestrReal.finalize_optionscCstdtjds |d|jr.||jsF|jd |j }n|jd |j }|rjt j d||j rtd|d|jr|d S) z"Set up testr repo, then run testr.z run calledz.testrepositoryZinitrun --parallelztestr failed (%d)z Slowest TestsrN)r)r*)r))r r ospathisdirrr_coverage_beforer r distutilserrorsZDistutilsErrorrprint_coverage_after)rZ testr_retrrrr)`s"    z TestrReal.runcCsbtd|j}|dr*|dd}|jr6|j}d|}d|tjd<tdtjddS)Nz_coverage_before calledzpython-z--source %s --parallel-modezcoverage run %sZPYTHONzos.environ['PYTHON'] = %r)r r Z distributionZget_name startswithrr+environ)rpackageZoptionsrrrr.us    zTestrReal._coverage_beforecCs(tdtdtd|jdS)Nz_coverage_after calledzcoverage combinezcoverage html -d ./cover %s)r r r+systemrrrrrr2s  zTestrReal._coverage_afterN) __name__ __module__ __qualname__ description user_optionsZboolean_optionsrr r(r)r.r2rrrrr2s    rc@s,eZdZdZgZddZddZddZdS) TestrFakercCsdSNrrrrrr szTestrFake.initialize_optionscCsdSr>rrrrrr(szTestrFake.finalize_optionscCs tddS)Nz7Install testrepository to run 'testr' command properly.)r1rrrrr)sz TestrFake.runN)r8r9r:r;r<r r(r)rrrrr=s r=)r TF)__doc__r/rZdistutils.errorsr#r+rZ getLoggerr8r ZCommandrr=Ztestrepositoryr Z have_testrZTestr ImportErrorrrrrs  V