�9�c@s�dZddlmZddlZddlZddlZddlZddlZddlm Z ddl
mZmZddl
mZmZddlmZddlmZdd lmZmZmZdd
lmZmZddlmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%ddl&m'Z'm(Z(m)Z)dd
l
m*Z*m+Z+ej,e-�Z.ej/j0Z1ej/j2Z3ej/j4Z5ej/j6Z7ej/j8Z9ddgZ:dej;fd��YZ;e;Z<dS(s�
Test Loader
-----------
nose's test loader implements the same basic functionality as its
superclass, unittest.TestLoader, but extends it by more liberal
interpretations of what may be a test and how a test may be named.
i�(t
generatorsN(t
isfunction(tunbound_methodtismethod(tFunctionTestCasetMethodTestCase(tFailure(tConfig(tImportertadd_pathtremove_path(tdefaultSelectortTestAddress(
tfunc_linenot
getpackagetisclasstisgeneratort ispackagetregex_last_keytresolve_namettransplant_functtransplant_classttest_address(tContextSuiteFactorytContextListt LazySuite(t sort_listt
cmp_to_keyt
TestLoadertdefaultTestLoadercBs�eZdZdZdZdZdZdZddddd�Z d�Z
d�Zd�Zd�Z
d�Zd�Zd�Zded �Zded
�Zdd�Zd�Zd
�Zdd�Zdd�Zd�Zd�ZRS(sATest loader that extends unittest.TestLoader to:
* Load tests from test-like functions and classes that are not
unittest.TestCase subclasses
* Find and load test modules in a directory
* Support tests that are generators
* Support easy extensions of or changes to that behavior through plugins
cCs|dkrt�}n|dkr6td|�}n|dkrN|j}n|dkrit|�}nt|�r�||�}n||_||_tt |��|_||_
|jr�t||�nt
d|�|_tg�|_tjj|�dS(sInitialize a test loader.
Parameters (all optional):
* config: provide a `nose.config.Config`_ or other config class
instance; if not provided a `nose.config.Config`_ with
default values is used.
* importer: provide an importer instance that implements
`importFromPath`. If not provided, a
`nose.importer.Importer`_ is used.
* workingDir: the directory to which file and module names are
relative. If not provided, assumed to be the current working
directory.
* selector: a selector class or instance. If a class is
provided, it will be instantiated with one argument, the
current config. If not provided, a `nose.selector.Selector`_
is used.
tconfigN(tNoneRRt
workingDirRRRtimportertop_normpatht
op_abspathtselectortaddPathsR Rt
suiteClasstsett
_visitedPathstunittestRt__init__(tselfRR!R R$((s//sys/lib/python2.7/site-packages/nose/loader.pyR*;s& cCs�|jjrtjj||�S||jd�}t|t|��}xG|jD]<}x3|j|�D]"}||krf|j |�qfqfWqPW|r�t
|d�r�dg}n|jr�t|t
|j��n|S(s_Override to select with selector, unless
config.getTestCaseNamesCompat is True
cSsMt||d�}t|�r0t||�}nt|�s@tS|j|�S(N(tgetattrRRRRtFalset
wantMethod(tattrtclstseltitem((s//sys/lib/python2.7/site-packages/nose/loader.pytwantedlstrunTest(RtgetTestCaseNamesCompatR)RtgetTestCaseNamesR$tfiltertdirt __bases__tappendthasattrtsortTestMethodsUsingRR(R+t
testCaseClassR3tcasestbasetcase((s//sys/lib/python2.7/site-packages/nose/loader.pyR6es cCs|dkrtS||jkS(N(RR-R((R+tpath((s//sys/lib/python2.7/site-packages/nose/loader.pyt_haveVisitedscCs#|dk r|jj|�ndS(N(RR(tadd(R+RA((s//sys/lib/python2.7/site-packages/nose/loader.pyt_addVisitedPath�sc
#s�tjd|��jj}|j|��jjrJt|�j�}ntj|�}t |t
�jj��xa|D]Y}|jd�r�qynt
t||���t��}t}|r�t}�jj��}n<t��}|r|jd�rqyn�jj��}nt��} |ry�j��ry�j��|r�|j�|jd�r}�j�dt�Vn�j��V|j�q�| r��j�dt�Vq��j��fd��VqyqyWg}
x$|j|�D]}|
j |�q�y|
r�j|
�VnWn=t!t"fk
r:�n$�jt#t$j%��g�VnX�jjr�x|D]}t&|�qqWn|j'|�dS(s�Load tests from the directory at path. This is a generator
-- each suite of tests from a module or other file is yielded
and is expected to be executed before the next file is
examined.
sload from dir %st.t_s.pyt
discoveredcs
�j��S(N(tloadTestsFromDir((t
entry_pathR+(s//sys/lib/python2.7/site-packages/nose/loader.pyt<lambda>�sN((tlogtdebugRtpluginstbeforeDirectoryR%R tostlistdirRRt testMatcht
startswithR#top_joint op_isfileR-R$twantFiletop_isdirt
wantDirectoryRRBRDt
beforeContexttendswithtloadTestsFromNametTruetloadTestsFromFiletafterContextR&RHR:tKeyboardInterruptt
SystemExitRtsystexc_infoR
tafterDirectory(
R+RARMtpaths_addedtentriestentrytis_fileR3tis_dirt
is_packagetteststtesttp((RIR+s//sys/lib/python2.7/site-packages/nose/loader.pyRH�sd
!
c Cs�tjd|�yqg|jjj|�D]}|^q)}|r]td|�}|j|�St|d�j �t
d|��Wn`ttfk
r��nGt
j�}|jt|d|d|dd|ddf�g�SXdS( s�Load tests from a non-module file. Default is to raise a
ValueError; plugins may implement `loadTestsFromFile` to
provide a list of tests loaded from the file.
sLoad from non-module file %strs!Unable to load tests from file %siiitaddressN(RKRLRRMR\R7RR&topentcloset
ValueErrorR^R_R`RaR(R+tfilenameRjRitexc((s//sys/lib/python2.7/site-packages/nose/loader.pyR\�s"%
cs1�|��fd�}�j|d�dt�S(s�Lazy-load tests from a generator function. The generator function
may yield either:
* a callable, or
* a function name resolvable within the same module
c3s�ybx[|�D]P}�j|�\}}t|�sFt||�}nt|d|d|�Vq
WWnOtk
rx�n<tj�}t|d|d|ddt���VnXdS(Ntargt
descriptoriiiRm( tparseGeneratedTesttcallableR,RR^R`RaRR(tgtmRjt test_funcRsRr(t generatorR+(s//sys/lib/python2.7/site-packages/nose/loader.pytgenerate�s
tcontextt can_split(R&R-(R+RztmoduleR{((RzR+s//sys/lib/python2.7/site-packages/nose/loader.pytloadTestsFromGenerator�s
csmt�d�r�j}n|�}�j}t||���|��fd�}�j|d�dt�S(s�Lazy-load tests from a generator method.
This is more complicated than loading from a generator function,
since a generator method may yield:
* a function
* a bound or unbound method, or
* a method name
tim_classc3sy�x�|�D]�}�j|�\}}t|�sOt|t||��}nt|�rut|d|d|�Vq
t|�r�t|d|d|�Vq
ttd|�Vq
WWnOt k
r��n<t
j�}t|d|d|ddt���VnXdS( NRsRtRjs%s is not a function or methodiiiRm(
RuRvRR,RRRRt TypeErrorR^R`RaR(RwtcRjRyRsRr(RzR+(s//sys/lib/python2.7/site-packages/nose/loader.pyR{s$
R|R}(R;R�t__name__R,R&R-(R+RzR0tinsttmethodR{((RzR+s//sys/lib/python2.7/site-packages/nose/loader.pytloadTestsFromGeneratorMethod
s cstjd��g}g}g}|s;�jj��rx�t��D]w}t�|d�}t|�r��jj|�r�|j |�q�qHt
|�rH�jj|�rH|j |�qHqHWt|d��t|t
�t��fd�||�}nt�dg�} |r/tjj|�}nx�| D]}
tjd|
�tjd||
tjj|
���jjs�|s�tjj|
�j|�r6|j�j|
��q6q6Wx-�jjj�|�D]}|j |�q�W�jt|d���S( s�Load all tests from module and return a suite containing
them. If the module has been discovered and is not test-like,
the suite will be empty by default, though plugins may add
their own tests.
sLoad from module %scSs|jS(N(R�(tx((s//sys/lib/python2.7/site-packages/nose/loader.pyRJLscs�j|d��S(Ntparent(tmakeTest(tt(R~R+(s//sys/lib/python2.7/site-packages/nose/loader.pyRJNst__path__sLoad tests from module path %s?s!path: %s os.path.realpath(%s): %sR|N(RKRLR$t
wantModuleR8R,RRt wantClassR:RtwantFunctionRR
tmapRORAtrealpathRttraverseNamespaceRRtextendRHRMtloadTestsFromModuleR&R(R+R~RARGRittest_classest
test_funcsR2Rjtmodule_pathstmodule_path((R~R+s//sys/lib/python2.7/site-packages/nose/loader.pyR�6s:
cshtjd||��j}�jjj||�}|rD||�St|d�j�}|rD|jrt|j}n�j ||�\}}t
|�r�|dd�|j
kr�|t�r�||j
�}t||j
�}ntjd|||�t|t�r||g�S|t�j||�gd|��Sn |jrby�|jdkrqt|j�}n[�jjj|j|j�z�jj|j|j�}Wd�jjj|j|j�XWnZttfk
r��nAtj�} |t| d| d| d d
|j��g�SX|jrF�j|j|�S�j||jd|�Sn|jr>|j�|jr�t ��}
|
dkr�|tt!d|j�fd
|j��g�S�j|jd
|
�St"��r���fd��St$��r�j%��S|tt&d�d
|j��g�Sn&|tt!d|d
|j��g�SdS(s�Load tests from the entity with the given name.
The name may indicate a file, directory, module, or any object
within a module. See `nose.util.split_test_name` for details on
test name parsing.
sload from %s (%s)R t
__module__sparent %s obj %s module %sR|NiiiRmRGs>Can't find callable %s in file %s: file is not a python moduleR~cs
�j��S(N(RH((RAR+(s//sys/lib/python2.7/site-packages/nose/loader.pyRJ�ssNo such file %ssUnresolvable test name %s('RKRLR&RRMRZRR tcalltresolveRR,RR�t
isinstanceRRRR�R~RqRtbeforeImportR!timportFromPathtafterImportR^R_R`RattotupleR�RRpRVRRTR\tOSError(R+tnameR~RGtsuitet
plug_teststaddrR�tobjRrtpackage((RAR+s//sys/lib/python2.7/site-packages/nose/loader.pyRZds�
cCsw|jjj||�}|ra|\}}|ra|j|j|�tjj|||�g�Sntjj|||�S(sSLoad tests from all names, returning a suite containing all
tests.
(RRMtloadTestsFromNamesR&R)R(R+tnamesR~tplug_resR�((s//sys/lib/python2.7/site-packages/nose/loader.pyR��scCs�g}|jj}x$|j|�D]}|j|�q"W|sUtt|�j|�S|jgtt|�j|�D]}|^qt�|j|�S(s6Load tests from a unittest.TestCase subclass.
(RRMtloadTestsFromTestCaseR:tsuperRR�R&(R+R=R>RMR@((s//sys/lib/python2.7/site-packages/nose/loader.pyR��s)cCs�||jd�}gt|t|��D]!}|jt||�|�^q(}x*|jjj|�D]}|j|�qeW|j t
|d|��S(s!Load tests from a test class that is *not* a unittest.TestCase
subclass.
In this case, we can't depend on the class's `__init__` taking method
name arguments, so we have to compose a MethodTestCase for each
method in the class that looks testlike.
cSsMt||d�}t|�r0t||�}nt|�s@tS|j|�S(N(R,RRRRR-R.(R/R0R1R2((s//sys/lib/python2.7/site-packages/nose/loader.pyR3�sR|(R$R7R8R�R,RRMtloadTestsFromTestClassR:R&R(R+R0R3R@R>Rj((s//sys/lib/python2.7/site-packages/nose/loader.pyR��s:cCs�y|j||�SWn~ttfk
r0�netj�}yt|�}Wn tk
re�n
d}nXt|d|d|dd|�SXdS(NiiiRm(t _makeTestR^R_R`RaRRR(R+R�R�RrR�((s//sys/lib/python2.7/site-packages/nose/loader.pyR�s
cCslg}yt|�}Wn tk
r,�n
d}nXx-|jjj||�D]}|j|�qRWy|r|j|�SWnKttfk
r��n2t j
�}t|d|d|dd|�SXt|�r|rt
|tj�rt||�}nt
|tj�r|St|�r�|rT|j|jkrTt||j�}nt|tj�rs|j|�S|j|�Sn�|�r�dkr�|j}nt|tj�r�||j�St|�r�j||�St|�Snyt|�rQ|r(|j|jkr(t||j�}nt|�rD|j ||�St!|�Sntt"d|d|�SdS(sVGiven a test object and its parent, return a test case
or test suite.
iiiRmsCan't make a test from %sN(#RR^RRRMR�R:R&R_R`RaRRR�ttypest
ModuleTypeRR)tTestCaseRR�R�Rt
issubclassR�R�Rt __class__RR�RRRRR�(R+R�R�R�R�RjRr((s//sys/lib/python2.7/site-packages/nose/loader.pyR�sX
#%
cCsk|}|jd�}x'|D]}|t||d�}}qW|dkrattd|�}n||fS(s#Resolve name within module
REsNo such test %sN(tsplitR,RRRp(R+R�R~R�tpartstpartR�((s//sys/lib/python2.7/site-packages/nose/loader.pyR�Ns
cCs�t|t�s"|t�}}nVt|�dkrK|dt�}}n-t|�dksct�|d|d}}||fS(s�Given the yield value of a test generator, return a func and args.
This is used in the two loadTestsFromGenerator* methods.
ii(R�ttupletlentAssertionError(R+RjRyRs((s//sys/lib/python2.7/site-packages/nose/loader.pyRuZsN(R�R�t__doc__RRR!R R$R&R*R6RBRDRHR\RR�R-R�RZR�R�R�R�R�R�Ru(((s//sys/lib/python2.7/site-packages/nose/loader.pyR,s0 ) M ,.l ; (=R�t
__future__RtloggingROR`R)R�tinspectRtnose.pyversionRRt nose.caseRRtnose.failureRtnose.configRt
nose.importerRR R
t
nose.selectorRRt nose.utilR
RRRRRRRRRt
nose.suiteRRRRRt getLoggerR�RKRAtnormpathR"tabspathR#tjoinRStisdirRVtisfileRTt__all__RR(((s//sys/lib/python2.7/site-packages/nose/loader.pyt<module>s6F�?
|