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__/manager.cpython-35.pyc



�^�]�<�@s�dZddlZddlZddlZddlZddlmZddlm	Z	ddl
Zddlm
Z
ddlmZddlmZyddlZWnddlZYnXyddlmZWnddlmZYnXd	d
ddd
gZeje�ZGdd�de�ZGdd�de�ZGdd
�d
e�ZGdd�d�ZGdd�de�ZGdd�de�Zy)ddl Z Gdd	�d	ee�Z!Wn(e"k
r�Gdd	�d	e�Z!YnXGdd
�d
e!�Z#dS)a
Plugin Manager
--------------

A plugin manager class is used to load plugins, manage the list of
loaded plugins, and proxy calls to those plugins.

The plugin managers provided with nose are:

:class:`PluginManager`
    This manager doesn't implement loadPlugins, so it can only work
    with a static list of plugins.

:class:`BuiltinPluginManager`
    This manager loads plugins referenced in ``nose.plugins.builtin``.

:class:`EntryPointPluginManager`
    This manager uses setuptools entrypoints to load plugins.

:class:`ExtraPluginsPluginManager`
    This manager loads extra plugins specified with the keyword
    `addplugins`.

:class:`DefaultPluginMananger`
    This is the manager class that will be used by default. If
    setuptools is installed, it is a subclass of
    :class:`EntryPointPluginManager` and :class:`BuiltinPluginManager`;
    otherwise, an alias to :class:`BuiltinPluginManager`.

:class:`RestrictedPluginManager`
    This manager is for use in test runs where some plugin calls are
    not available, such as runs started with ``python setup.py test``,
    where the test runner is the default unittest :class:`TextTestRunner`. It
    is a subclass of :class:`DefaultPluginManager`.

Writing a plugin manager
========================

If you want to load plugins via some other means, you can write a
plugin manager and pass an instance of your plugin manager class when
instantiating the :class:`nose.config.Config` instance that you pass to
:class:`TestProgram` (or :func:`main` or :func:`run`).

To implement your plugin loading scheme, implement ``loadPlugins()``,
and in that method, call ``addPlugin()`` with an instance of each plugin
you wish to make available. Make sure to call
``super(self).loadPlugins()`` as well if have subclassed a manager
other than ``PluginManager``.

�N)�chain)�warn)�Failure)�IPluginInterface)�	sort_list)�StringIO�DefaultPluginManager�
PluginManager�EntryPointPluginManager�BuiltinPluginManager�RestrictedPluginManagerc@seZdZdZeZdd�Zdd�Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�Zddd�Z
dS)�PluginProxya#Proxy for plugin calls. Essentially a closure bound to the
    given call and plugin list.

    The plugin proxy also must be bound to a particular plugin
    interface specification, so that it knows what calls are available
    and any special handling that is required for each call.
    cCs�yt|j|�|_Wn.tk
rItd||jjf��YnX|j|�|_g|_x|D]}|j||�qlWdS)Nz%s is not a valid %s method)	�getattr�	interface�method�AttributeError�__name__�makeCall�call�plugins�	addPlugin)�selfrr�p�r�E/opt/alt/python35/lib/python3.5/site-packages/nose/plugins/manager.py�__init__Ws
	
zPluginProxy.__init__cOs|j||�S)N)r)r�arg�kwrrr�__call__bszPluginProxy.__call__cs{t||d�}|dk	rw|dkrattj|�d�dkra|��fdd�}|jj||f�dS)z`Add plugin to my list of plugins to call, if it has the attribute
        I'm bound to.
        N�loadTestsFromModuler�cs
�|�S)Nr)�module�path�kwargs)�	orig_methrr�<lambda>nsz'PluginProxy.addPlugin.<locals>.<lambda>)r�len�inspect�
getargspecr�append)r�pluginr�methr)r$rreszPluginProxy.addPlugincsb|dkr�jS�j}t|dd�r>�fdd�St|dd�rW�jS�jSdS)N�loadTestsFromNames�
generativeFcst�j||��S)N)�list�generate)rr)rrrr%{sz&PluginProxy.makeCall.<locals>.<lambda>Z	chainable)�_loadTestsFromNamesrrr�simple)rrr+r)rrrqs	zPluginProxy.makeCallcOs{d}dd�tt|jdg�|�D�}xC|jD]8\}}|||�}|dd�}|j|�q;W|S)z�Call plugins in a chain, where the result of each plugin call is
        sent to the next plugin as input. The final output result is returned.
        NcSs"g|]\}}|r|�qSrr)�.0�static�arrr�
<listcomp>�s		z%PluginProxy.chain.<locals>.<listcomp>Zstatic_args)�ziprrrr))rrr�resultr3rr+rrrr�s	"zPluginProxy.chainc
os�x�|jD]�\}}d}y5|||�}|dk	rPx|D]}|VqAWWq
ttfk
rn�Yq
tj�}t|�Vw
Yq
Xq
WdS)zFCall all plugins, yielding each item in each non-None result.
        N)r�KeyboardInterrupt�
SystemExit�sys�exc_infor)rrrrr+r7�r�excrrrr/�s

zPluginProxy.generatecOs=x6|jD]+\}}|||�}|dk	r
|Sq
WdS)z?Call all plugins, returning the first non-None result.
        N)r)rrrrr+r7rrrr1�szPluginProxy.simpleNcCsgg}xT|jD]I\}}||d|�}|dk	r|\}}|r|j|�qW||fS)a
Chainable but not quite normal. Plugins return a tuple of
        (tests, names) after processing the names. The tests are added
        to a suite that is accumulated throughout the full call, while
        names are input for the next plugin in the chain.
        r!N)r�extend)r�namesr!�suiterr+r7Z
suite_partrrrr0�szPluginProxy._loadTestsFromNames)r�
__module__�__qualname__�__doc__rrrrrrrr/r1r0rrrrr
Nsr
c@s�eZdZdZeZdd�Zdd�Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dd�Zdd�ZdS)�	NoPluginsz(Null Plugin manager that has no plugins.cCsf|_|_dS)N)�_pluginsr)rrrrr�szNoPlugins.__init__cCsfS)Nr)rrrr�__iter__�szNoPlugins.__iter__cOsdS)Nr)r�args�kwdsrrr�
_doNothing�szNoPlugins._doNothingcOsfS)Nr)rrGrHrrr�_emptyIterator�szNoPlugins._emptyIteratorcCs6t|j|�}t|dd�r+|jS|jSdS)Nr-F)rrrJrI)rrrrrr�__getattr__�szNoPlugins.__getattr__cCs
t��dS)N)�NotImplementedError)r�plugrrrr�szNoPlugins.addPlugincCs
t��dS)N)rL)rrrrr�
addPlugins�szNoPlugins.addPluginscCsdS)Nr)r�options�configrrr�	configure�szNoPlugins.configurecCsdS)Nr)rrrr�loadPlugins�szNoPlugins.loadPluginscCsdS)Nr)rrrr�sort�szNoPlugins.sortN)rrArBrCrrrrFrIrJrKrrNrQrRrSrrrrrD�srDc@s�eZdZdZeZfddd�Zdd�Zdd�Zd	d
�Z	ffdd�Z
d
d�Zdd�Zdd�Z
dd�Zdd�Zeeedd�ZdS)r	a�Base class for plugin managers. PluginManager is intended to be
    used only with a static list of plugins. The loadPlugins() implementation
    only reloads plugins from _extraplugins to prevent those from being
    overridden by a subclass.

    The basic functionality of a plugin manager is to proxy all unknown
    attributes through a ``PluginProxy`` to a list of plugins.

    Note that the list of plugins *may not* be changed after the first plugin
    call.
    NcCsGg|_f|_i|_|r.|j|�|dk	rC||_dS)N)rE�
_extraplugins�_proxiesrN�
proxyClass)rrrVrrrr�s			
zPluginManager.__init__cCsJy|j|SWn4tk
rE|j||j�}||j|<YnX|S)N)rU�KeyErrorrVrE)rr�proxyrrrrK�s
zPluginManager.__getattr__cCs
t|j�S)N)�iterr)rrrrrFszPluginManager.__iter__csRt|dt����fdd�|jD�|jdd�<|jj|�dS)N�namecs.g|]$}t|dd��kr|�qS)rZN)r)r2r)�new_namerrr5s	z+PluginManager.addPlugin.<locals>.<listcomp>)r�objectrEr))rrMr)r[rrs)zPluginManager.addPlugincCs4||_x$t||�D]}|j|�qWdS)z�extraplugins are maintained in a separate list and
        re-added by loadPlugins() to prevent their being overwritten
        by plugins added by a subclass of PluginManager
        N)rT�	iterchainr)rrZextrapluginsrMrrrrNs	zPluginManager.addPluginscCsrtjd�||_td|j�}|||�dd�|jD�}||_|j�tjd|�dS)z�Configure the set of plugins with the given options
        and config instance. After configuration, disabled plugins
        are removed from the plugins list.
        zConfiguring pluginsrQcSsg|]}|jr|�qSr)�enabled)r2rMrrrr5s	z+PluginManager.configure.<locals>.<listcomp>zPlugins enabled: %sN)�log�debugrPr
rErrS)rrOrPZcfgr^rrrrQs
	
	
zPluginManager.configurecCs%x|jD]}|j|�q
WdS)N)rTr)rrMrrrrR"szPluginManager.loadPluginscCst|jdd�dd�S)NcSst|dd�S)N�score�)r)�xrrrr%'sz$PluginManager.sort.<locals>.<lambda>�reverseT)rrE)rrrrrS&szPluginManager.sortcCs|jS)N)rE)rrrr�_get_plugins)szPluginManager._get_pluginscCsg|_|j|�dS)N)rErN)rrrrr�_set_plugins,s	zPluginManager._set_pluginszPAccess the list of plugins managed by
                       this plugin manager)rrArBrCr
rVrrKrFrrNrQrRrSrerf�propertyrrrrrr	�s		c@s�eZdZdZdd�Zejdd�Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dd�ZdS)�ZeroNinePluginz>Proxy for 0.9 plugins, adapts 0.10 calls to 0.9 standard.
    cCs
||_dS)N)r*)rr*rrrr8szZeroNinePlugin.__init__cCs|jj||�dS)N)r*Zadd_options)r�parser�envrrrrO;szZeroNinePlugin.optionsc	Cs�t|jd�sdSddlm}m}|\}}}t||�rst|jd�s`dS|jj|j�St||�r�t|jd�s�dS|jj|j�S|j	}|jj
|j||�S)N�addErrorr)�SkipTest�DeprecatedTest�addSkip�
addDeprecated)�hasattrr*Znose.excrlrm�
issubclassrn�testro�capturedOutputrk)	rrr�errrlrmZecZev�tb�captrrrrk>s	zZeroNinePlugin.addErrorcCs&t|jd�r"|jj|�SdS)N�loadTestsFromPath)rpr*rw)r�filenamerrr�loadTestsFromFilePsz ZeroNinePlugin.loadTestsFromFilecCsDt|jd�sdS|j}|j}|jj|j|||�S)N�
addFailure)rpr*rs�tbinforzrr)rrrrtrvr{rrrrzTs
		zZeroNinePlugin.addFailurecCs9t|jd�sdS|j}|jj|j|�dS)N�
addSuccess)rpr*rsr|rr)rrrrvrrrr|\s	zZeroNinePlugin.addSuccesscCs)t|jd�sdS|jj|j�S)N�	startTest)rpr*r}rr)rrrrrrr}bszZeroNinePlugin.startTestcCs)t|jd�sdS|jj|j�S)N�stopTest)rpr*r~rr)rrrrrrr~gszZeroNinePlugin.stopTestcCst|j|�S)N)rr*)r�valrrrrKlszZeroNinePlugin.__getattr__N)rrArBrCr�os�environrOrkryrzr|r}r~rKrrrrrh5srhcs:eZdZdZddeffZ�fdd�Z�S)r
zhPlugin manager that loads plugins from the `nose.plugins` and
    `nose.plugins.0.10` entry points.
    �nose.plugins.0.10Nznose.pluginsc	s*ddlm}i}x�|jD]�\}}x�||�D]�}|j|krQq9d||j<tjd|jj|�y|j�}WnSt	k
r��Yn?t
k
r�}ztd||ft�w9WYdd}~XnX|r�||��}n	|�}|j
|�q9Wq Wtt|�j�dS)zBLoad plugins by iterating the `nose.plugins` entry point.
        r)�iter_entry_pointsTz%s load plugin %szUnable to load plugin %s: %sN)�
pkg_resourcesr��entry_pointsrZr_r`�	__class__r�loadr8�	Exceptionr�RuntimeWarningr�superr
rR)	rr�ZloadedZentry_pointZadapt�epZplugcls�erM)r�rrrRws*

	z#EntryPointPluginManager.loadPlugins)r�N)rrArBrCrhr�rRrr)r�rr
pscs(eZdZdZ�fdd�Z�S)rzSPlugin manager that loads plugins from the list in
    `nose.plugins.builtin`.
    csKddlm}x!|jD]}|j|��qWtt|�j�dS)z-Load plugins in nose.plugins.builtin
        r)�builtinN)Znose.pluginsr�rrr�rrR)rr�rM)r�rrrR�sz BuiltinPluginManager.loadPlugins)rrArBrCrRrr)r�rr�sc@seZdZdS)rN)rrArBrrrrr�sc@seZdZdS)rN)rrArBrrrrr�sc@sCeZdZdZffddd�Zdd�Zdd�Zd	S)
rz�Plugin manager that restricts the plugin list to those not
    excluded by a list of exclude methods. Any plugin that implements
    an excluded method will be removed from the manager's plugin list
    after plugins are loaded.
    TcCs8tj||�||_||_g|_d|_dS)N)rrr��exclude�excluded�
_excludedOpts)rrr�r�rrrr�s
			z RestrictedPluginManager.__init__cCso|jdkr[ddlm}|dd�|_x'|jD]}|j|jdi�q;W|jjd|�S)Nr)�OptionParserZadd_help_optionFrjz--)r��optparser�r�rOZ
get_option)rrZr�r*rrr�excludedOption�sz&RestrictedPluginManager.excludedOptioncCs�|jrtj|�g}xd|jD]Y}d}x7|jD],}t||�r<d}|jj|�Pq<W|r&|j|�q&W||_dS)NTF)r�rrRrr�rpr�r))rZallowr*�okrrrrrR�s	
z#RestrictedPluginManager.loadPluginsN)rrArBrCrr�rRrrrrr�s)$rCr'�loggingr�r:�	itertoolsrr]�warningsrZnose.config�noseZnose.failurerZnose.plugins.baserZnose.pyversionr�pickle�ior�__all__�	getLoggerrr_r\r
rDr	rhr
rr�r�ImportErrorrrrrr�<module>2sB	m&T;%