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.7/test/test_importlib/__pycache__/test_namespace_pkgs.cpython-37.pyc
B

��g~)�@shddlZddlZddlZddlZddlZddlmZejdd��Zejdd��Z	Gdd�dej
�ZGd	d
�d
e�ZGdd�de�Z
Gd
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�Zed'k�rde��dS)(�N)�utilc	cs>tj}tj��}z
dVWd|t_tj��tj�|�XdS)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�C/usr/local/lib/python3.7/test/test_importlib/test_namespace_pkgs.py�sys_modules_contexts	


r
c
ksT|�dtj�|�dtj�tjf|�}|�t��dVWdQRXWdQRXdS)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_hooksN)�
setdefaultrrrrZimport_stater
)�kwargsZimport_contextrrr	�namespace_tree_context$s
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>>sz.NamespacePackageTest.setUp.<locals>.<listcomp>)r)�pathsZresolved_pathsr�ctx�	__enter__)rr)rr	�setUp<szNamespacePackageTest.setUpcCs|j�ddd�dS)N)r�__exit__)rrrr	�tearDownCszNamespacePackageTest.tearDownN)�__name__�
__module__�__qualname__�__doc__rrr�dirname�__file__rrrrrrr	r5src@s*eZdZdgZdd�Zdd�Zdd�ZdS)	�SingleNamespacePackage�portion1cCsddl}|�|jjd�dS)Nrzportion1 foo one)�foo.one�assertEqual�one�attr)r�foorrr	�test_simple_packageKsz*SingleNamespacePackage.test_simple_packagec	Cs"|�t��ddl}WdQRXdS)Nr)�assertRaises�ImportError�foo.two)rr*rrr	�test_cant_import_otherOsz-SingleNamespacePackage.test_cant_import_othercCsddl}|�t|�d�dS)Nrz<module 'foo' (namespace)>)r&r'�repr)rr*rrr	�test_module_reprSsz'SingleNamespacePackage.test_module_reprN)rrr rr+r/r1rrrr	r$Hsr$c@seZdZdgZdd�ZdS)�DynamicPathNamespacePackager%c	Csjddl}|�|jjd�|�t��ddl}WdQRXtj�	t
j�|jd��ddl}|�|j
jd�dS)Nrzportion1 foo one�portion2zportion2 foo two)r&r'r(r)r,r-r.rr�appendrrr�two)rr*rrr	�test_dynamic_path[sz-DynamicPathNamespacePackage.test_dynamic_pathN)rrr rr6rrrr	r2Xsr2c@seZdZdgZdd�ZdS)�CombinedNamespacePackages�
both_portionscCs4ddl}ddl}|�|jjd�|�|jjd�dS)Nrzboth_portions foo onezboth_portions foo two)r&r.r'r(r)r5)rr*rrr	�test_importsnsz&CombinedNamespacePackages.test_importsN)rrr rr9rrrr	r7ksr7c@seZdZddgZdd�ZdS)�SeparatedNamespacePackagesr%r3cCs4ddl}ddl}|�|jjd�|�|jjd�dS)Nrzportion1 foo onezportion2 foo two)r&r.r'r(r)r5)rr*rrr	r9xsz'SeparatedNamespacePackages.test_importsN)rrr rr9rrrr	r:usr:c@s,eZdZddgZdd�Zdd�Zdd�Zd	S)
�%SeparatedOverlappingNamespacePackagesr%r8cCs4ddl}ddl}|�|jjd�|�|jjd�dS)Nrzportion1 foo onezboth_portions foo two)r&r.r'r(r)r5)rr*rrr	�test_first_path_wins�sz:SeparatedOverlappingNamespacePackages.test_first_path_winscCs>tj��ddl}ddl}|�|jjd�|�|jjd�dS)Nrzboth_portions foo onezboth_portions foo two)	rr�reverser&r.r'r(r)r5)rr*rrr	�test_first_path_wins_again�s

z@SeparatedOverlappingNamespacePackages.test_first_path_wins_againcCs4ddl}ddl}|�|jjd�|�|jjd�dS)Nrzportion1 foo onezboth_portions foo two)r.r&r'r(r)r5)rr*rrr	�+test_first_path_wins_importing_second_first�szQSeparatedOverlappingNamespacePackages.test_first_path_wins_importing_second_firstN)rrr rr<r>r?rrrr	r;sr;c@s"eZdZdgZdd�Zdd�ZdS)�SingleZipNamespacePackageztop_level_portion1.zipcCsddl}|�|jjd�dS)Nrzportion1 foo one)r&r'r(r))rr*rrr	r+�sz-SingleZipNamespacePackage.test_simple_packagec	Cs"|�t��ddl}WdQRXdS)Nr)r,r-r.)rr*rrr	r/�sz0SingleZipNamespacePackage.test_cant_import_otherN)rrr rr+r/rrrr	r@�sr@c@seZdZddgZdd�ZdS)�SeparatedZipNamespacePackagesztop_level_portion1.zipr3cCsTddl}ddl}|�|jjd�|�|jjd�|�d|jj�|�d|jj�dS)Nrzportion1 foo onezportion2 foo twoztop_level_portion1.zipz.zip)	r&r.r'r(r)r5�assertInr#�assertNotIn)rr*rrr	r9�sz*SeparatedZipNamespacePackages.test_importsN)rrr rr9rrrr	rA�srAc@s"eZdZdgZdd�Zdd�ZdS)�SingleNestedZipNamespacePackagez#nested_portion1.zip/nested_portion1cCsddl}|�|jjd�dS)Nrzportion1 foo one)r&r'r(r))rr*rrr	r+�sz3SingleNestedZipNamespacePackage.test_simple_packagec	Cs"|�t��ddl}WdQRXdS)Nr)r,r-r.)rr*rrr	r/�sz6SingleNestedZipNamespacePackage.test_cant_import_otherN)rrr rr+r/rrrr	rD�srDc@seZdZddgZdd�ZdS)�#SeparatedNestedZipNamespacePackagesz#nested_portion1.zip/nested_portion1r3cCsbddl}ddl}|�|jjd�|�|jjd�tj�dd�}|�	||jj
�|�d|jj
�dS)Nrzportion1 foo onezportion2 foo twoznested_portion1.zipZnested_portion1z.zip)r&r.r'r(r)r5rrrrBr#rC)rr*�fnrrr	r9�sz0SeparatedNestedZipNamespacePackages.test_importsN)rrr rr9rrrr	rE�srEc@s eZdZddddgZdd�ZdS)�
LegacySupportZnot_a_namespace_pkgr%r3r8c	CsNddl}|�t��ddl}WdQRX|�d|j�|�dt|j��	��dS)Nr�__init__�	namespace)
r&r,r-r.rBr#rC�str�
__loader__�lower)rr*rrr	�+test_non_namespace_package_takes_precedence�s
z9LegacySupport.test_non_namespace_package_takes_precedenceN)rrr rrMrrrr	rG�srGc@s$eZdZddgZdd�Zdd�ZdS)�DynamicPathCalculationZproject1Zproject2c	Cs�ddl}|�t|j�d�|�t|jj�d�ddl}|�t|j�d�|�t|jj�d�|�|jjjd�|�|jjjd�|�	t
��ddl}WdQRX|�t|j�d�|�t|jj�d�dS)Nr�zparent child onezparent child two)�parent.child.oner'�len�__path__�child�parent.child.twor(r)r5r,r-�parent.child.three)r�parentrrr	�test_project3_fails�sz*DynamicPathCalculation.test_project3_failsc	Cs�ddl}|�t|j�d�|�t|jj�d�ddl}|�t|j�d�|�t|jj�d�|�|jjjd�|�|jjjd�|�	t
��ddl}WdQRXtj
�tj
�|jd��ddl}|�t|j�d�|�t|jj�d�|�|jjjd�dS)NrrOzparent child onezparent child twoZproject3�zparent child three)rPr'rQrRrSrTr(r)r5r,r-rUrrr4rrrZthree)rrVrrr	�test_project3_succeeds�sz-DynamicPathCalculation.test_project3_succeedsN)rrr rrWrYrrrr	rN�srNc@s(eZdZdgZejdd��Zdd�ZdS)�ZipWithMissingDirectoryzmissing_directory.zipcCsddl}dS)Nr)r&)rr*rrr	�test_missing_directorysz.ZipWithMissingDirectory.test_missing_directorycCsddl}|�|jjd�dS)Nrzmissing_directory foo two)Zbar.twor'r5r))rZbarrrr	�test_present_directorysz.ZipWithMissingDirectory.test_present_directoryN)rrr r�unittestZexpectedFailurer[r\rrrr	rZ�srZc@seZdZdgZdd�ZdS)�"ModuleAndNamespacePackageInSameDirZmodule_and_namespace_packagecCsddl}|�|jd�dS)Nrz	in module)�a_testr'r))rr_rrr	�$test_module_before_namespace_packageszGModuleAndNamespacePackageInSameDir.test_module_before_namespace_packageN)rrr rr`rrrr	r^sr^c@s*eZdZdgZdd�Zdd�Zdd�ZdS)	�ReloadTestsr%cCs&ddl}t�|�}|�|jjd�dS)Nrzportion1 foo one)r&�	importlib�reloadr'r(r))rr*rrr	r+%s
zReloadTests.test_simple_packagec	CsRddl}|�t��ddl}WdQRXt�|�}|�t��ddl}WdQRXdS)Nr)r*r,r-r.rbrc)rr*rrr	r/*s
z"ReloadTests.test_cant_import_otherc	Csdddl}|�t��ddl}WdQRXtj�tj�|j	d��t
�|�}ddl}|�|j
jd�dS)Nrr3zportion2 foo two)r&r,r-r.rrr4rrrrbrcr'r5r))rr*rrr	r62s
zReloadTests.test_dynamic_pathN)rrr rr+r/r6rrrr	ra"srac@s"eZdZdgZdd�Zdd�ZdS)�LoaderTestsr%cCs*ddl}|�|j|jj�|�|j�dS)Nr)r*r'rK�__spec__�loaderZassertIsNotNone)rr*rrr	�!test_namespace_loader_consistencyCsz-LoaderTests.test_namespace_loader_consistencycCs&ddl}|�|jj�|�|j�dS)Nr)r*ZassertIsNonere�originr#)rr*rrr	�!test_namespace_origin_consistencyIsz-LoaderTests.test_namespace_origin_consistencyN)rrr rrgrirrrr	rd@srd�__main__)�
contextlibrbrrr]Ztest.test_importlibr�contextmanagerr
rZTestCaserr$r2r7r:r;r@rArDrErGrNrZr^rardr�mainrrrr	�<module>s2



-