ó J9•Qc@sÆdZddlZddlZddlZddlZddlmZddlmZddlm Z ej dƒZ ej dkZ d „Zed „Zd dd „ƒYZd efd„ƒYZdS(s Attribute 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 d d ƒtrw|jd dddd dddd|jdƒd dƒ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äkrLt}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.pytfs