Your IP : 172.28.240.42


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


=Nc@sdZddlZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZddlm
Z
ddlmZddlmZd	efd
YZdefdYZd
efdYZdefdYZdefdYZdS(sV
Tests for twisted.python.modules, abstract access to imported or importable
objects.
iN(tTestCase(tmodules(tFilePath(tnamedAny(tTwistedModulesTestCase(tzipitt
BasicTestscBsteZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
RS(cCstdd}|j}|jd}|jdj||jd}|j|jdj||jdjd|j}|jd}|jdj||jd}|j|jdj||jdjd|j|j|jgtjd}z,g|j	d	t
D]}	|	j^q:}
Wd
x3tjj
D]"}|jdrctj|=qcqcWXdddd
g}|j|
|d
S(sd
        Duplicate packages are not yielded when iterating over namespace
        packages.
        tpkgutilsBimport pkgutil; __path__ = pkgutil.extend_path(__path__, __name__)ttest_packages__init__.pytnested_packages	module.pyts
module2.pytimportPackagesNstest_package.nested_packages"test_package.nested_package.modules#test_package.nested_package.module2(t
__import__tpathEntryWithOnePackagetchildt
setContenttmakedirstreplaceSysPathtpathRt	getModuletwalkModulestTruetnametsystkeyst
startswithtassertEqual(tselftnamespaceBoilerplatetentryttestPackagePathtnestedEntrytanotherEntrytanotherPackagePathtanotherNestedEntrytmoduletmodtwalkedNamestexpected((s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pyttest_namespacedPackagess8


,	c
Cstg}tjd|jjgd|jdidididd6}|j|g|j|djtdS(s
        If a package has been explicitly forbidden from importing by setting a
        C{None} key in sys.modules under its name,
        L{modules.PythonPath.__getitem__} should still be able to retrieve an
        unloaded L{modules.PythonModule} for that package.
        tsysPathtmoduleLoadert
importerCachetsysPathHookst
moduleDictRN(	Rt
PythonPathR
RtappendtNoneRtisLoadedtFalse(Rt
shouldNotLoadR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pyttest_unimportablePackageGetItemjs	cCs|j}|j|jg|jidd6ttj}|jg|D]}|j	^qRdg|j|dj
tdS(s	
        If a package has been explicitly forbidden from importing by setting a
        C{None} key in sys.modules under its name, L{modules.walkModules} should
        still be able to retrieve an unloaded L{modules.PythonModule} for that
        package.
        RiN(R
RRtreplaceSysModulesR/tlistRRRRR0R1(RtexistentPathtwalkedtm((s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pyt#test_unimportablePackageWalkModules{s
cCs|j}t|j}|j|j|j|jgtjdg}t	tj
}tjj|jt	tj
}|j
|||j
||dS(s~
        Verify that L{modules.walkModules} ignores entries in sys.path which
        do not exist in the filesystem.
        RN(R
RtmktemptfailIftexistsRRRRR5RRR.R(RR6tnonexistentPathR&t
beforeModulestafterModules((s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pyttest_nonexistentPathsscCs|j}t|j}|j|j|jd|j|jgtt	j
}tjj|jtt	j
}|j
||dS(s
        Verify that L{modules.walkModules} ignores entries in sys.path which
        refer to regular files in the filesystem.
        szip file or whatever
N(R
RR:R;R<RRRR5RRRR.R(RR6tnonDirectoryPathR>R?((s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pyttest_nonDirectoryPathss
cCs&|jtjd|jddS(s
        Scrounge around in the top-level module namespace and make sure that
        Twisted shows up, and that the module thusly obtained is the same as
        the module that we find when we look for it explicitly by name.
        ttwistedN(RRRtfindByIteration(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pyttest_twistedShowsUpscCs5|jtjd|jddtjddS(so
        Verify that the walkModules APIs will give us back subpackages, not just
        subpackages.
        stwisted.pythontwhereRCN(RRRRD(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pyttest_dottedNamesscCs;x4tjD]&}|jd|jkd|jq
WdS(s
        Verify that the iterModules API will only return top-level modules and
        packages, not submodules or subpackages.
        t.s9no nested modules should be returned from iterModules: %rN(RtiterModulesR;RtfilePath(RR#((s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pyttest_onlyTopModuless
cCskxdddddgD]P}t|}|jtj|j||j|j|j|qWdS(sl
        Verify that we can locate and load packages, modules, submodules, and
        subpackages.
        tosRCstwisted.pythonstwisted.python.reflectN(RtfailUnlessIdenticalRRtloadRD(RtnR8((s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pyttest_loadPackagesAndModuless
cCsFx?ddddgD]+}|jtj|jjjtjqWdS(su
        Verify that path entries discovered via module loading are, in fact, on
        sys.path somewhere.
        RLRCstwisted.pythonstwisted.python.reflectN(tfailUnlessInRRt	pathEntryRJRR(RRO((s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pyttest_pathEntriesOnPaths
cst|j}|jtjd|jg}|jfd}|jdjdt	j
|jdt|jt
|jd||_|j|dj|jddS(	s~
        Verify that .py files will always be preferred to .pyc files, regardless of
        directory listing order.
        R(cs1|}|jfd}||_|S(Ncs!}|j|j|S(N(tsorttreverse(tx(toriginalChildren(s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pytevilChildrens	

(tchildren(tpathNametoRX(toriginalSmartPath(RWs=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pyt_evilSmartPaths
		sabcd.pys
tquietitabcdN(RR:tcreateDirectoryRR-Rt
_smartPathRRt
compilealltcompile_dirRRtlenRYRJ(RtmypathtppR]((R\s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pyttest_alwaysPreferPys
		cCst|j}|jtjd|jg}|jd}|j|jdjdtjj	|jt
dzCt|j}|j
t|d|j
|djdWdtjd=tjj|jXdS(s
        A package can delete its __path__ for some reasons,
        C{modules.PythonPath} should be able to deal with it.
        R(R_s__init__.pys
del __path__
iiN(RR:R`RR-RRRRR.RR5RRRdRtremove(RReRftsubpathtl((s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pyttest_packageMissingPaths



(t__name__t
__module__R'R3R9R@RBRERGRKRPRSRgRk(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pyRs	N					
					tPathModificationTestcBszeZdZejjZdZdZe	dZ
dZdZde_
dZdZd	Zd
ZRS(sp
    These tests share setup/cleanup behavior of creating a dummy package and
    stuffing some code in it.
    cCs|j|_t|j|_|jjd|jf|_|jj|j|_|jj|jjdj	d|jjdj	d|jjdj	d|jjdj	dt
|_dS(Nspyspacetests%ds__init__.pyR
sa.pysb.pysc__init__.py(R:tpathExtensionNameRt
pathExtensionR`t
_serialnumtpackageNameRtpackagePathRR1t	pathSetUp(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pytsetUp5s

cCs0|jstt|_tjj|jdS(N(RttAssertionErrorRRRR.Ro(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pyt
_setupSysPathCs	cCs|j}t|}|j|jdjd|jjdjd|f|jtj|j	}|j
|j|j	d|d||d|j
|djj
ddS(	Ns	foozle.pysx = 123
s__init__.pys__path__.append(%r)
s.foozleRtfoozlei{(R:RR`RRRsRwRRRrRRDRNRV(RtdoImporttmoddir2tfpmdtmodinfo((s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pyt_underUnderPathTestIs

cCs|jdS(s]
        Verify that iterModules will honor the __path__ of already-loaded packages.
        N(R}(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pyt"test_underUnderPathAlreadyImportedZscCs|jtdS(s]
        Verify that iterModules will honor the __path__ of already-loaded packages.
        N(R}R1(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pyt%test_underUnderPathNotAlreadyImportedass1This may be impossible but it sure would be nice.cCshtj|j}g|jD]}|jjdd^q}|j|j|dddgdS(NRHitatbt	c__init__(RRRrRIRtsplitRTR(RtpkginfoR|tnfni((s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pyt_listModulesls
,
cCs|j|jdS(s
        Make sure the module list comes back as we expect from iterModules on a
        package, whether zipped or not.
        N(RwR(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pyttest_listingModulests
cCs%|jt|j|jdS(s
        Make sure the module list comes back as we expect from iterModules on a
        package, whether zipped or not, even if the package has already been
        imported.
        N(RwRRrR(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pyt"test_listingModulesAlreadyImported}s

cCs`|jr\d}tjj|jks7t|d|jtjks\t|dndS(Ns<path cleanup failed: don't be surprised if other tests breaks, 1s, 2(RtRRtpopRoRv(RtHORK((s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pyttearDowns	((RlRmt__doc__t	itertoolstcounttnextRqRuRwRR}R~RttodoRRRR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pyRn,s									t
RebindingTestcBs eZdZdZdZRS(s
    These tests verify that the default path interrogation API works properly
    even when sys.path has been rebound to a different object.
    cCsI|jstt|_tj|_tjt_tjj|jdS(N(RtRvRRRtsavedSysPathR.Ro(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pyRws
	
cCs|jr|jt_ndS(sF
        Clean up sys.path by re-binding our original object.
        N(RtRRR(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pyRs	(RlRmRRwR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pyRs	tZipPathModificationTestcBseZdZRS(cCs_|jstt|j|jd|jd7_tj|jsNttj|dS(Ns.zip(RtRvRRotzipfilet
is_zipfileRnRw(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pyRws
(RlRmRw(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pyRstPythonPathTestCasecBs eZdZdZdZRS(s
    Tests for the class which provides the implementation for all of the
    public API of L{twisted.python.modules}, L{PythonPath}.
    csdtfdYfd}dg}i}|g}i}d}tj|||||}t|j|jtd|jtfddS(	s}
        Make sure that the behavior when encountering an unknown importer
        type is not catastrophic failure.
        tSecretImportercBseZRS((RlRm(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pyRscsS(N((R(R(s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pythookssexample/pathcSsdS(N(R/(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pyt	sysloadersicsddS(NiR#(((tentries(s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pyt<lambda>sN(	tobjectRR-R5titerEntriesRRdtassertRaisestKeyError(RRtsyspatht
sysmodulestsyshookstsyscacheRtspace((RRs=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pyttest_unhandledImporters			cCstjgtjgi}|t}|j|jg}|j|ddt|j|ddtt	j
jjdtd|jt
|d|j|jtdS(s
        If the path a module loaded with L{PythonPath.__getitem__} is not
        present in the path importer cache, a warning is emitted, but the
        L{PythonModule} is returned as usual.
        itcategorytmessages
 (for module sR) not in path importer cache (PEP 302 violation - check your local configuration).iN(RR-RRlt
flushWarningsttest_inconsistentImporterCacheRtUserWarningRRCt__file__tparenttdirnameRdR(RRt
thisModuletwarnings((s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pyRs
((RlRmRRR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pyRs	(RRRRRbRCttwisted.trial.unittestRttwisted.pythonRttwisted.python.filepathRttwisted.python.reflectRt#twisted.python.test.modules_helpersRttwisted.test.test_pathsRRRnRRR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_modules.pyt<module>s"f