
    Vh                     P    d Z ddlZddlmZ ddlmZmZmZ ddlm	Z	  G d d      Z
y)z\
Facilities for helping test code which interacts with Python's module system
to load code.
    N)
ModuleType)IterableListTuple)FilePathc                   ^    e Zd ZdZdee   ddfdZdeeee	f      ddfdZ
d
dedee   fd	Zy)TwistedModulesMixinz
    A mixin for C{twisted.trial.unittest.SynchronousTestCase} providing useful
    methods for manipulating Python's module system.
    sysPathreturnNc                     t         j                  dd dfd}| j                  |       |t         j                  dd y)zW
        Replace sys.path, for the duration of the test, with the given value.
        Nc                  ,     t         j                  d d  y N)syspath)originalSysPaths   S/home/dcms/DCMS/lib/python3.12/site-packages/twisted/python/test/modules_helpers.pycleanUpSysPathz:TwistedModulesMixin.replaceSysPath.<locals>.cleanUpSysPath   s    )CHHQK    r   N)r   r   
addCleanup)selfr
   r   r   s      @r   replaceSysPathz"TwistedModulesMixin.replaceSysPath   s2     ((1+	* 	'r   
sysModulesc                     t         j                  j                         dfd}| j                  |       t         j                  j	                          t         j                  j                  |       y)zZ
        Replace sys.modules, for the duration of the test, with the given value.
        Nc                      t         j                  j                          t         j                  j                          y r   )r   modulesclearupdate)originalSysModuless   r   cleanUpSysModulesz@TwistedModulesMixin.replaceSysModules.<locals>.cleanUpSysModules(   s&    KKKK12r   r   )r   r   copyr   r   r   )r   r   r    r   s      @r   replaceSysModulesz%TwistedModulesMixin.replaceSysModules"   sN     ![[--/	3 	)*:&r   pkgnamec                     t        | j                               }|j                  d      }|j                          |j                  d      j	                  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   )r   mktempchildmakedirs
setContent)r   r#   entrypkgs       r   pathEntryWithOnePackagez+TwistedModulesMixin.pathEntryWithOnePackage0   sG    
 'kk.)		- ++C0r   )r%   )__name__
__module____qualname____doc__r   strr   r   r   r   r"   r   r,    r   r   r	   r	      sX    

d3i 
D 
'HU3
?5K,L 'QU '	s 	QT 	r   r	   )r0   r   typesr   typingr   r   r   twisted.python.filepathr   r	   r2   r   r   <module>r6      s%   
   ( ( ,) )r   