>Hc@sdZddkZddkZddkZddkZddkZddkZddkZddkZddk l Z ddkl Z l Z ei dZeidZe e fZdZded d d d d ZdZdZddZdZdZdZdZdZdZeZdZddZ dZ!dZ"ddZ#dZ$e%e$_&dZ'e%e'_&dZ(dZ)d Z*d!Z+d"e,fd#YZ-d$Z.d%Z/e0d&joddk1Z1e1i2ndS('s7Utility functions and classes used by nose internally. iN(t CO_GENERATOR(t ClassTypetTypeTypetnoses^[A-Za-z_][A-Za-z0-9_.]*$s5(?:\.svn)|(?:[^.]+\.py[co])|(?:.*~)|(?:.*\$py\.class)ts|-- s| s`-- s cCs"dit||||||S(Ns (tjoint_ls_tree_lines(tdir_patht skip_patterntindentt branch_indentt last_indenttlast_branch_indent((s-/usr/lib/python2.6/site-packages/nose/util.pytls_treesc#sdjoting}ti}|igg}} xh|D]`} ti| oqPntiitii| o|i | qP| i | qPWt t i g} | D]} | | t fq~ g} |D]} | | tfq~ } fd}x=| d D]1\} }x"|| |D] }|VqYWq7W| o9| d\} }x&|| |D] }|VqWndS(NRc3s|p ||Vnktii|}tii|pB||Vt|}x|D]}||VqgWndS(N(tostpathRtislinkR(tnametis_dirtindt branch_indRtsubtreetx(R RR R RR (s-/usr/lib/python2.6/site-packages/nose/util.pytls_entry3s    i(RtgetcwdtlistdirtsorttretmatchRtisdirRtappendtlistt itertoolstchaintFalsetTrue(RRR R R R tlinestnamestdirstnondirsRt_[1]t_[2]tentriesRRtline((R RR R RR s-/usr/lib/python2.6/site-packages/nose/util.pyRs4   "--  cCsttii|p7tiitiitiiti|}n|djptii| odS|S(sUReturn absolute, normalized path to directory, if it exists; None otherwise. N( RRtisabstnormpathtabspathRRtNoneR(R((s-/usr/lib/python2.6/site-packages/nose/util.pytabsdirHs $!cCs|}|djoti}nt|tpt|to7x/|D]'}t||}|dj o|SqJWdStii|p1tii tii tii ||}n|djptii | oN|tijo7tii tii tii ti|}q-n|djptii | odStii |o1tii |d}tii|o|Sntii|o|SdS(sReturn absolute, normalized path to file (optionally in directory where), or None if the file can't be found either in where or the current working directory. s __init__.pyN(R/RRt isinstanceRttupletabsfileRR,R-R.RtexistsRtisfile(Rtwheretorigt maybe_patht maybe_abstinit((s-/usr/lib/python2.6/site-packages/nose/util.pyR3Ts2    1!$! cCs'x |D]}||otSqWtS(N(R#R"(t predicatetiterabletitem((s-/usr/lib/python2.6/site-packages/nose/util.pytanypus   cCsTtii|pAtii|p.|idptitii|d S(sA name is file-like if it is a path that exists, or it has a directory part, or it ends in .py, or it isn't a legal python identifier. s.pyi(RRR4tdirnametendswithtident_reRtsplitext(R((s-/usr/lib/python2.6/site-packages/nose/util.pyt file_like|scCstt|t|S(sCompare functions by their line numbers. >>> cmp_lineno(isgenerator, ispackage) -1 >>> cmp_lineno(ispackage, isgenerator) 1 >>> cmp_lineno(isgenerator, isgenerator) 0 (tcmpt func_lineno(tatb((s-/usr/lib/python2.6/site-packages/nose/util.pyt cmp_linenos cCsJy |iSWn8tj o,y|iiSWqFtj odSXnXdS(srGet the line number of a function. First looks for compat_co_firstlineno, then func_code.co_first_lineno. iN(tcompat_co_firstlinenotAttributeErrort func_codetco_firstlineno(tfunc((s-/usr/lib/python2.6/site-packages/nose/util.pyREs cCs&t|}|tjp t|tS(s|Is obj a class? inspect's isclass is too liberal and returns True for objects that can't be subclasses of anything. (ttypet class_typest issubclass(tobjtobj_type((s-/usr/lib/python2.6/site-packages/nose/util.pytisclasss cCs3y|iit@djSWntj otSXdS(Ni(RKtco_flagsRRJR"(RM((s-/usr/lib/python2.6/site-packages/nose/util.pyt isgeneratorscCstii|otii|}ti|ovx5dD]-}tiitii||otSq<Wt i i do'tiitii|dotSqnt S(s Is this path a package directory? >>> ispackage('nose') True >>> ispackage('unit_tests') False >>> ispackage('nose/plugins') True >>> ispackage('nose/loader.py') False s __init__.pys __init__.pycs __init__.pyotjavas__init__$py.class(s __init__.pys __init__.pycs __init__.pyo( RRRtbasenameRARR5RR#tsystplatformt startswithR"(RtendR:((s-/usr/lib/python2.6/site-packages/nose/util.pyt ispackages " " cCs|djoti}ntii|tii|id}d}x0|D](}||}tii|o|SqTWdS(sFind the python source file for a package, relative to a particular directory (defaults to current working directory if not given). t.s /__init__.pys.pyN(s /__init__.pys.py(R/RRRRtseptsplitR4(tpackaget relativeToRtsuffixestsuffixtfilename((s-/usr/lib/python2.6/site-packages/nose/util.pyt getfilenames *  cCst|}|id ot| odStiitii|\}}|djo g}n |g}tiitii|d\}}xR|oJttii ||o|i |nPtii|\}}qW|i di |S(s Find the full dotted package name for a given python source file name. Returns None if the file is not a python source file. >>> getpackage('foo.py') 'foo' >>> getpackage('biff/baf.py') 'baf' >>> getpackage('nose/util.py') 'nose.util' Works for directories too. >>> getpackage('nose') 'nose' >>> getpackage('nose/plugins') 'nose.plugins' And __init__ files stuck onto directories >>> getpackage('nose/plugins/__init__.py') 'nose.plugins' Absolute paths also work. >>> path = os.path.abspath(os.path.join('nose', 'plugins')) >>> getpackage(path) 'nose.plugins' s.pyt__init__iR]N( tsrcR@R\R/RRRBRWR_RRtreverse(Rdtsrc_filetbasetextt mod_partsRtpart((s-/usr/lib/python2.6/site-packages/nose/util.pyt getpackages  $   ( cCslt|d}d|d}dd||d|f}dt|}|djo|d|}n|S(sDraw a 70-char-wide divider, with label in the middle. >>> ln('hello there') '---------------------------- hello there -----------------------------' iiFs%s %s %st-i(tlen(tlabelt label_lentchunktouttpad((s-/usr/lib/python2.6/site-packages/nose/util.pytlns cCs|id}|}|djorxa|oYy*tid|tdi|}PWq&tj o|d=|pqq&Xq&W|d}n|}tid||||x|D]}t||}qW|S(s8Resolve a dotted name to a module and its parts. This is stolen wholesale from unittest.TestLoader.loadTestByName. >>> resolve_name('nose.util') #doctest: +ELLIPSIS >>> resolve_name('nose.util.resolve_name') #doctest: +ELLIPSIS R]s __import__ %siisresolve: %s, %s, %s, %sN(R_R/tlogtdebugt __import__Rt ImportErrortgetattr(Rtmoduletpartst parts_copyRQRm((s-/usr/lib/python2.6/site-packages/nose/util.pyt resolve_names(  cCstii}|}d}d|jo2t|o||ddfSd|dfSntii|\}}|py7|id\}}t|o|d}}nWqptj o[|id}t|ddjo"di|d |d}}qtdqpXnV|p |}nEd|jo|id\}}n|}ti i||g}|o2t|o||d|fSd||fSndd|fSdS(s3Split a test name into a 3-tuple containing file, module, and callable names, any of which (but not all) may be blank. Test names are in the form: file_or_module:callable Either side of the : may be dotted. To change the splitting behavior, you can alter nose.util.split_test_re. t:iiisaTest name '%s' could not be parsed. Please format test names as path:callable or module:callable.N( RRR-R/RCR_t ValueErrorRpRR^(ttesttnormt file_or_modtfntheadttailR}t file_part((s-/usr/lib/python2.6/site-packages/nose/util.pytsplit_test_name:s:    "   cCs:t|do |iSt|}d }}}|tijo2t|dd }t|dd }|||fS|tijp t|tp|ti jot|dd }|d j oFt i |}t|dd }|d j ot i i|}q nt|dd }|||fS|tijot|iS|tijo6t|i}|d|dd|d|iffSt|tio}t|d ot|iSt|i}y |i}Wntj o|i}nX|d|dd|d|ffStd ||fd S( sfFind the test address for a test, which may be a module, filename, class, method or function. taddresst__file__t__name__t __module__iis%s.%sit_FunctionTestCase__testFuncsI don't know what %s is (%s)N(thasattrRRNR/ttypest ModuleTypeR{t FunctionTypeRPRRXtmodulesRRR.t InstanceTypet test_addresst __class__t MethodTypetim_classRR1tunittesttTestCaseRt_TestCase__testMethodNameRJt_testMethodNamet TypeError(RtttfileR|tcalltmtcls_adrt method_name((s-/usr/lib/python2.6/site-packages/nose/util.pyRysD  0    c CsAx:|D]2}t||d}|dj o t|tijoyti|\}}}}Wntj o|t|do |i }ny,ti|\}}}}|i dWqtj otd||fqXnXt |o!t i d|||||Snt i d|||SqWdS(sGiven a list of possible method names, try to run them with the provided object. Keep going until something works. Used to run setup/teardown methods for module, package, and function tests. t__call__isaAttribute %s of %r is not a python function. Only functions or callables may be used as fixtures.scall fixture %s.%s(%s)scall fixture %s.%sN(R{R/RNRRtinspectt getargspecRRRtpopRpRwRx(RQR%RRMtargstvarargstvarkwtdefaults((s-/usr/lib/python2.6/site-packages/nose/util.pyttry_runs*   cCs|d jo|Stiido(|idodi|d dfStii|\}}|d jodi|dfS|S( sFind the python source file for a .pyc, .pyo or $py.class file on jython. Returns the filename provided if it is not a python source file. RVs $py.classR]itpys.pycs.pyos.pyN(s.pycs.pyos.py( R/RXRYRZR@RRRRB(RdRjRk((s-/usr/lib/python2.6/site-packages/nose/util.pyRgs # cCsY|i|o|i| odS|i|o|i| odSt||S(szSort compare function that puts items that match a regular expression last. >>> from nose.config import Config >>> c = Config() >>> regex = c.testMatch >>> entries = ['.', '..', 'a_test', 'src', 'lib', 'test', 'foo.py'] >>> entries.sort(lambda a, b: match_last(a, b, regex)) >>> entries ['.', '..', 'foo.py', 'lib', 'src', 'a_test', 'test'] ii(tsearchRD(RFRGtregex((s-/usr/lib/python2.6/site-packages/nose/util.pyt match_lasts !!c Csr|djodSy|ig|SWntj onXytid|SWntj ot|SXdS(swConvert a value that may be a list or a (possibly comma-separated) string into a list. The exception: None is returned as None, not [None]. >>> tolist(["one", "two"]) ['one', 'two'] >>> tolist("hello") ['hello'] >>> tolist("separate,values, with, commas, spaces , are ,ok") ['separate', 'values', 'with', 'commas', 'spaces', 'are', 'ok'] s\s*,\s*N(R/textendRJRR_RR(tval((s-/usr/lib/python2.6/site-packages/nose/util.pyttolists  todictcBsteZdZdZdZdZdZdZdZdZ dZ d d Z d Z d ZRS( svSimple ordered dict implementation, based on: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/107747 cOs&g|_tt|i||dS(N(t_keystsuperRRf(tselftargtkw((s-/usr/lib/python2.6/site-packages/nose/util.pyRf s cCs*tt|i||ii|dS(N(RRt __delitem__Rtremove(Rtkey((s-/usr/lib/python2.6/site-packages/nose/util.pyRscCsAtt|i||||ijo|ii|ndS(N(RRt __setitem__RR(RRR=((s-/usr/lib/python2.6/site-packages/nose/util.pyRscCsBddig}|iD]\}}|d||fq~S(Ns{%s}s, s%r: %r(Rtitems(RR(tktv((s-/usr/lib/python2.6/site-packages/nose/util.pyt__str__scCs tt|ig|_dS(N(RRtclearR(R((s-/usr/lib/python2.6/site-packages/nose/util.pyRscCs&tt|i}|i|_|S(N(RRtcopyR(Rtd((s-/usr/lib/python2.6/site-packages/nose/util.pyRs cCst|i|iS(N(tzipRtvalues(R((s-/usr/lib/python2.6/site-packages/nose/util.pyR#scCs|iS(N(R(R((s-/usr/lib/python2.6/site-packages/nose/util.pytkeys&scCsCtt|i||}||ijo|ii|n|S(N(RRt setdefaultRR(RRtfailobjR=((s-/usr/lib/python2.6/site-packages/nose/util.pyR)scCsUtt|i|x8|iD]*}||ijo|ii|q#q#WdS(N(RRtupdateRRR(RtdictR((s-/usr/lib/python2.6/site-packages/nose/util.pyR/s  cCst|i|iS(N(tmaptgetR(R((s-/usr/lib/python2.6/site-packages/nose/util.pyR5sN(RRt__doc__RfRRRRRRRR/RRR(((s-/usr/lib/python2.6/site-packages/nose/util.pyRs          cs>ddkl}fd}||}||_|S(s Make a function imported from module A appear as if it is located in module B. >>> from pprint import pprint >>> pprint.__module__ 'pprint' >>> pp = transplant_func(pprint, __name__) >>> pp.__module__ 'nose.util' The original function is not modified >>> pprint.__module__ 'pprint' Calling the transplanted function calls the original. >>> pp([1, 2]) [1, 2] >>> pprint([1,2]) [1, 2] i(tmake_decoratorcs ||S(N((RR(RM(s-/usr/lib/python2.6/site-packages/nose/util.pytnewfuncSs(t nose.toolsRR(RMR|RR((RMs-/usr/lib/python2.6/site-packages/nose/util.pyttransplant_func9s  cCs/d|fdY}||_|i|_|S(sF Make a class appear to reside in `module`, rather than the module in which it is actually defined. >>> from nose.failure import Failure >>> Failure.__module__ 'nose.failure' >>> Nf = transplant_class(Failure, __name__) >>> Nf.__module__ 'nose.util' >>> Nf.__name__ 'Failure' tCcBseZRS((RR(((s-/usr/lib/python2.6/site-packages/nose/util.pyRjs(RR(tclsR|R((s-/usr/lib/python2.6/site-packages/nose/util.pyttransplant_class[s  t__main__(3RRR tloggingRRRXRRtcompiler.constsRRRt getLoggerRwtcompileRARORR RR0R/R3R>RCRHRERSRUt is_generatorR\ReRnRvRRR"t__test__RRRgRRRRRRRtdoctestttestmod(((s-/usr/lib/python2.6/site-packages/nose/util.pyts^          * !      1   <  ,    4 "