ϪfPdZddlZddlmZddlmZmZmZddlm Z GddZ y)z\ Facilities for helping test code which interacts with Python's module system to load code. N) ModuleType)IterableListTuple)FilePathc^eZdZdZdeeddfdZdeeee fddfdZ d dede efd Z y) TwistedModulesMixinz A mixin for C{twisted.trial.unittest.SynchronousTestCase} providing useful methods for manipulating Python's module system. sysPathreturnNctjdddfd }|j||tjddy)zW Replace sys.path, for the duration of the test, with the given value. Nc,tjddyN)syspath)originalSysPathsE/usr/lib/python3/dist-packages/twisted/python/test/modules_helpers.pycleanUpSysPathz:TwistedModulesMixin.replaceSysPath..cleanUpSysPaths)CHHQKr N)rr addCleanup)selfr rrs @rreplaceSysPathz"TwistedModulesMixin.replaceSysPaths2((1+ * ' r sysModulesctjjdfd }|j|tjj tjj |y)zZ Replace sys.modules, for the duration of the test, with the given value. Nctjjtjjyr)rmodulesclearupdate)originalSysModulessrcleanUpSysModulesz@TwistedModulesMixin.replaceSysModules..cleanUpSysModules(s& KK    KK  1 2rr)rrcopyrrr)rrr rs @rreplaceSysModulesz%TwistedModulesMixin.replaceSysModules"sN![[--/ 3 )*  :&rpkgnamect|j}|jd}|j|jdj d|S)z Generate a L{FilePath} with one package, named C{pkgname}, on it, and return the L{FilePath} of the path entry. test_packagez __init__.pyr)rmktempchildmakedirs setContent)rr#entrypkgs rpathEntryWithOnePackagez+TwistedModulesMixin.pathEntryWithOnePackage0sG 'kk.)  - ++C0 r)r%) __name__ __module__ __qualname____doc__rstrrrrrr"rr,rrr r sX d3i D  'HU3 ?5K,L 'QU ' s QT rr ) r0rtypesrtypingrrrtwisted.python.filepathrr r2rrr6s%  ((,))r