
    tf                     X    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
dS )z\
Facilities for helping test code which interacts with Python's module system
to load code.
    N)
ModuleType)IterableListTuple)FilePathc                   x    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dS )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}|                     |           |t           j        dd<   dS )zW
        Replace sys.path, for the duration of the test, with the given value.
        Nr   c                  *     t           j        d d <   d S N)syspath)originalSysPaths   b/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/python/test/modules_helpers.pycleanUpSysPathz:TwistedModulesMixin.replaceSysPath.<locals>.cleanUpSysPath   s    )CHQQQKKK    r   N)r   r   
addCleanup)selfr
   r   r   s      @r   replaceSysPathz"TwistedModulesMixin.replaceSysPath   sY     (111+	* 	* 	* 	* 	* 	* 	'''r   
sysModulesc                     t           j                                        dfd}|                     |           t           j                                         t           j                            |           dS )zZ
        Replace sys.modules, for the duration of the test, with the given value.
        r   Nc                      t           j                                         t           j                                        d S r   )r   modulesclearupdate)originalSysModuless   r   cleanUpSysModulesz@TwistedModulesMixin.replaceSysModules.<locals>.cleanUpSysModules(   s4    KK122222r   r   )r   r   copyr   r   r   )r   r   r    r   s      @r   replaceSysModulesz%TwistedModulesMixin.replaceSysModules"   s|     ![--//	3 	3 	3 	3 	3 	3 	)***:&&&&&r   test_packagepkgnamec                     t          |                                           }|                    d          }|                                 |                    d                              d           |S )z
        Generate a L{FilePath} with one package, named C{pkgname}, on it, and
        return the L{FilePath} of the path entry.
        r#   z__init__.pyr   )r   mktempchildmakedirs
setContent)r   r$   entrypkgs       r   pathEntryWithOnePackagez+TwistedModulesMixin.pathEntryWithOnePackage0   s\    
 ''kk.))		-  ++C000r   )r#   )__name__
__module____qualname____doc__r   strr   r   r   r   r"   r   r,    r   r   r	   r	      s         

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   