Plan 9 from Bell Labs’s /usr/web/sources/contrib/jas/root/sys/lib/python2.7/site-packages/nose/plugins/attrib.pyc

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


�9�c@s�dZddlZddlZddlZddlZddlmZddlmZddlm	Z	ej
d�ZejdkZ
d	�Zed
�Zddd��YZd
efd��YZdS(sAttribute selector plugin.

Oftentimes when testing you will want to select tests based on
criteria rather then simply by filename. For example, you might want
to run all tests except for the slow ones. You can do this with the
Attribute selector plugin by setting attributes on your test methods.
Here is an example:

.. code-block:: python

    def test_big_download():
        import urllib
        # commence slowness...

    test_big_download.slow = 1

Once you've assigned an attribute ``slow = 1`` you can exclude that
test and all other tests having the slow attribute by running ::

    $ nosetests -a '!slow'

There is also a decorator available for you that will set attributes.
Here's how to set ``slow=1`` like above with the decorator:

.. code-block:: python

    from nose.plugins.attrib import attr
    @attr('slow')
    def test_big_download():
        import urllib
        # commence slowness...

And here's how to set an attribute with a specific value:

.. code-block:: python

    from nose.plugins.attrib import attr
    @attr(speed='slow')
    def test_big_download():
        import urllib
        # commence slowness...

This test could be run with ::

    $ nosetests -a speed=slow

In Python 2.6 and higher, ``@attr`` can be used on a class to set attributes
on all its test methods at once.  For example:

.. code-block:: python

    from nose.plugins.attrib import attr
    @attr(speed='slow')
    class MyTestCase:
        def test_long_integration(self):
            pass
        def test_end_to_end_something(self):
            pass

Below is a reference to the different syntaxes available.

Simple syntax
-------------

Examples of using the ``-a`` and ``--attr`` options:

* ``nosetests -a status=stable``
   Only runs tests with attribute "status" having value "stable"

* ``nosetests -a priority=2,status=stable``
   Runs tests having both attributes and values

* ``nosetests -a priority=2 -a slow``
   Runs tests that match either attribute

* ``nosetests -a tags=http``
   If a test's ``tags`` attribute was a list and it contained the value
   ``http`` then it would be run

* ``nosetests -a slow``
   Runs tests with the attribute ``slow`` if its value does not equal False
   (False, [], "", etc...)

* ``nosetests -a '!slow'``
   Runs tests that do NOT have the attribute ``slow`` or have a ``slow``
   attribute that is equal to False
   **NOTE**:
   if your shell (like bash) interprets '!' as a special character make sure to
   put single quotes around it.

Expression Evaluation
---------------------

Examples using the ``-A`` and ``--eval-attr`` options:

* ``nosetests -A "not slow"``
  Evaluates the Python expression "not slow" and runs the test if True

* ``nosetests -A "(priority > 5) and not slow"``
  Evaluates a complex Python expression and runs the test if True

i�N(t
isfunction(tPlugin(ttolistsnose.plugins.attribiics��fd�}|S(sgDecorator that adds attributes to classes or functions
    for use with the Attribute (-a) plugin.
    csRx�D]}t||t�qWx*�j�D]\}}t|||�q.W|S(N(tsetattrtTruet	iteritems(tobtnametvalue(targstkwargs(s7/sys/lib/python2.7/site-packages/nose/plugins/attrib.pytwrap_obvs

((R	R
R((R	R
s7/sys/lib/python2.7/site-packages/nose/plugins/attrib.pytattrrscCs\t�}t|||�}||krH|dk	rHt|||�}n||krX|S|S(s�Look up an attribute on a method/ function. 
    If the attribute isn't found there, looking it up in the
    method's class, if any.
    N(tobjecttgetattrtNone(tmethodtclst	attr_nametdefaulttMissingR((s7/sys/lib/python2.7/site-packages/nose/plugins/attrib.pytget_method_attr~s	t
ContextHelpercBs eZdZd�Zd�ZRS(s�Object that can act as context dictionary for eval and looks up
    names as attributes on a method/ function and its class. 
    cCs||_||_dS(N(RR(tselfRR((s7/sys/lib/python2.7/site-packages/nose/plugins/attrib.pyt__init__�s	cCst|j|j|�S(N(RRR(RR((s7/sys/lib/python2.7/site-packages/nose/plugins/attrib.pyt__getitem__�s(t__name__t
__module__t__doc__RR(((s7/sys/lib/python2.7/site-packages/nose/plugins/attrib.pyR�s	tAttributeSelectorcBsGeZdZd�Zd�Zd�Zdd�Zd�Zd�Z	RS(s<Selects test cases to be run based on their attributes.
    cCstj|�g|_dS(N(RRtattribs(R((s7/sys/lib/python2.7/site-packages/nose/plugins/attrib.pyR�s
c
Cs{|jddddddd|jd�d	d
dd�trw|jd
dddd	dddd|jd�dd�ndS(sRegister command line optionss-as--attrtdestRtactiontappendRt	NOSE_ATTRtmetavartATTRthelpsARun only tests that have attributes specified by ATTR [NOSE_ATTR]s-As--eval-attrt	eval_attrtEXPRtNOSE_EVAL_ATTRsaRun only tests for whose attributes the Python expression EXPR evaluates to True [NOSE_EVAL_ATTR]N(t
add_optiontgett	compat_24(Rtparsertenv((s7/sys/lib/python2.7/site-packages/nose/plugins/attrib.pytoptions�scCs]g|_tr]|jr]t|j�}x3|D](}d�}|jj||fg�q.Wn|jrDt|j�}x�|D]�}g}x�|j�jd�D]�}|s�q�n|jdd�}	t|	�dkr�	\}
}n3|	d}
|
ddkr|
d}
t	}nt
}|j|
|f�q�W|jj|�q|Wn|jrYt
|_ndS(sConfigure the plugin and system, based on selected options.

        attr and eval_attr may each be lists.

        self.attribs will be a list of lists of tuples. In that list, each
        list is a group of attributes, all of which must match for the rule to
        match.
        cSst|dt||��S(N(tevalRR(texprtobjR((s7/sys/lib/python2.7/site-packages/nose/plugins/attrib.pyteval_in_context�st,t=iit!N(RR+R&RR!RtstriptsplittlentFalseRtenabled(RR.tconfigR&RR2tstd_attrt
attr_grouptattribtitemstkeyR((s7/sys/lib/python2.7/site-packages/nose/plugins/attrib.pyt	configure�s2		
	 	


		c
Csnt}xW|jD]L}t}x1|D])\}}t|||�}t|�rl||||�sLt}PqLq#|tkr�t|�sLt}PqLq#|tkr�t|�rLt}PqLq#t|�ttfkrt	|�j
�g|D]}	t	|	�j
�^q�rLt}PqLq#||kr#t	|�j
�t	|�j
�kr#t}Pq#q#W|pY|}qW|rjdStS(s�Verify whether a method has the required attributes
        The method is considered a match if it matches all attributes
        for any attribute group.
        .N(R9RRRtcallabletboolttypetlistttupletstrtlowerR(
RRRtanytgrouptmatchR@RRtx((s7/sys/lib/python2.7/site-packages/nose/plugins/attrib.pytvalidateAttrib�s<%$cCs
|j|�S(s5Accept the function if its attributes match.
        (RM(Rtfunction((s7/sys/lib/python2.7/site-packages/nose/plugins/attrib.pytwantFunctionscCs2y
|j}Wntk
r!tSX|j||�S(s3Accept the method if its attributes match.
        (tim_classtAttributeErrorR9RM(RRR((s7/sys/lib/python2.7/site-packages/nose/plugins/attrib.pyt
wantMethods


N(
RRRRR.RARRMRORR(((s7/sys/lib/python2.7/site-packages/nose/plugins/attrib.pyR�s			5,	(ii((RtinspecttloggingtostsysRtnose.plugins.baseRt	nose.utilRt	getLoggertlogtversion_infoR+RR9RRR(((s7/sys/lib/python2.7/site-packages/nose/plugins/attrib.pyt<module>fs	

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].