B t `@sdZyddlZddlmZWnek r8d\ZZYnXddlZddlZddlZddlZddlm Z ddl m Z e dZ Gdd d e ZdS) a/This plugin will run tests using the hotshot profiler, which is part of the standard library. To turn it on, use the ``--with-profile`` option or set the NOSE_WITH_PROFILE environment variable. Profiler output can be controlled with the ``--profile-sort`` and ``--profile-restrict`` options, and the profiler output file may be changed with ``--profile-stats-file``. See the `hotshot documentation`_ in the standard library documentation for more details on the various output options. .. _hotshot documentation: http://docs.python.org/library/hotshot.html N)stats)NN)Plugin)tolistz nose.pluginsc@s`eZdZdZdZdZddZddZeeZdd Z d d Z d d Z ddZ ddZ ddZdS)ProfilezC Use this plugin to run tests using the hotshot profiler. NFcCst|s dSt||||jddd|ddddd |jd dd d |d dd|jdddd|ddddS)z&Register commandline options. Nz--profile-sortstore profile_sortZNOSE_PROFILE_SORTZ cumulativeZSORTz"Set sort order for profiler output)actiondestdefaultmetavarhelpz--profile-stats-fileprofile_stats_fileFILEZNOSE_PROFILE_STATS_FILEz;Profiler stats file; default is a new temp file on each run)rr r r r z--profile-restrictappendprofile_restrictZRESTRICTZNOSE_PROFILE_RESTRICTz?Restrict profiler output. See help for pstats.Stats for details) availableroptions add_optionget)selfparserenvr5/tmp/pip-unpacked-wheel-cjhnoqsi/nose/plugins/prof.pyr!s"  zProfile.optionscCstdk S)N)hotshot)clsrrrr8szProfile.availablecCs&|s dS|t|j|_dS)z5Create profile stats file and load profiler. N)r _create_pfilerrpfileprof)rrrrbegin<sz Profile.begincCsf|sd|_dSt|||||_|jr<|j|_d|_n d|_d|_d|_|j |_ t |j |_ dS)zConfigure plugin. FNT)rZenabledr configureconfr rclean_stats_filefilenorsortrrrestrict)rrr!rrrr DszProfile.configurecs2s dStd|j|ffdd }|S)z6Wrap entire test run in :func:`prof.runcall`. Nzpreparing test %scs|||dS)N)rZruncall)resultrtest)rrrrun_and_profile\sz,Profile.prepareTest..run_and_profile)rlogdebugr)rr'r(r)rr prepareTestVs zProfile.prepareTestcCstd|jt|j}||jt |d}|rH|j }||_ n t j }|t _ z.|j rxtd|j |j|j n|Wd|r||_ n|t _ XdS)z Output profiler report. zprinting profiler reportstreamz"setting profiler restriction to %sN)r)r*rcloserloadrZ sort_statsr$hasattrr,sysstdoutr%Z print_stats)rr,Z prof_statsZ compat_25tmprrrreportas$      zProfile.reportcCs|s dSy|jWntk r.YnX|jr|jrbyt|jWntk r`YnXyt|j Wntk rYnXdS)z5Clean up stats file, if configured to do so. N) rrr-AttributeErrorr"r#osOSErrorunlinkr)rr&rrrfinalizes"zProfile.finalizecCs |jst\|_|_d|_dS)NT)rtempfilemkstempr#r")rrrrrszProfile._create_pfile)__name__ __module__ __qualname____doc__rr"rr classmethodrr r+r3r8rrrrrrs r)r>rr ImportErrorloggingr5r0r9Znose.plugins.baserZ nose.utilr getLoggerr)rrrrr s