U e@sdZzddlZddlmZWnek 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)selfparserenvr?/opt/hc_python/lib/python3.8/site-packages/nose/plugins/prof.pyr!s(  zProfile.optionscCstdk SN)hotshot)clsrrrr8szProfile.availablecCs&|s dS|t|j|_dS)z5Create profile stats file and load profiler. N)r _create_pfilerrpfileprofrrrrbegin<sz Profile.begincCsf|sd|_dSt|||||_|jr<|j|_d|_n d|_d|_d|_|j |_ t |j |_ dS)zConfigure plugin. FNT)renabledr configureconfr rclean_stats_filefilenorsortrrrestrict)rrr$rrrr#DszProfile.configurecs2s dStd|j|ffdd }|S)z6Wrap entire test run in :func:`prof.runcall`. Nzpreparing test %scs|||dSr)rZruncall)resultrtestr rrrun_and_profile\sz,Profile.prepareTest..run_and_profile)rlogdebugr)rr*r+rr r prepareTestVs zProfile.prepareTestcCstd|jt|j}||jt |d}|rH|j }||_ n t j }|t _ z.|j rxtd|j |j|j n|W5|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 dSz|jWntk r.YnX|jr|jrbzt|jWntk r`YnXzt|j Wntk rYnXdS)z5Clean up stats file, if configured to do so. N) rrr0AttributeErrorr%r&osOSErrorunlinkr)rr)rrrfinalizes"zProfile.finalizecCs |jst\|_|_d|_dS)NT)rtempfilemkstempr&r%r rrrrszProfile._create_pfile)__name__ __module__ __qualname____doc__rr%rr classmethodr!r#r.r6r;rrrrrrs r)rArr ImportErrorloggingr8r3r<Znose.plugins.baserZ nose.utilr getLoggerr,rrrrrs