Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib/python3.5/site-packages/nose/plugins/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib/python3.5/site-packages/nose/plugins/__pycache__/prof.cpython-35.pyc



�fP��@s�dZy ddlZddlmZWnek
rFd	\ZZYnXddlZddlZddlZddlZddlm	Z	ddl
mZejd�Z
Gdd�de	�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)�Plugin)�tolistznose.pluginsc@s�eZdZdZdZdZdd�Zdd�Zee�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dd�ZdS)�ProfilezC
    Use this plugin to run tests using the hotshot profiler. 
    NFcCs�|j�sdStj|||�|jdddddd|jdd	�d
ddd
�|jdddddd
dd|jd�dd�|jdddddd
dd|jd�dd�dS)z&Register commandline options.
        Nz--profile-sort�action�store�dest�profile_sort�defaultZNOSE_PROFILE_SORTZ
cumulative�metavarZSORT�helpz"Set sort order for profiler outputz--profile-stats-file�profile_stats_fileZFILEZNOSE_PROFILE_STATS_FILEz;Profiler stats file; default is a new temp file on each runz--profile-restrict�append�profile_restrictZRESTRICTZNOSE_PROFILE_RESTRICTz?Restrict profiler output. See help for pstats.Stats for details)�	availabler�options�
add_option�get)�self�parser�env�r�B/opt/alt/python35/lib/python3.5/site-packages/nose/plugins/prof.pyr!s"zProfile.optionscCs
tdk	S)N)�hotshot)�clsrrrr8szProfile.availablecCs3|j�sdS|j�tj|j�|_dS)z5Create profile stats file and load profiler.
        N)r�
_create_pfilerr�pfile�prof)rrrr�begin<s
z
Profile.begincCs�|j�sd|_dStj|||�||_|jrV|j|_d|_nd|_d|_d|_|j	|_
t|j�|_
dS)zConfigure plugin.
        FNT)r�enabledr�	configure�confr
r�clean_stats_file�filenor	�sortrr�restrict)rrr!rrrr Ds						zProfile.configurecs@�j�sdStjd|��j|�fdd�}|S)z6Wrap entire test run in :func:`prof.runcall`.
        Nzpreparing test %scs�j�|j||�dS)N)rZruncall)�resultr�test)rrr�run_and_profile\s
z,Profile.prepareTest.<locals>.run_and_profile)r�log�debugr)rr'r(r)rr�prepareTestVs
zProfile.prepareTestcCs�tjd�|jj�tj|j�}|j|j�t	|d�}|rf|j
}||_
ntj}|t_z=|j
r�tjd|j
�|j|j
�n
|j�Wd|r�||_
n	|t_XdS)z Output profiler report.
        zprinting profiler report�streamz"setting profiler restriction to %sN)r)r*r�closer�loadrZ
sort_statsr$�hasattrr,�sys�stdoutr%Zprint_stats)rr,Z
prof_statsZ	compat_25�tmprrr�reportas$

				zProfile.reportcCs�|j�sdSy|jj�Wntk
r5YnX|jr�|jrqytj|j�Wntk
rpYnXytj|j	�Wntk
r�YnXdS)z5Clean up stats file, if configured to do so.
        N)
rrr-�AttributeErrorr"r#�os�OSError�unlinkr)rr&rrr�finalizes"
		

zProfile.finalizecCs.|js*tj�\|_|_d|_dS)NT)r�tempfile�mkstempr#r")rrrrr�s	zProfile._create_pfile)�__name__�
__module__�__qualname__�__doc__rr"rr�classmethodrr r+r3r8rrrrrrsr)NN)r>rr�ImportError�loggingr5r0r9Znose.plugins.baserZ	nose.utilr�	getLoggerr)rrrrr�<module>s