HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.10/test/test_importlib/__pycache__/test_namespace_pkgs.cpython-310.pyc
o

�it0�@s�ddlZddlZddlZddlZddlZddlZddlZddlmZej	dd��Z
ej	dd��ZGdd�dej�Z
Gd	d
�d
e
�ZGdd�de
�ZGd
d�de
�ZGdd�de
�ZGdd�de
�ZGdd�de
�ZGdd�de
�ZGdd�de
�ZGdd�de
�ZGdd�de
�ZGdd�de
�ZGdd �d e
�ZGd!d"�d"e
�ZGd#d$�d$e
�ZGd%d&�d&e
�ZGd'd(�d(e
�Zed)kr�e��dSdS)*�N)�utilc	csZ�tj}tj��}zdVW|t_tj��tj�|�dS|t_tj��tj�|�w)z�
    Make sure sys.modules is the same object and has the same content
    when exiting the context as when entering.

    Similar to importlib.test.util.uncache, but doesn't require explicit
    names.
    N)�sys�modules�copy�clear�update)Zsys_modules_savedZsys_modules_copy�r�D/usr/local/lib/python3.10/test/test_importlib/test_namespace_pkgs.py�sys_modules_contexts�	

�
r
c	ks��|�dtj�|�dtj�tjdi|��}|�'t��dVWd�n1s+wYWd�dSWd�dS1sCwYdS)z�
    Save import state and sys.modules cache and restore it on exit.
    Typical usage:

    >>> with namespace_tree_context(path=['/tmp/xxyy/portion1',
    ...         '/tmp/xxyy/portion2']):
    ...     pass
    �	meta_path�
path_hooksNr)�
setdefaultrrrrZimport_stater
)�kwargsZimport_contextrrr	�namespace_tree_context&s�P�rc@s6eZdZdZej�ej�e�d�Z	dd�Z
dd�ZdS)�NamespacePackageTestzj
    Subclasses should define self.root and self.paths (under that root)
    to be added to sys.path.
    Znamespace_pkgscs2�fdd��jD��_t�jd��_�j��dS)Ncsg|]
}tj��j|��qSr)�os�path�join�root)�.0r��selfrr	�
<listcomp>?s�z.NamespacePackageTest.setUp.<locals>.<listcomp>)r)�pathsZresolved_pathsr�ctx�	__enter__rrrr	�setUp>s

�zNamespacePackageTest.setUpcCs|j�ddd�dS)N)r�__exit__rrrr	�tearDownEszNamespacePackageTest.tearDownN)�__name__�
__module__�__qualname__�__doc__rrr�dirname�__file__rrrrrrr	r7s
rc@�*eZdZdgZdd�Zdd�Zdd�ZdS)	�SingleNamespacePackage�portion1cC�ddl}|�|jjd�dS�Nr�portion1 foo one��foo.one�assertEqual�one�attr�r�foorrr	�test_simple_packageM�z*SingleNamespacePackage.test_simple_packagecC�8|�t��
ddl}Wd�dS1swYdS�Nr��assertRaises�ImportError�foo.twor0rrr	�test_cant_import_otherQ�
"�z-SingleNamespacePackage.test_cant_import_othercCsVddl}t���t�d�|�|jj�|�d�Wd�dS1s$wYdS)Nr�ignorez<module 'foo' (namespace)>)r,�warnings�catch_warnings�simplefilterr-�__spec__�loader�module_reprr0rrr	�test_module_reprUs

�"�z'SingleNamespacePackage.test_module_reprN)rr r!rr2r:rCrrrr	r&Js
r&c@�eZdZdgZdd�ZdS)�DynamicPathNamespacePackager'cCs~ddl}|�|jjd�|�t��ddl}Wd�n1s wYtj�	t
j�|jd��ddl}|�|j
jd�dS)Nrr*�portion2�portion2 foo two)r,r-r.r/r7r8r9rr�appendrrr�twor0rrr	�test_dynamic_path`s
�z-DynamicPathNamespacePackage.test_dynamic_pathN)rr r!rrJrrrr	rE]�rEc@rD)�CombinedNamespacePackages�
both_portionscC�4ddl}ddl}|�|jjd�|�|jjd�dS�Nrzboth_portions foo one�both_portions foo two�r,r9r-r.r/rIr0rrr	�test_importss�z&CombinedNamespacePackages.test_importsN�rr r!rrRrrrr	rLprKrLc@�eZdZddgZdd�ZdS)�SeparatedNamespacePackagesr'rFcCrN)Nrr*rGrQr0rrr	rR}rSz'SeparatedNamespacePackages.test_importsNrTrrrr	rVz�rVc@rD)�-SeparatedNamespacePackagesCreatedWhileRunningr'c	Cs4t����}tj�|�ddl}|�|jjd�|�	t
��ddl}Wd�n1s+wYtj�
|d�}t�|�tj�
|d�}t|ddd��
}|�d�Wd�n1sZwY|�	t
��ddl}Wd�n1sswYt��ddl}|�|jjd	�Wd�dS1s�wYdS)
Nrr*r1zjust_created.py�wzutf-8)�encodingzattr = "just_created foo"zjust_created foo)�tempfile�TemporaryDirectoryrrrHr,r-r.r/r7r8Zfoo.just_createdrr�mkdir�open�write�	importlib�invalidate_cachesZjust_created)rZtemp_dirr1�namespace_pathZmodule_path�filerrr	�test_invalidate_caches�s(

�
�
�"�zDSeparatedNamespacePackagesCreatedWhileRunning.test_invalidate_cachesN)rr r!rrdrrrr	rX�rKrXc@s,eZdZddgZdd�Zdd�Zdd�Zd	S)
�%SeparatedOverlappingNamespacePackagesr'rMcCrN�Nrr*rPrQr0rrr	�test_first_path_wins�rSz:SeparatedOverlappingNamespacePackages.test_first_path_winscCs>tj��ddl}ddl}|�|jjd�|�|jjd�dSrO)	rr�reverser,r9r-r.r/rIr0rrr	�test_first_path_wins_again�s

z@SeparatedOverlappingNamespacePackages.test_first_path_wins_againcCrNrf)r9r,r-r.r/rIr0rrr	�+test_first_path_wins_importing_second_first�rSzQSeparatedOverlappingNamespacePackages.test_first_path_wins_importing_second_firstN)rr r!rrgrirjrrrr	re�s
rec@�"eZdZdgZdd�Zdd�ZdS)�SingleZipNamespacePackage�top_level_portion1.zipcCr(r)r+r0rrr	r2�r3z-SingleZipNamespacePackage.test_simple_packagecCr4r5r6r0rrr	r:�r;z0SingleZipNamespacePackage.test_cant_import_otherN�rr r!rr2r:rrrr	rl��rlc@rU)�SeparatedZipNamespacePackagesrmrFcCsTddl}ddl}|�|jjd�|�|jjd�|�d|jj�|�d|jj�dS)Nrr*rGrm�.zip)	r,r9r-r.r/rI�assertInr$�assertNotInr0rrr	rR�sz*SeparatedZipNamespacePackages.test_importsNrTrrrr	rp�rWrpc@rk)�SingleNestedZipNamespacePackage�#nested_portion1.zip/nested_portion1cCr(r)r+r0rrr	r2�r3z3SingleNestedZipNamespacePackage.test_simple_packagecCr4r5r6r0rrr	r:�r;z6SingleNestedZipNamespacePackage.test_cant_import_otherNrnrrrr	rt�rortc@rU)�#SeparatedNestedZipNamespacePackagesrurFcCsbddl}ddl}|�|jjd�|�|jjd�tj�dd�}|�	||jj
�|�d|jj
�dS)Nrr*rGznested_portion1.zipZnested_portion1rq)r,r9r-r.r/rIrrrrrr$rs)rr1�fnrrr	rR�sz0SeparatedNestedZipNamespacePackages.test_importsNrTrrrr	rv�rWrvc@seZdZgd�Zdd�ZdS)�
LegacySupport)Znot_a_namespace_pkgr'rFrMcCsbddl}|�t��ddl}Wd�n1swY|�d|j�|�dt|j��	��dS)Nr�__init__�	namespace)
r,r7r8r9rrr$rs�str�
__loader__�lowerr0rrr	�+test_non_namespace_package_takes_precedence�s
�z9LegacySupport.test_non_namespace_package_takes_precedenceN)rr r!rr~rrrr	rx�rWrxc@s$eZdZddgZdd�Zdd�ZdS)�DynamicPathCalculationZproject1Zproject2cCs�ddl}|�t|j�d�|�t|jj�d�ddl}|�t|j�d�|�t|jj�d�|�|jjjd�|�|jjjd�|�	t
��ddl}Wd�n1sTwY|�t|j�d�|�t|jj�d�dS)Nr��parent child one�parent child two)�parent.child.oner-�len�__path__�child�parent.child.twor.r/rIr7r8�parent.child.three�r�parentrrr	�test_project3_fails�s
�z*DynamicPathCalculation.test_project3_failscCsddl}|�t|j�d�|�t|jj�d�ddl}|�t|j�d�|�t|jj�d�|�|jjjd�|�|jjjd�|�	t
��ddl}Wd�n1sTwYtj
�tj
�|jd��ddl}|�t|j�d�|�t|jj�d�|�|jjjd�dS)Nrr�r�r�Zproject3�zparent child three)r�r-r�r�r�r�r.r/rIr7r8r�rrrHrrrZthreer�rrr	�test_project3_succeeds
s 
�z-DynamicPathCalculation.test_project3_succeedsN)rr r!rr�r�rrrr	r�src@s(eZdZdgZejdd��Zdd�ZdS)�ZipWithMissingDirectoryzmissing_directory.zipcCsddl}dSr5)r,r0rrr	�test_missing_directory)sz.ZipWithMissingDirectory.test_missing_directorycCr()Nrzmissing_directory foo two)Zbar.twor-rIr/)rZbarrrr	�test_present_directory9sz.ZipWithMissingDirectory.test_present_directoryN)rr r!r�unittestZexpectedFailurer�r�rrrr	r�&s

r�c@rD)�"ModuleAndNamespacePackageInSameDirZmodule_and_namespace_packagecCsddl}|�|jd�dS)Nrz	in module)�a_testr-r/)rr�rrr	�$test_module_before_namespace_packageBszGModuleAndNamespacePackageInSameDir.test_module_before_namespace_packageN)rr r!rr�rrrr	r�?rKr�c@r%)	�ReloadTestsr'cCs&ddl}t�|�}|�|jjd�dSr))r,r`�reloadr-r.r/r0rrr	r2Ls
zReloadTests.test_simple_packagecCs|ddl}|�t��ddl}Wd�n1swYt�|�}|�t��
ddl}Wd�dS1s7wYdSr5)r1r7r8r9r`r�r0rrr	r:Qs
�

"�z"ReloadTests.test_cant_import_othercCsxddl}|�t��ddl}Wd�n1swYtj�tj�|j	d��t
�|�}ddl}|�|j
jd�dS)NrrFrG)r,r7r8r9rrrHrrrr`r�r-rIr/r0rrr	rJYs
�
zReloadTests.test_dynamic_pathN)rr r!rr2r:rJrrrr	r�Is
r�c@r%)	�LoaderTestsr'cCs*ddl}|�|j|jj�|�|j�dSr5)r1r-r|r@rAZassertIsNotNoner0rrr	�!test_namespace_loader_consistencyjsz-LoaderTests.test_namespace_loader_consistencycCs&ddl}|�|jj�|�|j�dSr5)r1ZassertIsNoner@�originr$r0rrr	�!test_namespace_origin_consistencypsz-LoaderTests.test_namespace_origin_consistencycCs0ddl}tj�|jdd�}|�|jd|�dS)Nrr'r1)r1rrrrr-r�)rr1Z
expected_pathrrr	�test_path_indexablevszLoaderTests.test_path_indexableN)rr r!rr�r�r�rrrr	r�gs
r��__main__) �
contextlibr`rrr[r�r=Ztest.test_importlibr�contextmanagerr
rZTestCaserr&rErLrVrXrerlrprtrvrxrr�r�r�r�r�mainrrrr	�<module>s@




"
-
�