Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/twisted/trial/test/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyc


=Nc@sdZddlZddlZddlZddlmZddlmZddlm	Z	ddl
mZmZm
Z
ddlmZddlmZd	Zd
e	jfdYZde	jfd
YZde	jfdYZdefdYZde	jfdYZdS(s"
Tests for loading tests by name.
iN(tutil(tmd5(tpackages(trunnertreportertunittest(t	ITestCase(t	getModulecCs7g}x*tj|D]}|j|jqW|S(sI
    Return the id of each test within the given test suite or case.
    (Rt
_iterateTeststappendtid(tteststnamesttest((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt	testNamesst
FinderTestcBsYeZdZdZdZdZdZdZdZdZ	dZ
RS(	cCs#tjj|tj|_dS(N(RtPackageTesttsetUpRt
TestLoadertloader(tself((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyR"scCstjj|dS(N(RRttearDown(R((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyR&scCs2|jjd}ddl}|j||dS(Nttwistedi(Rt
findByNameRtassertEqual(Rtsample1tsample2((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_findPackage)scCs2|jjd}ddl}|j||dS(Nstwisted.trial.test.samplei(RRtsampleR(RRR((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_findModule.scCsDtjtd}|jj|}ddl}|j||dS(Ns	sample.pyi(Rtsibpatht__file__RRRR(RtpathRR((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt
test_findFile3scCs5|jjd}ddl}|j|j|dS(Ns!twisted.trial.test.sample.FooTesti(RRRRtFooTest(RRR((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_findObject9scCs|jt|jjddS(Nstwisted.trial.test.nonexistent(tfailUnlessRaisestAttributeErrorRR(R((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_findNonModule>s		cCs|jt|jjddS(Nt	nonextant(R$t
ValueErrorRR(R((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_findNonPackageCs		cCs/tjtd}|jt|jj|dS(Nsnonexistent.py(RRRR$R(RR(RR ((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_findNonFileHs(t__name__t
__module__RRRRR!R#R&R)R*(((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyR!s								tFileTestcBs_eZdZdZdZdZdZdZdZdZ	dZ
d	ZRS(
s/
    Tests for L{runner.filenameToModule}.
    cCs|jttjddS(Ntdoesntexist(R$R(RtfilenameToModule(R((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_notFileRs	cCs;tjtjtd}ddl}|j||dS(Ns	sample.pyi(RR/RRRRR(RRR((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_moduleInPathVscCs|jtjjdd|j|jtjt	j
j|jdd}|j|j
ddlm}|jt	j
j|jdt	j
j|jddS(s
        If passed the path to a file containing the implementation of a
        module within a package which is not on the import path,
        L{runner.filenameToModule} returns a module object loosely
        resembling the module defined by that file anyway.
        ttest_sampletgoodpackagestest_sample.pyi(R2iN(t
addCleanuptsystmodulestpoptNonet
mangleSysPathtoldPathRR/tosR tjointparenttnewPathR3R2RtsplitextR(RRR((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_moduleNotInPath\scCsAtjtjj|jd}ddl}|j||dS(NR3i(RR/R;R R<R=R3R(Rtpackage1R3((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_packageInPathsscCs|jtjjd|j|jtjtj	j
|jd}|j|jddl
}|jtj	j|jdtj	j|jddS(s
        If passed the path to a directory which represents a package which
        is not on the import path, L{runner.filenameToModule} returns a
        module object loosely resembling the package defined by that
        directory anyway.
        t__init__R3iNi(R4R5R6R7R9R:RR/R;R R<R=R>R3RR?R(RRAR3((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_packageNotInPathzscCs&|jttjtjtddS(Nt	directory(R$R(RR/RRR(R((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_directoryNotPackagescCs&|jttjtjtddS(Nsnotpython.py(R$R(RR/RRR(R((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_filenameNotPythonscCs|tjj|jd}t|d}|jtj|jz&t	j
|}|j||jWdtj
|XdS(Nsgoodpackage.pytw(R;R R<R=topentwriteRt
testModuletcloseRR/RRtremove(Rtfilenametfdtmodule((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_filenameMatchesPackages
cCstjtd}tj|ttjj|dd}|jz^t	j
|}|j|jj
dt	j
|tjj}|j|jj
dWdtj|XdS(sw
        Test loader against a filesystem directory. It should handle
        'path' and 'path/' the same way.
        t
goodDirectorys__init__.pyRHN(RRRR;tmkdirtfileR R<RLRR/tassert_R+tendswithtseptshutiltrmtree(RR tfRP((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_directorys

(R+R,t__doc__R0R1R@RBRDRFRGRQR[(((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyR-Ns								t
LoaderTestcBs7eZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!d Z"d!Z#RS("s(
    Tests for L{trial.TestLoader}.
    cCs#tj|_tjj|dS(N(RRRRtSysPathManglingTestR(R((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyRscsddl}|jj|j}|jdddgg|jD]}|j^q=dddg}tt|t	dfd|j_
|jj|j}|j|g|jD]}|j^qdS(Nittest_attest_bttest_cicsj|jdS(Ni(tgettshortDescription(tx(tsortDict(sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt<lambda>s(RRt	loadClasstAlphabetTestRt_testst_testMethodNametdicttziptrangetsorter(RRtsuiteR
tnewOrder((ResB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_sortCasess 	cCsQddl}|jj|jj}|jd|j|jd|jdS(Niittest_foo(RRt
loadMethodR"RrRtcountTestCasesRj(RRRo((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_loadMethodscCsmddl}|jj|jj}tj}|j||j|j	d|jt
|jddS(Nii(t	erroneousRRstTestRegularFailt	test_failRt
TestResulttrunRttestsRuntlentfailures(RRvRotresult((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_loadFailingMethods
cCswddl}|jt|jj||jt|jj|j|jt|jjd|jt|jjddS(Nitstringtfootbar(RR(RR$t	TypeErrorRRsR"(RR((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_loadNonMethods		cCsQddl}|jj|jj}|jd|j|jd|jdS(s
        A decorated test method for which the decorator has failed to set the
        method's __name__ correctly is loaded and its name in the class scope
        discovered.
        iNittest_badDecorator(RRRstDecorationTestRRRtRj(RRRo((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_loadBadDecoratorscCsQddl}|jj|jj}|jd|j|jd|jdS(s
        A decorated test method for which the decorator has set the method's
        __name__ correctly is loaded and the only name by which it goes is used.
        iNittest_goodDecorator(RRRsRRRRtRj(RRRo((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_loadGoodDecorators
	cCsQddl}|jj|jj}|jd|j|jd|jdS(s
        Load a decorated method which has been copied to a new name inside the
        class.  Thus its __name__ and its key in the class's __dict__ no
        longer match.
        iNittest_renamedDecorator(RRRsRRRRtRj(RRRo((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_loadRenamedDecorators
	cCsjddl}|jj|j}|jd|j|jddgg|jD]}|j^qPdS(Niittest_barRr(RRRgR"RRtRiRj(RRRoR
((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_loadClasss
cCszddl}|jt|jj||jt|jj|jj|jt|jjd|jt|jjddS(NiRRR(sfoosbar(RR$RRRgR"Rr(RR((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_loadNonClasss		cCs,ddl}|jt|jj|jdS(Ni(RR$R(RRgtNotATest(RR((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_loadNonTestCase scCs8ddl}|jj|}|jd|jdS(Nii
(RRt
loadModuleRRt(RRRo((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_loadModule&scCs}ddl}|jt|jj|j|jt|jj|jj|jt|jjd|jt|jjddS(NiRRR(sfoosbar(RR$RRRR"Rr(RR((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_loadNonModule,s			cCs8ddl}|jj|}|jd|jdS(Nii(R3RtloadPackageRRt(RR3Ro((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_loadPackage7scCs}ddl}|jt|jj|j|jt|jj|jj|jt|jjd|jt|jjddS(NiRRR(sfoosbar(RR$RRRR"Rr(RR((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_loadNonPackage=s			cCs)ddl}|jt|jj|dS(Ni(RR$RRR(RR((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_loadModuleAsPackageHscCs>ddl}|jj|dt}|jd|jdS(Nitrecursei(R3RRtTrueRRt(RR3Ro((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_loadPackageRecursiveNscCsIddl}|jj|}|j|j|jdjdjjdS(Nii(RRtloadAnythingRR+Rit	__class__R,(RRRo((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_loadAnythingOnModuleTscCs;ddl}|jj|j}|jd|jdS(Nii(RRRR"RRt(RRRo((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_loadAnythingOnClass[scCs>ddl}|jj|jj}|jd|jdS(Nii(RRRR"RrRRt(RRRo((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_loadAnythingOnMethodascCsTddl}|jj|}|jt||jj|jd|jdS(Nii(R3RRt
failUnlesst
isinstancetsuiteFactoryRRt(RR3Ro((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_loadAnythingOnPackagegscCsZddl}|jj|dt}|jt||jj|jd|jdS(NiRi(	R3RRRRRRRRt(RR3Ro((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt#test_loadAnythingOnPackageRecursivenscCs|jt|jjddS(NR3(R$RRR(R((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_loadAnythingOnStringus	cCsddl}|jj|dt}tj}|j||jt|j	|jdt
|jg|jD]\}}|j^qv}|j
|j|ddgdS(NiRispackage.test_bad_modulespackage.test_import_module(tpackageRRRRtReporterRzRtFalset
wasSuccessfulR|terrorsR
tsort(RRRoR~R
terrorR((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_importErrors|s
(
cCs[dtjfdY}|jj|}tj}|j||j|jdS(s
        L{TestLoader.loadClass} returns a suite with each test method
        represented by a different instances of the L{TestCase} they are
        defined on.
        tDistinctInstancescBseZdZdZRS(cSs
d|_dS(Nttest1Run(tfirst(R((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_1scSs|jt|ddS(NR(tassertFalsethasattr(R((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_2s(R+R,RR(((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyRs	N(	RtTestCaseRRgRRRzt
assertTrueR(RRRoR~((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_differentInstancess

cCsXddlm}|jj|}|jd|j|jdt|dddS(sp
        Check that C{test_suite} is used when present and other L{TestCase}s are
        not included.
        i(tmockcustomsuiteit
MyCustomSuitetnameN(ttwisted.trial.testRRRRRttgetattrR8(RRRo((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_loadModuleWith_test_suitescCsXddlm}|jj|}|jd|j|jdt|dddS(so
        Check that C{testSuite} is used when present and other L{TestCase}s are
        not included.
        i(tmockcustomsuite2iRRN(RRRRRRtRR8(RRRo((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_loadModuleWith_testSuitescCsBddlm}|jj|}|jdt|dddS(s
        Check that if C{testSuite} and C{test_suite} are both present in a
        module then C{testSuite} gets priority.
        i(tmockcustomsuite3t	testSuiteRN(RRRRRRR8(RRRo((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_loadModuleWithBothCustomscCsZd}ddlm}||j|_}z|jt|jj|Wd||_XdS(sz
        Make sure that any C{AttributeError}s raised by C{testSuite} are not
        swallowed by L{TestLoader}.
        cSstddS(Nsshould be reraised(R%(((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyRsi(RN(RRRtassertRaisesR%RR(RRRtoriginal((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt#test_customLoadRaisesAttributeErrors	cCs@t|}t|}|j|j|j||dS(N(RRR(Rttest1ttest2tnames1tnames2((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pytassertSuitesEquals


cCsJd}|jj||gt}|jj|t}|j||dS(s@
        Check that loadByNames ignores duplicate names
        s$twisted.trial.test.test_test_visitorN(RtloadByNamesRt
loadByNameR(RRPtsuite1tsuite2((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_loadByNamesDuplicatescCsPddg}|jj|}tjt|jj|}|j||dS(sM
        Check that loadByNames loads all the names that it is given
        R3spackage.test_moduleN(RRRt	TestSuitetmapRR(RR6RR((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_loadDifferentNamesscCsPddg}|jj|}tjt|jj|}|j||dS(su
        Check that test methods names which are inherited from are all
        loaded rather than just one.
        s$inheritancepackage.test_x.A.test_foos$inheritancepackage.test_x.B.test_fooN(RRRRRRR(RtmethodsRR((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_loadInheritedMethodss
	($R+R,R\RRqRuRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR(((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyR]sD		
		
	
			
		
														
				
			
		tZipLoadingTestcBseZdZRS(cCsaddlm}tj|||j|jd|jd7_|j|j|jgdS(Ni(tzipits.zip(ttwisted.test.test_pathsRR]RR=R9R:(RR((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyRs

(R+R,R(((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyRstPackageOrderingTestcBsSeZejdkrdZndZdZejdZ	dZ
dZRS(	iisPython 2.3 import semantics make this behavior incorrect on that version of Python as well as difficult to test.  The second import of a package which raised an exception the first time it was imported will succeed on Python 2.3, whereas it will fail on later versions of Python.  Trial does not account for this, so this test fails with inconsistencies between the expected and the received loader errors.cCstj|_|j|_tjj|jd}tj|t	tjj|ddj
tjj
|||j|j|jgdS(Ntuberpackages__init__.pytwb(RRRtmktempttopDirR;R R<tmakedirsRTRLRR^RR9R:(RR=((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyRs
"ccs{td}g}xC|jD]5}|jjddjdr|j|qqWt|d|}x
|D]}|jd}|dkr|Vqqg}x9|j	D]+}	t
j|	jr|j|	qqWt|d|}
x|
D]z}g}xC|j	D]5}
|
jjddjdr|j|
qqWt|d|}x|D]}|Vq`WqWqqWdS(s
        Right now, halfway by accident, trial sorts like this:

            1. all modules are grouped together in one list and sorted.

            2. within each module, the classes are grouped together in one list
               and sorted.

            3. finally within each class, each test method is grouped together
               in a list and sorted.

        This attempts to return a sorted list of testable thingies following
        those rules, so that we can compare the behavior of loadPackage.

        The things that show as 'cases' are errors from modules which failed to
        import, and test methods.  Let's gather all those together.
        Rt.ittest_tkeyR
N(RtwalkModulesRtsplitt
startswithR	tsortedtloadR8titerAttributesRt
isTestCase(RRntpkgttestModulesRKt
sortedModulestmodinfoRPttestClassestattribt
sortedClassestclsinfottestMethodstattrt
sortedMethodstmethinfo((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt_trialSortAlgorithms.


c	Csddl}||j_|jj|dt}tj|t}ttj	|}t|j
|}x[tt||D]D\}\}}|j
|j|jd||j|jfqW|j
t|t|dS(sG
        Verify that packages are loaded in the correct order.
        iNRs
#%d: %s != %s(RRRnRRRtdecorateRtlistRRt	enumerateRlRRR
R|(	RRnRRotresultingTeststmanifesttnumbertmanifestTestt
actualTest((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pytloadSortedPackagesAs"cCs|jdS(N(R(R((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_sortPackagesDefaultOrderVscCsd}|j|dS(NcSs%tj|}t|j}|S(N(RRRt	hexdigest(tstntd((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pytsillySorter[s(R(RR((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyttest_sortPackagesSillyOrderZs	(ii(R+R,R5tversion_infotskipRRRRRRR(((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyRs				-	(R\R;RXR5ttwisted.pythonRttwisted.python.hashlibRRRt
twisted.trialRRRttwisted.trial.itrialRttwisted.python.modulesRRRRR^R-R]RR(((sB/usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt<module>s 	-i@