• File: manager.cpython-37.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/opt/alt/python37/lib/python3.7/site-packages/nose/plugins/__pycache__/manager.cpython-37.pyc
  • Date Modified: 07/07/2021 11:30 PM
  • File size: 16.31 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit
B

9`<@sdZddlZddlZddlZddlZddlmZddlm	Z	ddl
Zddlm
Z
ddlmZddlmZyddlZWnddlZYnXyddlmZWnddlmZYnXd	d
ddd
gZeeZGdddeZGdddeZGdd
d
eZGdddZGdddeZGdddeZyddl Z Gdd	d	eeZ!Wn&e"k
rnGdd	d	eZ!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)StringIODefaultPluginManager
PluginManagerEntryPointPluginManagerBuiltinPluginManagerRestrictedPluginManagerc@sVeZdZdZeZddZddZddZdd	Z	d
dZ
dd
ZddZdddZ
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.
    cCslyt|j||_Wn(tk
r:td||jjfYnX|||_g|_x|D]}|||qTWdS)Nz%s is not a valid %s method)	getattr	interfacemethodAttributeError__name__makeCallcallplugins	addPlugin)selfrrprE/opt/alt/python37/lib/python3.7/site-packages/nose/plugins/manager.py__init__Ws
zPluginProxy.__init__cOs|j||S)N)r)rargkwrrr__call__bszPluginProxy.__call__csVt||d}|dk	rR|dkrBtt|ddkrB|fdd}|j||fdS)z`Add plugin to my list of plugins to call, if it has the attribute
        I'm bound to.
        NZloadTestsFromModulercs|S)Nr)modulepathkwargs)	orig_methrr<lambda>nz'PluginProxy.addPlugin.<locals>.<lambda>)rleninspectZ
getargspecrappend)rpluginrmethr)r#rreszPluginProxy.addPlugincsH|dkrjSj}t|ddr,fddSt|ddr>jSjSdS)NZloadTestsFromNames
generativeFcstj||S)N)listgenerate)rr)rrrr${r%z&PluginProxy.makeCall.<locals>.<lambda>Z	chainable)_loadTestsFromNamesrrrsimple)rrr*r)rrrqszPluginProxy.makeCallcOsZd}ddtt|jdg|D}x2|jD](\}}|||}|dd}||q*W|S)zCall 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.
        NcSsg|]\}}|r|qSrr).0staticarrr
<listcomp>sz%PluginProxy.chain.<locals>.<listcomp>Zstatic_args)ziprrrr()rrrresultr1rr*rrrrs
zPluginProxy.chainc
osxz|jD]p\}}d}y*|||}|dk	r<x|D]
}|Vq.WWqttfk
rXYqt}t|VwYqXqWdS)zFCall all plugins, yielding each item in each non-None result.
        N)rKeyboardInterrupt
SystemExitsysexc_infor)rrrrr*r5rexcrrrr-s


zPluginProxy.generatecOs.x(|jD]\}}|||}|dk	r|SqWdS)z?Call all plugins, returning the first non-None result.
        N)r)rrrrr*r5rrrr/s
zPluginProxy.simpleNcCsJg}x<|jD]2\}}|||d}|dk	r|\}}|r||qW||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)rextend)rnamesr Zsuiterr*r5Z
suite_partrrrr.szPluginProxy._loadTestsFromNames)N)r
__module____qualname____doc__rrrrrrrr-r/r.rrrrr
Nsr
c@sdeZdZdZeZddZddZddZdd	Z	d
dZ
dd
ZddZddZ
ddZddZdS)	NoPluginsz(Null Plugin manager that has no plugins.cCsd|_|_dS)Nr)_pluginsr)rrrrrszNoPlugins.__init__cCsdS)Nrr)rrrr__iter__szNoPlugins.__iter__cOsdS)Nr)rargskwdsrrr
_doNothingszNoPlugins._doNothingcOsdS)Nrr)rrDrErrr_emptyIteratorszNoPlugins._emptyIteratorcCs(t|j|}t|ddr|jS|jSdS)Nr+F)rrrGrF)rrrrrr__getattr__szNoPlugins.__getattr__cCs
tdS)N)NotImplementedError)rplugrrrrszNoPlugins.addPlugincCs
tdS)N)rI)rrrrr
addPluginsszNoPlugins.addPluginscCsdS)Nr)roptionsconfigrrr	configureszNoPlugins.configurecCsdS)Nr)rrrrloadPluginsszNoPlugins.loadPluginscCsdS)Nr)rrrrsortszNoPlugins.sortN)rr>r?r@rrrrCrFrGrHrrKrNrOrPrrrrrAsrAc@sveZdZdZeZdddZddZdd	Zd
dZ	ddd
Z
ddZddZddZ
ddZddZeeeddZdS)r	aBase 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.
    rNcCs2g|_d|_i|_|r |||dk	r.||_dS)Nr)rB
_extraplugins_proxiesrK
proxyClass)rrrSrrrrs
zPluginManager.__init__cCs<y
|j|Stk
r6|||j}||j|<YnX|S)N)rRKeyErrorrSrB)rrproxyrrrrHs
zPluginManager.__getattr__cCs
t|jS)N)iterr)rrrrrCszPluginManager.__iter__cs<t|dtfdd|jD|jdd<|j|dS)Nnamecs g|]}t|ddkr|qS)rWN)r)r0r)new_namerrr3sz+PluginManager.addPlugin.<locals>.<listcomp>)robjectrBr()rrJr)rXrrszPluginManager.addPlugincCs(||_xt||D]}||qWdS)zextraplugins 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)rQ	iterchainr)rrZextrapluginsrJrrrrKszPluginManager.addPluginscCsTtd||_td|j}|||dd|jD}||_|td|dS)zConfigure the set of plugins with the given options
        and config instance. After configuration, disabled plugins
        are removed from the plugins list.
        zConfiguring pluginsrNcSsg|]}|jr|qSr)enabled)r0rJrrrr3sz+PluginManager.configure.<locals>.<listcomp>zPlugins enabled: %sN)logdebugrMr
rBrrP)rrLrMZcfgr[rrrrNs

zPluginManager.configurecCsx|jD]}||qWdS)N)rQr)rrJrrrrO"szPluginManager.loadPluginscCst|jddddS)NcSst|ddS)NZscore)r)xrrrr$'r%z$PluginManager.sort.<locals>.<lambda>T)reverse)rrB)rrrrrP&szPluginManager.sortcCs|jS)N)rB)rrrr_get_plugins)szPluginManager._get_pluginscCsg|_||dS)N)rBrK)rrrrr_set_plugins,szPluginManager._set_pluginszPAccess the list of plugins managed by
                       this plugin manager)rN)rr)rr>r?r@r
rSrrHrCrrKrNrOrPrarbpropertyrrrrrr	s
	
	c@s^eZdZdZddZejfddZddZdd	Z	d
dZ
dd
ZddZddZ
ddZdS)ZeroNinePluginz>Proxy for 0.9 plugins, adapts 0.10 calls to 0.9 standard.
    cCs
||_dS)N)r))rr)rrrr8szZeroNinePlugin.__init__cCs|j||dS)N)r)Zadd_options)rparserenvrrrrL;szZeroNinePlugin.optionsc	Cst|jdsdSddlm}m}|\}}}t||rRt|jdsDdS|j|jSt||rzt|jdsldS|j|jS|j	}|j
|j||S)NaddErrorr)SkipTestDeprecatedTestaddSkip
addDeprecated)hasattrr)Znose.excrhri
issubclassrjtestrkcapturedOutputrg)	rrnerrrhriZecZevtbcaptrrrrg>s


zZeroNinePlugin.addErrorcCst|jdr|j|SdS)NloadTestsFromPath)rlr)rs)rfilenamerrrloadTestsFromFilePsz ZeroNinePlugin.loadTestsFromFilecCs0t|jdsdS|j}|j}|j|j|||S)N
addFailure)rlr)rotbinforvrn)rrnrprrrwrrrrvTs
zZeroNinePlugin.addFailurecCs*t|jdsdS|j}|j|j|dS)N
addSuccess)rlr)rorxrn)rrnrrrrrrx\szZeroNinePlugin.addSuccesscCst|jdsdS|j|jS)N	startTest)rlr)ryrn)rrnrrrrybszZeroNinePlugin.startTestcCst|jdsdS|j|jS)NstopTest)rlr)rzrn)rrnrrrrzgszZeroNinePlugin.stopTestcCst|j|S)N)rr))rvalrrrrHlszZeroNinePlugin.__getattr__N)rr>r?r@rosenvironrLrgrurvrxryrzrHrrrrrd5srdcs,eZdZdZddeffZfddZZS)r
zhPlugin manager that loads plugins from the `nose.plugins` and
    `nose.plugins.0.10` entry points.
    )znose.plugins.0.10Nznose.pluginsc	sddlm}i}x|jD]\}}x||D]}|j|kr:q*d||j<td|jj|y|}WnJt	k
rxYn6t
k
r}ztd||ftw*Wdd}~XYnX|r||}n|}|
|q*WqWtt|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_pointsrWr\r]	__class__rloadr6	ExceptionrRuntimeWarningrsuperr
rO)	rr~ZloadedZentry_pointZadaptZepZplugclserJ)rrrrOws*

z#EntryPointPluginManager.loadPlugins)rr>r?r@rdrrO
__classcell__rr)rrr
ps
cs eZdZdZfddZZS)rzSPlugin manager that loads plugins from the list in
    `nose.plugins.builtin`.
    cs:ddlm}x|jD]}||qWtt|dS)z-Load plugins in nose.plugins.builtin
        r)builtinN)Znose.pluginsrrrrrrO)rrrJ)rrrrOsz BuiltinPluginManager.loadPlugins)rr>r?r@rOrrr)rrrsc@seZdZdS)rN)rr>r?rrrrrsc@seZdZdS)rN)rr>r?rrrrrsc@s*eZdZdZdddZddZdd	Zd
S)rzPlugin 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.
    rTcCs(t||||_||_g|_d|_dS)N)rrrexcludeexcluded
_excludedOpts)rrrrrrrrs
z RestrictedPluginManager.__init__cCsR|jdkrBddlm}|dd|_x|jD]}|j|jidq*W|jd|S)Nr)OptionParserF)Zadd_help_option)rfz--)rZoptparserrrLZ
get_option)rrWrr)rrrexcludedOptions
z&RestrictedPluginManager.excludedOptioncCsl|jrt|g}xL|jD]B}d}x*|jD] }t||r,d}|j|Pq,W|r||qW||_dS)NTF)rrrOrrrlrr()rZallowr)okrrrrrOs

z#RestrictedPluginManager.loadPluginsN)rrT)rr>r?r@rrrOrrrrrs
)$r@r'Zloggingr|r8	itertoolsrrZwarningsrZnose.configZnoseZnose.failurerZnose.plugins.baserZnose.pyversionrpickleior__all__Z	getLoggerrr\rYr
rAr	rdr
rrrImportErrorrrrrr<module>2sB
m&T;%