Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.12/test/test_importlib/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.12/test/test_importlib/__pycache__/test_namespace_pkgs.cpython-312.pyc

�

)Μga0��X�ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
ejd��Zejd��Z
Gd�dej�ZGd�de�ZGd	�d
e�ZGd�de�ZGd
�de�ZGd�de�ZGd�de�ZGd�de�ZGd�de�ZGd�de�ZGd�de�ZGd�de�ZGd�de�ZGd�d e�ZGd!�d"e�ZGd#�d$e�ZGd%�d&e�Ze d'k(rejB�yy)(�N)�utilc#�K�tj}tjj�}	d��|t_tjj�tjj	|�y#|t_tjj�tjj	|�wxYw�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)�sys_modules_saved�sys_modules_copys  �D/usr/local/lib/python3.12/test/test_importlib/test_namespace_pkgs.py�sys_modules_contextr
s����������{�{�'�'�)��-�
�'��������������+�,��(��������������+�,�s�/C�A?�A	C�?A
C	�	Cc+�*K�|jdtj�|jdtj�t	j
di|��}|5t
�5d��ddd�ddd�y#1swY�xYw#1swYyxYw�w)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�)�
setdefaultrrrr�import_stater
)�kwargs�import_contexts  r�namespace_tree_contextr(sc�������k�3�=�=�1�
���l�C�N�N�3��&�&�0��0�N�	�,�.�
�/���.�.����s6�AB�B�%A;�*B�2	B�;B	�B�B�Bc��eZdZdZej
j
ej
je�d�Z	d�Z
y)�NamespacePackageTestzj
    Subclasses should define self.root and self.paths (under that root)
    to be added to sys.path.
    �namespace_pkgsc���|jD�cgc],}tjj|j|���.c}|_|j
t|j
���ycc}w)N)�path)�paths�osr�join�root�resolved_paths�enterContextr)�selfrs  r�setUpzNamespacePackageTest.setUp@sV��6:�j�j�
�6@�d�B�G�G�L�L����D�)�j�
���	
���0�d�6I�6I�J�K��
s�1A.N)�__name__�
__module__�__qualname__�__doc__rrr�dirname�__file__rr#r�rrr9s1����7�7�<�<�������1�3C�D�D�Lr*rc�$�eZdZdgZd�Zd�Zd�Zy)�SingleNamespacePackage�portion1c�X�ddl}|j|jjd�y�Nr�portion1 foo one��foo.one�assertEqual�one�attr�r"�foos  r�test_simple_packagez*SingleNamespacePackage.test_simple_packageJ������������'9�:r*c�`�|jt�5ddl}ddd�y#1swYyxYw�Nr��assertRaises�ImportError�foo.twor6s  r�test_cant_import_otherz-SingleNamespacePackage.test_cant_import_otherN���
�
�
�{�
+��,�
+�
+���$�-c�^�ddl}|jt|�jd��y)Nrz <module 'foo' (namespace) from [)r2�
assertTrue�repr�
startswithr6s  r�test_simple_reprz'SingleNamespacePackage.test_simple_reprRs!�������S�	�,�,�-O�P�Qr*N)r$r%r&rr8r@rGrr*rr,r,Gs��
�L�E�;��Rr*r,c��eZdZdgZd�Zy)�DynamicPathNamespacePackager-c��ddl}|j|jjd�|j	t
�5ddl}ddd�tjjtjj|jd��ddl}|j|jjd�y#1swY�{xYw)Nrr0�portion2�portion2 foo two)r2r3r4r5r=r>r?rr�appendrrr�twor6s  r�test_dynamic_pathz-DynamicPathNamespacePackage.test_dynamic_pathZs������������'9�:�
�
�
�{�
+��,�	����������T�Y�Y�
�;�<�	���������'9�:�,�
+�s�B?�?CN)r$r%r&rrOrr*rrIrIWs��
�L�E�
;r*rIc��eZdZdgZd�Zy)�CombinedNamespacePackages�
both_portionsc��ddl}ddl}|j|jjd�|j|j
jd�y�Nrzboth_portions foo one�both_portions foo two�r2r?r3r4r5rNr6s  r�test_importsz&CombinedNamespacePackages.test_importsms:������������'>�?���������'>�?r*N�r$r%r&rrWrr*rrQrQjs��
��E�@r*rQc��eZdZddgZd�Zy)�SeparatedNamespacePackagesr-rKc��ddl}ddl}|j|jjd�|j|j
jd�y)Nrr0rLrVr6s  rrWz'SeparatedNamespacePackages.test_importsws:������������'9�:���������'9�:r*NrXrr*rrZrZts��
��$�E�;r*rZc��eZdZdgZd�Zy)�-SeparatedNamespacePackagesCreatedWhileRunningr-c�.�tj�5}tjj	|�ddl}|j
|jjd�|jt�5ddl}ddd�tjj|d�}tj|�tjj|d�}t|dd��5}|j!d�ddd�|jt�5ddl}ddd�t#j$�ddl}|j
|j&jd	�ddd�y#1swY��xYw#1swY�~xYw#1swY�hxYw#1swYyxYw)
Nrr0r7zjust_created.py�wzutf-8)�encodingzattr = "just_created foo"zjust_created foo)�tempfile�TemporaryDirectoryrrrMr2r3r4r5r=r>�foo.just_createdrr�mkdir�open�write�	importlib�invalidate_caches�just_created)r"�temp_dirr7�namespace_path�module_path�files      r�test_invalidate_cacheszDSeparatedNamespacePackagesCreatedWhileRunning.test_invalidate_caches�s��
�
(�
(�
*�h�
�H�H�O�O�H�%�����S�W�W�\�\�+=�>��"�"�;�/�'�0�
 �W�W�\�\�(�E�:�N��H�H�^�$��'�'�,�,�~�7H�I�K��k�3��9�T��
�
�6�7�:��"�"�;�/�'�0�
�'�'�)�#����S�-�-�2�2�4F�G�7+�
*�0�/��:�9��0�/��++�
*�sV�AF�4E'�9A+F�$E3�6F�E?�AF�'E0	�,F�3E<	�8F�?F	�F�FN)r$r%r&rrnrr*rr]r]~s��
�L�E�Hr*r]c�&�eZdZddgZd�Zd�Zd�Zy)�%SeparatedOverlappingNamespacePackagesr-rRc��ddl}ddl}|j|jjd�|j|j
jd�y�Nrr0rUrVr6s  r�test_first_path_winsz:SeparatedOverlappingNamespacePackages.test_first_path_wins��:������������'9�:���������'>�?r*c���tjj�ddl}ddl}|j|jjd�|j|jjd�yrT)	rr�reverser2r?r3r4r5rNr6s  r�test_first_path_wins_againz@SeparatedOverlappingNamespacePackages.test_first_path_wins_again�sJ������������������'>�?���������'>�?r*c��ddl}ddl}|j|jjd�|j|j
jd�yrr)r?r2r3r4r5rNr6s  r�+test_first_path_wins_importing_second_firstzQSeparatedOverlappingNamespacePackages.test_first_path_wins_importing_second_first�rtr*N)r$r%r&rrsrwryrr*rrprp�s��
��)�E�@�@�@r*rpc��eZdZdgZd�Zd�Zy)�SingleZipNamespacePackage�top_level_portion1.zipc�X�ddl}|j|jjd�yr/r1r6s  rr8z-SingleZipNamespacePackage.test_simple_package�r9r*c�`�|jt�5ddl}ddd�y#1swYyxYwr;r<r6s  rr@z0SingleZipNamespacePackage.test_cant_import_other�rArBN�r$r%r&rr8r@rr*rr{r{�s��
%�&�E�;�r*r{c��eZdZddgZd�Zy)�SeparatedZipNamespacePackagesr|rKc�D�ddl}ddl}|j|jjd�|j|j
jd�|j
d|jj�|jd|j
j�y)Nrr0rLr|�.zip)	r2r?r3r4r5rN�assertInr)�assertNotInr6s  rrWz*SeparatedZipNamespacePackages.test_imports�sm������������'9�:���������'9�:��
�
�.����0@�0@�A��������!1�!1�2r*NrXrr*rr�r��s��
%�z�2�E�3r*r�c��eZdZdgZd�Zd�Zy)�SingleNestedZipNamespacePackage�#nested_portion1.zip/nested_portion1c�X�ddl}|j|jjd�yr/r1r6s  rr8z3SingleNestedZipNamespacePackage.test_simple_package�r9r*c�`�|jt�5ddl}ddd�y#1swYyxYwr;r<r6s  rr@z6SingleNestedZipNamespacePackage.test_cant_import_other�rArBNrrr*rr�r��s��
2�3�E�;�r*r�c��eZdZddgZd�Zy)�#SeparatedNestedZipNamespacePackagesr�rKc��ddl}ddl}|j|jjd�|j|j
jd�tjjdd�}|j||jj�|jd|j
j�y)Nrr0rLznested_portion1.zip�nested_portion1r�)r2r?r3r4r5rNrrrr�r)r�)r"r7�fns   rrWz0SeparatedNestedZipNamespacePackages.test_imports�s�������������'9�:���������'9�:�
�W�W�\�\�/�1B�
C���
�
�b�#�'�'�*�*�+��������!1�!1�2r*NrXrr*rr�r��s��
2�J�?�E�3r*r�c��eZdZgd�Zd�Zy)�
LegacySupport)�not_a_namespace_pkgr-rKrRc��ddl}|jt�5ddl}ddd�|j	d|j
�|j
dt|j�j��y#1swY�YxYw)Nr�__init__�	namespace)
r2r=r>r?r�r)r��str�
__loader__�lowerr6s  r�+test_non_namespace_package_takes_precedencez9LegacySupport.test_non_namespace_package_takes_precedence�sX���
�
�
�{�
+��,��
�
�j�#�,�,�/�����c�#�.�.�&9�&?�&?�&A�B�,�
+�s�A7�7BN)r$r%r&rr�rr*rr�r��s
��L�E�Cr*r�c� �eZdZddgZd�Zd�Zy)�DynamicPathCalculation�project1�project2c�(�ddl}|jt|j�d�|jt|jj�d�ddl}|jt|j�d�|jt|jj�d�|j|jjjd�|j|jjjd�|jt�5ddl}ddd�|jt|j�d�|jt|jj�d�y#1swY�^xYw)Nr��parent child one�parent child two)�parent.child.oner3�len�__path__�child�parent.child.twor4r5rNr=r>�parent.child.three�r"�parents  r�test_project3_failsz*DynamicPathCalculation.test_project3_fails�s�������V�_�_�-�q�1�����V�\�\�2�2�3�Q�7������V�_�_�-�q�1�����V�\�\�2�2�3�Q�7�������)�)�.�.�0B�C�������)�)�.�.�0B�C�
�
�
�{�
+�%�,�	
����V�_�_�-�q�1�����V�\�\�2�2�3�Q�7�	,�
+�s�&F�Fc��ddl}|jt|j�d�|jt|jj�d�ddl}|jt|j�d�|jt|jj�d�|j|jjjd�|j|jjjd�|jt�5ddl}ddd�tjjtjj!|j"d��ddl}|jt|j�d�|jt|jj�d�|j|jj$jd�y#1swY��xYw)Nrr�r�r��project3�zparent child three)r�r3r�r�r�r�r4r5rNr=r>r�rrrMrrr�threer�s  r�test_project3_succeedsz-DynamicPathCalculation.test_project3_succeedss\�������V�_�_�-�q�1�����V�\�\�2�2�3�Q�7������V�_�_�-�q�1�����V�\�\�2�2�3�Q�7�������)�)�.�.�0B�C�������)�)�.�.�0B�C�
�
�
�{�
+�%�,�	����������T�Y�Y�
�;�<�!�	
����V�_�_�-�q�1�����V�\�\�2�2�3�Q�7�������+�+�0�0�2F�G�,�
+�s�&H�HN)r$r%r&rr�r�rr*rr�r��s��
��$�E�8�"Hr*r�c�<�eZdZdgZej
d��Zd�Zy)�ZipWithMissingDirectoryzmissing_directory.zipc��ddl}yr;)r2r6s  r�test_missing_directoryz.ZipWithMissingDirectory.test_missing_directory#s��	r*c�X�ddl}|j|jjd�y)Nrzmissing_directory foo two)�bar.twor3rNr5)r"�bars  r�test_present_directoryz.ZipWithMissingDirectory.test_present_directory3s�����������'B�Cr*N)r$r%r&r�unittest�expectedFailurer�r�rr*rr�r� s(��
$�%�E�
���
��
�Dr*r�c��eZdZdgZd�Zy)�"ModuleAndNamespacePackageInSameDir�module_and_namespace_packagec�D�ddl}|j|jd�y)Nrz	in module)�a_testr3r5)r"r�s  r�$test_module_before_namespace_packagezGModuleAndNamespacePackageInSameDir.test_module_before_namespace_package<s��	�������k�2r*N)r$r%r&rr�rr*rr�r�9s��
+�,�E�3r*r�c�$�eZdZdgZd�Zd�Zd�Zy)�ReloadTestsr-c��ddl}tj|�}|j|jj
d�yr/)r2rg�reloadr3r4r5r6s  rr8zReloadTests.test_simple_packageFs.������s�#����������'9�:r*c���ddl}|jt�5ddl}ddd�t	j
|�}|jt�5ddl}ddd�y#1swY�AxYw#1swYyxYwr;)r7r=r>r?rgr�r6s  rr@z"ReloadTests.test_cant_import_otherKsV���
�
�
�{�
+��,����s�#��
�
�
�{�
+��,�
+�,�
+��,�
+�s�A�A+�A(�+A4c�t�ddl}|jt�5ddl}ddd�tj
j
tj
j|jd��tj|�}ddl}|j|jjd�y#1swY��xYw)NrrKrL)r2r=r>r?rrrMrrrrgr�r3rNr5r6s  rrOzReloadTests.test_dynamic_pathSsw���
�
�
�{�
+��,�	����������T�Y�Y�
�;�<����s�#��	���������'9�:�,�
+�s�B.�.B7N)r$r%r&rr8r@rOrr*rr�r�Cs��
�L�E�;�
�;r*r�c�*�eZdZdgZd�Zd�Zd�Zd�Zy)�LoaderTestsr-c��ddl}|j|j|jj�|j|j�yr;)r7r3r��__spec__�loader�assertIsNotNoner6s  r�!test_namespace_loader_consistencyz-LoaderTests.test_namespace_loader_consistencyds5������������)<�)<�=����S�^�^�,r*c��ddl}|j|jj�|j|j�yr;)r7�assertIsNoner��originr)r6s  r�!test_namespace_origin_consistencyz-LoaderTests.test_namespace_origin_consistencyjs/������#�,�,�-�-�.����#�,�,�'r*c��ddl}tjj|jdd�}|j|jd|�y)Nrr-r7)r7rrrrr3r�)r"r7�
expected_paths   r�test_path_indexablezLoaderTests.test_path_indexableps7��������T�Y�Y�
�E�B�
�������a��-�8r*c��ddl}|jt|jtj
j��|jt|jtjj��yr;)	r7rD�
isinstancer�rg�abc�Loader�	machinery�NamespaceLoaderr6s  r�test_loader_abczLoaderTests.test_loader_abcvsI������
�3�>�>�9�=�=�3G�3G�H�I����
�3�>�>�9�3F�3F�3V�3V�W�Xr*N)r$r%r&rr�r�r�r�rr*rr�r�as��
�L�E�-�(�9�Yr*r��__main__)"�
contextlibrg�
importlib.abc�importlib.machineryrrrar��warnings�test.test_importlibr�contextmanagerr
r�TestCaserr,rIrQrZr]rpr{r�r�r�r�r�r�r�r�r�r$�mainrr*r�<module>r�sg������	�
����$����-��-�$������ L�8�,�,�L�
R�1�
R� ;�"6�;�&@� 4�@�;�!5�;�H�4H�H�D@�,@�@�.	� 4�	�	3�$8�	3�	�&:�	�
3�*>�
3�C�(�C�*H�1�*H�ZD�2�D�23�)=�3�;�&�;�<Y�&�Y�6�z���H�M�M�O�r*

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists