K9Qc@sCdZddlZddlZddlZddlZddlZddlZddlZddlZddl m Z m Z m Z ej dZejdZe e fZdZyeeZWn9ek ryddlmZWqek rqXnXded d d d d ZdZdZddZdZdZdZdZ e Z!dZ"dZ#ddZ$dZ%dZ&ddZ'dZ(e)e(_*dZ+e)e+_*dZ,dZ-dZ.d Z/d!e0fd"YZ1d#Z2d$Z3d%d&Z4e5d'kr?ddl6Z6e6j7ndS((s7Utility functions and classes used by nose internally. iN(t ClassTypetTypeTypet isgeneratortnoses^[A-Za-z_][A-Za-z0-9_.]*$sE(?:\.svn)|(?:[^.]+\.py[co])|(?:.*~)|(?:.*\$py\.class)|(?:__pycache__)(tSetts|-- s| s`-- s cCs"djt||||||S(Ns (tjoint_ls_tree_lines(tdir_patht skip_patterntindentt branch_indentt last_indenttlast_branch_indent((s-/sys/lib/python2.7/site-packages/nose/util.pytls_treesc#sdkrtjng}tj}|jgg}} xd|D]\} tj| rlqNntjjtjj| r|j | qN| j | qNWt t j g| D]} | t f^qg|D]} | tf^q} fd} x=| d D]1\} } x"| | | D] }|VqCWq!W| r| d\} } x%| | | D] }|VqWndS(NRc3s~|s||Vnhtjj|}tjj|sz||Vt|}x|D]}||VqdWndS(N(tostpathRtislinkR(tnametis_dirtindt branch_indRtsubtreetx(R RR R R R (s-/sys/lib/python2.7/site-packages/nose/util.pytls_entry=s     i(RtgetcwdtlistdirtsorttretmatchRtisdirRtappendtlistt itertoolstchaintFalsetTrue(RR R R R R tlinestnamestdirstnondirsRtentriesRRtline((R RR R R R s-/sys/lib/python2.7/site-packages/nose/util.pyR(s,    !%%  cCsotjj|sHtjjtjjtjjtj|}n|dksgtjj| rkdS|S(sUReturn absolute, normalized path to directory, if it exists; None otherwise. N( RRtisabstnormpathtabspathRRtNoneR(R((s-/sys/lib/python2.7/site-packages/nose/util.pytabsdirRs $cCs|}|dkr!tj}nt|ts?t|trsx-|D]%}t||}|dk rF|SqFWdStjj|stjj tjj tjj ||}n|dkstjj | r|tjkrtjj tjj tjj tj|}qn|dks>tjj | rBdStjj |rtjj |d}tjj|r|Sntjj|r|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 isinstanceR ttupletabsfileRR+R,R-RtexistsRtisfile(Rtwheretorigt maybe_patht maybe_abstinit((s-/sys/lib/python2.7/site-packages/nose/util.pyR2^s0   0$cCs%x|D]}||rtSqWtS(N(R$R#(t predicatetiterabletitem((s-/sys/lib/python2.7/site-packages/nose/util.pytanyps  cCsQtjj|pPtjj|pP|jdpPtjtjj|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(RRR3tdirnametendswithtident_reRtsplitext(R((s-/sys/lib/python2.7/site-packages/nose/util.pyt file_likescCsFy |jSWn4tk rAy|jjSWqBtk r=dSXnXdS(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-/sys/lib/python2.7/site-packages/nose/util.pyt func_linenos   cCs%t|}|tkp$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-/sys/lib/python2.7/site-packages/nose/util.pytisclasss cCstjj|rtjj|}tj|rx3dD]+}tjjtjj||r:tSq:Wt j j drtjjtjj|drtSqnt 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( RRRtbasenameR@RR4RR$tsystplatformt startswithR#(RtendR9((s-/sys/lib/python2.7/site-packages/nose/util.pyt ispackages  !! cCst|tkS(s Is this a property? >>> class Foo: ... def got(self): ... return 2 ... def get(self): ... return 1 ... get = property(get) >>> isproperty(Foo.got) False >>> isproperty(Foo.get) True (RItproperty(RL((s-/sys/lib/python2.7/site-packages/nose/util.pyt ispropertyscCs|dkrtj}ntjj|tjj|jd}d}x.|D]&}||}tjj|rR|SqRWdS(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.RRRRtseptsplitR3(tpackaget relativeToRtsuffixestsuffixtfilename((s-/sys/lib/python2.7/site-packages/nose/util.pyt getfilenames *  cCst|}tjj|s.|jd r?t| r?dStjjtjj|\}}|dkrxg}n |g}tjj tjj |d\}}xN|rttjj ||r|j |nPtjj |\}}qW|j dj |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__iRXN( tsrcRRRR?RUR.RARPRZRRtreverse(R_tsrc_filetbasetextt mod_partsRtpart((s-/sys/lib/python2.7/site-packages/nose/util.pyt getpackages /$   (  cCsjt|d}d|d}dd||d|f}dt|}|dkrf|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-/sys/lib/python2.7/site-packages/nose/util.pytlns cCs|jd}|}|dkrx[|ry*tjd|tdj|}PWq%tk r{|d=|s|q|q%Xq%W|d}n|}tjd||||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 RXs __import__ %siisresolve: %s, %s, %s, %sN(RZR.tlogtdebugt __import__Rt ImportErrortgetattr(Rtmoduletpartst parts_copyRLRh((s-/sys/lib/python2.7/site-packages/nose/util.pyt resolve_name(s$      cCstjj}|}d}d|krSt|rC||ddfSd|dfSntjj|\}}|sy5|jd\}}t|r|d}}nWq`tk r |jd}t|ddkrdj|d |d}}q tdq`XnQ|s|}nBd|krB|jd\}}n|}tj j||g}|rt|r||d|fSd||fSn dd|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.RBRZt ValueErrorRkRRY(ttesttnormt file_or_modtfntheadttailRxt file_part((s-/sys/lib/python2.7/site-packages/nose/util.pytsplit_test_nameEs:     !   cCst|dr|jSt|}d}}}|tjkryt|dd}t|dd}t|||fS|tjkst |ts|tj kr,t|dd}|dk rt j |}t|dd}|dk rt jj|}qnt|dd}t|||fS|tjkrvt|j}t|d|dd|d|jffSt|tjr:t|d st|d ryt|jSWqtk rt|jSXnt|j}y |j}Wntk r|j}nXt|d|dd|d|ffSt|d rh|jjdkrht|jStd||fdS(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__testFunct _testFunct __class__t __builtin__tbuiltinssI don't know what %s is (%s)N(s __builtin__R(thasattrRRIR.ttypest ModuleTypeRvRbt FunctionTypeRKRRQtmodulesRRR-t MethodTypet test_addresstim_classRR0tunittesttTestCaseRRDRRt_TestCase__testMethodNamet_testMethodNameRt TypeError(R}tttfileRwtcalltmtcls_adrt method_name((s-/sys/lib/python2.7/site-packages/nose/util.pyRsN  -        cCs5x.|D]&}t||d}|dk rt|tjkrytj|\}}}}Wntk rt|dr|j }ny,tj|\}}}}|j dWqtk rtd||fqXnXt |rt j d|||||Snt j 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(RvR.RIRRtinspectt getargspecRRRtpopRkRrRs(RLR&RRGtargstvarargstvarkwtdefaults((s-/sys/lib/python2.7/site-packages/nose/util.pyttry_runs(       cCs|d kr|StjjdrH|jdrHdj|d dfStjj|\}}|d krdj|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. ROs $py.classRXitpys.pycs.pyos.pyN(s.pycs.pyos.py( R.RQRRRSR?RRRRA(R_ReRf((s-/sys/lib/python2.7/site-packages/nose/util.pyRbs ! csfd}|S(sSort key function factory that puts items that match a regular expression last. >>> from nose.config import Config >>> from nose.pyversion import sort_list >>> c = Config() >>> regex = c.testMatch >>> entries = ['.', '..', 'a_test', 'src', 'lib', 'test', 'foo.py'] >>> sort_list(entries, regex_last_key(regex)) >>> entries ['.', '..', 'foo.py', 'lib', 'src', 'a_test', 'test'] cs#j|rd|fSd|fS(Nii(tsearch(RL(tregex(s-/sys/lib/python2.7/site-packages/nose/util.pytks ((RR((Rs-/sys/lib/python2.7/site-packages/nose/util.pytregex_last_keys cCsl|dkrdSy|jg|SWntk r8nXytjd|SWntk rgt|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.textendRDRRZRR (tval((s-/sys/lib/python2.7/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|j||dS(N(t_keystsuperRRa(tselftargtkw((s-/sys/lib/python2.7/site-packages/nose/util.pyRas cCs*tt|j||jj|dS(N(RRt __delitem__Rtremove(Rtkey((s-/sys/lib/python2.7/site-packages/nose/util.pyRscCs?tt|j||||jkr;|jj|ndS(N(RRt __setitem__RR(RRR<((s-/sys/lib/python2.7/site-packages/nose/util.pyR#scCs:ddjg|jD]\}}d||f^qS(Ns{%s}s, s%r: %r(Rtitems(RRtv((s-/sys/lib/python2.7/site-packages/nose/util.pyt__str__(scCs tt|jg|_dS(N(RRtclearR(R((s-/sys/lib/python2.7/site-packages/nose/util.pyR+scCs&tt|j}|j|_|S(N(RRtcopyR(Rtd((s-/sys/lib/python2.7/site-packages/nose/util.pyR/s cCst|j|jS(N(tzipRtvalues(R((s-/sys/lib/python2.7/site-packages/nose/util.pyR4scCs|jS(N(R(R((s-/sys/lib/python2.7/site-packages/nose/util.pytkeys7scCsAtt|j||}||jkr=|jj|n|S(N(RRt setdefaultRR(RRtfailobjR<((s-/sys/lib/python2.7/site-packages/nose/util.pyR:scCsStt|j|x6|jD](}||jkr#|jj|q#q#WdS(N(RRtupdateRRR(RtdictR((s-/sys/lib/python2.7/site-packages/nose/util.pyR@scCst|j|jS(N(tmaptgetR(R((s-/sys/lib/python2.7/site-packages/nose/util.pyRFsN(RRt__doc__RaRRRRRRRR.RRR(((s-/sys/lib/python2.7/site-packages/nose/util.pyRs          cs>ddlm}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(RG(s-/sys/lib/python2.7/site-packages/nose/util.pytnewfuncds(t nose.toolsRR(RGRwRR((RGs-/sys/lib/python2.7/site-packages/nose/util.pyttransplant_funcJs  cCs/d|fdY}||_|j|_|S(sB 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-/sys/lib/python2.7/site-packages/nose/util.pyR{s(RR(tclsRwR((s-/sys/lib/python2.7/site-packages/nose/util.pyttransplant_classls  sutf-8cCsnyt|SWnYtk rit|trVdjg|D]}t||^q:St|j|SXdS(Nt (tstrtUnicodeEncodeErrorR0t ExceptionRtsafe_strtunicodetencode(RtencodingR((s-/sys/lib/python2.7/site-packages/nose/util.pyRs   t__main__(8RRR!tloggingRRRQRRtnose.pyversionRRRt getLoggerRrtcompileR@RJR tsett NameErrortsetsRRuRRR/R.R2R=RBRHRNt is_generatorRURWR`RiRqRzRR#t__test__RRRbRRRRRRRRtdoctestttestmod(((s-/sys/lib/python2.7/site-packages/nose/util.pytsl             * !      1   <  1    4 "