HEX
Server: LiteSpeed
System: Linux server.nevid-deploma.com 4.18.0-553.111.1.lve.el8.x86_64 #1 SMP Fri Mar 13 13:42:17 UTC 2026 x86_64
User: smilepac (1037)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //opt/cppython/lib/python3.8/test/test_importlib/__pycache__/test_namespace_pkgs.cpython-38.pyc
U

/D�gE*�@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
dVW5|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�F/opt/cppython/lib/python3.8/test/test_importlib/test_namespace_pkgs.py�sys_modules_contexts	


r
c
ksT|�dtj�|�dtj�tjf|�}|�t��dVW5QRXW5QRXdS)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__rrrr	�setUp<s

�zNamespacePackageTest.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�Nr�portion1 foo one��foo.one�assertEqual�one�attr�r�foorrr	�test_simple_packageKsz*SingleNamespacePackage.test_simple_packagec	Cs"|�t��ddl}W5QRXdS�Nr��assertRaises�ImportError�foo.twor.rrr	�test_cant_import_otherOsz-SingleNamespacePackage.test_cant_import_othercCsddl}|�t|�d�dS)Nrz<module 'foo' (namespace)>)r*r+�reprr.rrr	�test_module_reprSsz'SingleNamespacePackage.test_module_reprN)rr r!rr0r6r8rrrr	r%Hsr%c@seZdZdgZdd�ZdS)�DynamicPathNamespacePackager&c	Csjddl}|�|jjd�|�t��ddl}W5QRXtj�	t
j�|jd��ddl}|�|j
jd�dS)Nrr(�portion2�portion2 foo two)r*r+r,r-r3r4r5rr�appendrrr�twor.rrr	�test_dynamic_path[sz-DynamicPathNamespacePackage.test_dynamic_pathN)rr r!rr>rrrr	r9Xsr9c@seZdZdgZdd�ZdS)�CombinedNamespacePackages�
both_portionscCs4ddl}ddl}|�|jjd�|�|jjd�dS�Nrzboth_portions foo one�both_portions foo two�r*r5r+r,r-r=r.rrr	�test_importsnsz&CombinedNamespacePackages.test_importsN�rr r!rrDrrrr	r?ksr?c@seZdZddgZdd�ZdS)�SeparatedNamespacePackagesr&r:cCs4ddl}ddl}|�|jjd�|�|jjd�dS)Nrr(r;rCr.rrr	rDxsz'SeparatedNamespacePackages.test_importsNrErrrr	rFusrFc@s,eZdZddgZdd�Zdd�Zdd�Zd	S)
�%SeparatedOverlappingNamespacePackagesr&r@cCs4ddl}ddl}|�|jjd�|�|jjd�dS�Nrr(rBrCr.rrr	�test_first_path_wins�sz:SeparatedOverlappingNamespacePackages.test_first_path_winscCs>tj��ddl}ddl}|�|jjd�|�|jjd�dSrA)	rr�reverser*r5r+r,r-r=r.rrr	�test_first_path_wins_again�s

z@SeparatedOverlappingNamespacePackages.test_first_path_wins_againcCs4ddl}ddl}|�|jjd�|�|jjd�dSrH)r5r*r+r,r-r=r.rrr	�+test_first_path_wins_importing_second_first�szQSeparatedOverlappingNamespacePackages.test_first_path_wins_importing_second_firstN)rr r!rrIrKrLrrrr	rGsrGc@s"eZdZdgZdd�Zdd�ZdS)�SingleZipNamespacePackage�top_level_portion1.zipcCsddl}|�|jjd�dSr'r)r.rrr	r0�sz-SingleZipNamespacePackage.test_simple_packagec	Cs"|�t��ddl}W5QRXdSr1r2r.rrr	r6�sz0SingleZipNamespacePackage.test_cant_import_otherN�rr r!rr0r6rrrr	rM�srMc@seZdZddgZdd�ZdS)�SeparatedZipNamespacePackagesrNr:cCsTddl}ddl}|�|jjd�|�|jjd�|�d|jj�|�d|jj�dS)Nrr(r;rN�.zip)	r*r5r+r,r-r=�assertInr$�assertNotInr.rrr	rD�sz*SeparatedZipNamespacePackages.test_importsNrErrrr	rP�srPc@s"eZdZdgZdd�Zdd�ZdS)�SingleNestedZipNamespacePackage�#nested_portion1.zip/nested_portion1cCsddl}|�|jjd�dSr'r)r.rrr	r0�sz3SingleNestedZipNamespacePackage.test_simple_packagec	Cs"|�t��ddl}W5QRXdSr1r2r.rrr	r6�sz6SingleNestedZipNamespacePackage.test_cant_import_otherNrOrrrr	rT�srTc@seZdZddgZdd�ZdS)�#SeparatedNestedZipNamespacePackagesrUr:cCsbddl}ddl}|�|jjd�|�|jjd�tj�dd�}|�	||jj
�|�d|jj
�dS)Nrr(r;znested_portion1.zipZnested_portion1rQ)r*r5r+r,r-r=rrrrRr$rS)rr/�fnrrr	rD�sz0SeparatedNestedZipNamespacePackages.test_importsNrErrrr	rV�srVc@s eZdZddddgZdd�ZdS)�
LegacySupportZnot_a_namespace_pkgr&r:r@c	CsNddl}|�t��ddl}W5QRX|�d|j�|�dt|j��	��dS)Nr�__init__�	namespace)
r*r3r4r5rRr$rS�str�
__loader__�lowerr.rrr	�+test_non_namespace_package_takes_precedence�s
z9LegacySupport.test_non_namespace_package_takes_precedenceN)rr r!rr^rrrr	rX�srXc@s$eZdZddgZdd�Zdd�ZdS)�DynamicPathCalculationZproject1Zproject2c	Cs�ddl}|�t|j�d�|�t|jj�d�ddl}|�t|j�d�|�t|jj�d�|�|jjjd�|�|jjjd�|�	t
��ddl}W5QRX|�t|j�d�|�t|jj�d�dS)Nr��parent child one�parent child two)�parent.child.oner+�len�__path__�child�parent.child.twor,r-r=r3r4�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}W5QRXtj
�tj
�|jd��ddl}|�t|j�d�|�t|jj�d�|�|jjjd�dS)Nrr`rarbZproject3�zparent child three)rcr+rdrerfrgr,r-r=r3r4rhrrr<rrrZthreerirrr	�test_project3_succeeds�sz-DynamicPathCalculation.test_project3_succeedsN)rr r!rrkrmrrrr	r_�sr_c@s(eZdZdgZejdd��Zdd�ZdS)�ZipWithMissingDirectoryzmissing_directory.zipcCsddl}dSr1)r*r.rrr	�test_missing_directorysz.ZipWithMissingDirectory.test_missing_directorycCsddl}|�|jjd�dS)Nrzmissing_directory foo two)Zbar.twor+r=r-)rZbarrrr	�test_present_directorysz.ZipWithMissingDirectory.test_present_directoryN)rr r!r�unittestZexpectedFailurerorprrrr	rn�s
rnc@seZdZdgZdd�ZdS)�"ModuleAndNamespacePackageInSameDirZmodule_and_namespace_packagecCsddl}|�|jd�dS)Nrz	in module)�a_testr+r-)rrsrrr	�$test_module_before_namespace_packageszGModuleAndNamespacePackageInSameDir.test_module_before_namespace_packageN)rr r!rrtrrrr	rrsrrc@s*eZdZdgZdd�Zdd�Zdd�ZdS)	�ReloadTestsr&cCs&ddl}t�|�}|�|jjd�dSr')r*�	importlib�reloadr+r,r-r.rrr	r0%s
zReloadTests.test_simple_packagec	CsRddl}|�t��ddl}W5QRXt�|�}|�t��ddl}W5QRXdSr1)r/r3r4r5rvrwr.rrr	r6*s
z"ReloadTests.test_cant_import_otherc	Csdddl}|�t��ddl}W5QRXtj�tj�|j	d��t
�|�}ddl}|�|j
jd�dS)Nrr:r;)r*r3r4r5rrr<rrrrvrwr+r=r-r.rrr	r>2s
zReloadTests.test_dynamic_pathN)rr r!rr0r6r>rrrr	ru"sruc@s*eZdZdgZdd�Zdd�Zdd�ZdS)	�LoaderTestsr&cCs*ddl}|�|j|jj�|�|j�dSr1)r/r+r\�__spec__�loaderZassertIsNotNoner.rrr	�!test_namespace_loader_consistencyCsz-LoaderTests.test_namespace_loader_consistencycCs&ddl}|�|jj�|�|j�dSr1)r/ZassertIsNonery�originr$r.rrr	�!test_namespace_origin_consistencyIsz-LoaderTests.test_namespace_origin_consistencycCs0ddl}tj�|jdd�}|�|jd|�dS)Nrr&r/)r/rrrrr+re)rr/Z
expected_pathrrr	�test_path_indexableOszLoaderTests.test_path_indexableN)rr r!rr{r}r~rrrr	rx@srx�__main__)�
contextlibrvrrrqZtest.test_importlibr�contextmanagerr
rZTestCaserr%r9r?rFrGrMrPrTrVrXr_rnrrrurxr�mainrrrr	�<module>s6





-