Your IP : 216.73.216.52


Current Path : /opt/alt/python312/lib64/python3.12/test/test_import/__pycache__/
Upload File :
Current File : //opt/alt/python312/lib64/python3.12/test/test_import/__pycache__/__init__.cpython-312.pyc

�

�#�j����`�ddlZddlZddlZddlZddlZddlmZddlm	Z	m
Z
mZmZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZddlZddlZddlmZddlmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&ddl'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.ddl/m0Z0m1Z1m2Z2m3Z3dd	lm4Z4dd
lm5Z5ddl6m7Z7ddlm8Z8	ddl9Z9	ddl;Z;	ddl<Z=ej~ej�d
�ZAd�ZBdd�d�ZCdd�d�ZDdd�d�ZEdd�d�ZFd�ZGd�ZHe9�e9d�d�ZId�ZJd�ZKGd�dej��ZMGd�dej��ZOeAGd �d!ej���ZPGd"�d#ej��ZQGd$�d%ej��ZRGd&�d'ej��ZSGd(�d)ej��ZTGd*�d+ej��ZUGd,�d-ej��ZVe"Gd.�d/ej���ZWe"Gd0�d1ej���ZXGd2�d3ej��ZYGd4�d5ej��ZZGd6�d7ej��Z[Gd8�d9eM�Z\eJGd:�d;ej���Z]e^d<k(rej��yy#e:$rdZ9Y���wxYw#e:$rdZ;Y���wxYw#e>$rdZ=Y���wxYw)=�N)�_get_sourcefile)�BuiltinImporter�ExtensionFileLoader�FrozenImporter�SourceFileLoader)�mock)�	os_helper)�
STDLIB_DIR�	swap_attr�	swap_item�cpython_only�
is_emscripten�is_wasi�run_in_subinterp�run_in_subinterp_with_config)�forget�make_legacy_pyc�unlink�unload�ready_to_import�
DirsOnSysPath�CleanImport)�TESTFN�rmtree�
temp_umask�TESTFN_UNENCODABLE)�
script_helper)�threading_helper)�uncache)�
ModuleTypez*test meaningful only when writing bytecodec��t|t�rt|�}tdtdt
dtdi}|}t|t�sJ|��||}|jj}t|t�st|�}||}||k7r4d|�d|j��}|rtj|��t|��|S)N�built-in�	extension�frozenzpure Pythonzexpected module to be z, got )
�
isinstance�str�
__import__rrrr�type�__spec__�loader�unittest�SkipTest�	Exception)�moduler*�skip�MODULE_KINDS�expected�actual�errs       �@/opt/alt/python312/lib64/python3.12/test/test_import/__init__.py�_require_loaderr5;s����&�#���F�#��	���[����-�	�L��H��h��%�/�x�/�%��H�%�H�
�_�_�
#�
#�F��f�d�#��f���
�&�
!�F�
���&�x�j��v���6G�H����#�#�C�(�(���n���M�F�r/c�z�t|t|�}|jjdk(sJ|j��y)Nr")r5rr)�origin�r.r/s  r4�require_builtinr;Vs1��
�V�_�d�
;�F��?�?�!�!�Z�/�@����@�/r6c�&�t|t|�y�N)r5rr:s  r4�require_extensionr>Zs���F�/��6r6Tc�z�t|t|�}|jjdk(sJ|j��y)Nr$)r5rr)r9r:s  r4�require_frozenr@]s1��
�V�^�T�
:�F��?�?�!�!�X�-�>�v���>�-r6c�&�t|t|�yr=)r5rr:s  r4�require_pure_pythonrBas���F�,�d�3r6c�^�|dz|dz|dz|dzfD]
}t|��td�y)N�.py�.pyc�.pywz	$py.class�__pycache__)rr)�name�fs  r4�remove_filesrJds>���U�l��V�m��V�m��[� �"��	�q�	�	"�
�=�r6c����fd�}|S)z�Skip rerunning for a particular test.

    WARNING: Use this decorator with care; skipping rerunning makes it
    impossible to find reference leaks. Provide a clear reason for skipping the
    test using the 'reason' parameter.
    c�����d����fd�}|S)NFc�@���r|j���|�d�y)NT)�skipTest)�self�_has_run�func�reasons ���r4�wrapperz'no_rerun.<locals>.deco.<locals>.wrappervs�����
�
�f�%���J��Hr6�)rQrSrPrRs` @�r4�decozno_rerun.<locals>.decots�����	��r6rT)rRrUs` r4�no_rerunrVms�����Kr6)�_origc��tjjdd�|j�t	j
d|j�ddl}y)N�_testsinglephaser)�sys�modules�pop�_clear_globals�_testinternalcapi�clear_extension�__file__rY)rWrYs  r4�restore__testsinglephasera�s;��	�����*�D�1�
�����)�)�*<�e�n�n�M�r6c��t|t�s|fd�}t|�}tjt
dud�|�S)zADecorator to skip if single-phase init modules are not supported.c�F�	||�t�S#t�wxYwr=�ra)rO�_meths  r4�methz'requires_singlephase_init.<locals>.meth�s��
+��T�{�(�*��(�*�s�� Nz%test requires _testsinglephase module)r%r(r
r+�skipIfrY�rfs r4�requires_singlephase_initri�sL���d�D�!�!�	+�
���D�D�8�?�?�+�t�3�B�D�DH�J�Jr6c�F�tjtdud�|�S)z>Decorator to skip a test if subinterpreters are not supported.Nzsubinterpreters required)r+rg�
_interpretersrhs r4�requires_subinterpretersrl�s)��7�8�?�?�=�D�0�5�7�7;�=�=r6c��eZdZdZedj��Zed��Ze	jd�Ze	jd�j�Z
e	jd�j�Ze	jd�j�Zedd	dd	d
�d��Zed��Zeddd
�d��Zed��Zy)�ModuleSnapshota?A representation of a module for testing.

    Fields:

    * id - the module's object ID
    * module - the actual module or an adequate substitute
       * __file__
       * __spec__
          * name
          * origin
    * ns - a copy (dict) of the module's __dict__ (or None)
    * ns_id - the object ID of the module's __dict__
    * cached - the sys.modules[mod.__spec__.name] entry (or None)
    * cached_id - the object ID of the sys.modules entry (or None)

    In cases where the value is not available (e.g. due to serialization),
    the value will be None.
    z#id module ns ns_id cached cached_idc
��|jj}tjj	|�}|t|�|t
jdi|j��t|j�|t|���S)N)�idr.�ns�ns_id�cached�	cached_idrT)	r)rHrZr[�getrp�types�SimpleNamespace�__dict__)�cls�modrHrss    r4�from_modulezModuleSnapshot.from_module�se���|�|� � ��������&����#�w���$�$�4�s�|�|�4��S�\�\�"����j�

�	
r6z�
        {imports}

        name = {name!r}

        {prescript}

        mod = {name}

        {body}

        {postscript}
        z
        import sys
        a�
        # Capture the snapshot data.
        cached = sys.modules.get(name)
        snapshot = dict(
            id=id(mod),
            module=dict(
                __file__=mod.__file__,
                __spec__=dict(
                    name=mod.__spec__.name,
                    origin=mod.__spec__.origin,
                ),
            ),
            ns=None,
            ns_id=id(mod.__dict__),
            cached=None,
            cached_id=id(cached) if cached else None,
        )
        zL
        # Clean up the module.
        sys.modules.pop(name, None)
        NF)�	prescript�import_first�
postscript�postcleanupc��|dur
|j}nVt|t�rDtj|�j�}|jtjz|z}nd}|r#tj|�j�nd}|r#tj|�j�nd}|r|r|tjdzz|z}n|}|r|tjd|���z
}|jj|jj�||j�|jj�|��S)NT��zq

                # Now import the module.
                assert name not in sys.modules
                import )�importsrHr|�bodyr~)�CLEANUP_SCRIPTr%r&�textwrap�dedent�strip�os�linesep�SCRIPT�format�IMPORTS�SCRIPT_BODY)ryrHr|r}r~rs      r4�build_scriptzModuleSnapshot.build_script�s%���$���,�,�K�
��S�
)�"�/�/�+�6�<�<�>�K��,�,�r�z�z�9�K�G�K��K�:C�H�O�O�I�.�4�4�6��	�<F�X�_�_�Z�0�6�6�8�B�
���'�"�*�*�q�.�8�;�F�
�(�
������.��v�	*!�"�
"�I��z�z� � ��K�K�%�%�'���o�o�'����&�&�(�!�!�
�	
r6c��tj|�}|d}tjdi|d��|d<tjdi|��|d<|di|��S)Nr.r)rT)�json�loadsrvrw)ry�text�rawrzs    r4�parsezModuleSnapshot.parsesW���j�j�����(�m���/�/�B�#�j�/�B��J���-�-�4��4��H�
��z�S�z�r6)�pipec�F�|�|j||||�Stj�}	|j||||�|\}}tj|�tj|�S#|\}}tj|�tj|�wxYwr=)�_from_subinterpr�r��close)ryrH�interpidr��script_kwds�r�ws       r4�from_subinterpzModuleSnapshot.from_subinterps������&�&�t�X�t�[�I�I��w�w�y��	��&�&�t�X�t�[�I��D�A�q��H�H�Q�K��H�H�Q�K���D�A�q��H�H�Q�K��H�H�Q�K�s�A/�/1B c���|\}}tjd|�d��}|jd�}|r(tj|�j�}||z
}|j	�|d<|j
|fi|��}	|�t
|	�}
|
dk7r$t|
�d���tj||	�tj|d�}|j|j��S)Nzq
            # Send the result over the pipe.
            import json
            import os
            os.write(z., json.dumps(snapshot).encode())

            r~rz != 0��)r�r�ru�lstripr�r�r�AssertionErrorrk�
run_stringr��readr��decode)ryrHr�r��
script_kwargsr�r�r~�_postscript�script�retr�s            r4r�zModuleSnapshot._from_subinterp s������1��_�_�*��S�
�	&��
�$�'�'��5���"�/�/�+�6�=�=�?�K��+�%�J�&0�&6�&6�&8�
�l�#�!��!�!�$�8�-�8����"�6�*�C��a�x�$��u�E�]�3�3��$�$�X�v�6��w�w�q�$����y�y�����'�'r6r=)�__name__�
__module__�__qualname__�__doc__�tuple�split�_fields�classmethodr{r�r�r�r�r�r�r�r�r�r�r�rTr6r4rnrn�s���$�9�?�?�A�B�G��

��

��X�_�_��
�F��h�o�o��
�
�U�W��"�(�/�/�#�
�"�U�W�#�$%�X�_�_�&�
��U�W��
�#�"'� $�!&�	#
��#
�J�����	��	��	��(��(r6rnc�n�eZdZd�Zd�Zd�Zd�Zd�Zd�Ze	d��Z
d�Zd	�Zd
�Z
d�Zd�Zd
�Zd$d�Zd�Zd�Zd�Zd�Zed��Zd�Zd�Zed��Zd�Ze	d��Zd�Zd�Zd�Ze	d��Z e!jD�d��Z#e$jJe&jNdk(d�d ��Z(d!�Z)d"�Z*y#)%�ImportTestsc�J�tt�tj�yr=)rJr�	importlib�invalidate_caches�rOs r4�setUpzImportTests.setUpBs���V���#�#�%r6c�"�tt�yr=)rrr�s r4�tearDownzImportTests.tearDownFs	���v�r6c�`�|jt�5ddl}ddd�y#1swYyxYw�Nr)�assertRaises�ModuleNotFoundError�(something_that_should_not_exist_anywhere�rOr�s  r4�&test_import_raises_ModuleNotFoundErrorz2ImportTests.test_import_raises_ModuleNotFoundErrorIs ��
�
�
�2�
3�;�4�
3�
3���$�-c�d�|jt�5ddlm}ddd�y#1swYyxYw)Nr)�blah)r�r�r�r�)rOr�s  r4�:test_from_import_missing_module_raises_ModuleNotFoundErrorzFImportTests.test_from_import_missing_module_raises_ModuleNotFoundErrorMs ��
�
�
�2�
3�E�4�
3�
3���&�/c�d�|jt�5ddlm}ddd�y#1swYyxYw)Nr)r�)r��ImportErrorr�r�r�s  r4�0test_from_import_missing_attr_raises_ImportErrorz<ImportTests.test_from_import_missing_attr_raises_ImportErrorQs��
�
�
�{�
+�J�,�
+�
+�r�c��td�5ddl}|jt�5}ddlm}ddd�ddd�|jjjd�|j|jjj�|jt|j�d�y#1swY��xYw#1swY��xYw)Nr�r��i_dont_existz7cannot import name 'i_dont_exist' from 'os' \(.*os.py\))rr�r�r�r��assertEqual�	exceptionrH�pathr`�assertRegexr&)rOr��cmr�s    r4�/test_from_import_missing_attr_has_name_and_pathz;ImportTests.test_from_import_missing_attr_has_name_and_pathUs���
��
���"�"�;�/�2�+�0��	
������*�*�D�1�������*�*�B�K�K�8�����R�\�\�*�,f�g�	0�/���
�s!�C�B9�C�9C	�>C�Cc���ddl}|jt�5}ddlm}ddd�|j	j
jd�t|d�rV|j	|j
j|j�|jt|j
�d�y|j	t|j
�d�y#1swY��xYw)Nrr��	_testcapir`zCcannot import name 'i_dont_exist' from '_testcapi' \(.*\.(so|pyd)\)zEcannot import name 'i_dont_exist' from '_testcapi' (unknown location))r�r�r�r�r�r�rH�hasattrr�r`r�r&)rOr�r�r�s    r4�2test_from_import_missing_attr_has_name_and_so_pathz>ImportTests.test_from_import_missing_attr_has_name_and_so_path^s����
�
�
�{�
+�r�.�,�������*�*�K�8��9�j�)����R�\�\�.�.�	�0B�0B�C�����B�L�L�!�V�
�

����B�L�L�!�W�
�,�
+�s�C�C c��|jt�5}ddlm}ddd�|j	j
jd�|j|j
j�y#1swY�UxYw)Nrr��_warning)	r�r�r�r�r�r�rH�assertIsNoner��rOr�r�s   r4�&test_from_import_missing_attr_has_namez2ImportTests.test_from_import_missing_attr_has_namepsW��
�
�
�{�
+�r�-�,�	
������*�*�J�7����"�,�,�+�+�,�	,�
+�s�A1�1A:c���|jt�5}ddlm}ddd�|j	j
jddh�|j|j
�y#1swY�MxYw)Nrr��	posixpath�ntpath)r�r��os.pathr��assertInr�rH�assertIsNotNoner�s   r4�/test_from_import_missing_attr_path_is_canonicalz;ImportTests.test_from_import_missing_attr_path_is_canonicalwsR��
�
�
�{�
+�r�,�,��
�
�b�l�l�'�'�+�x�)@�A����R�\�\�*�,�
+�s�A)�)A2c���ddl}t�5\}}t|dd��5}|jd�ddd�i}|j	t
|j
|��d��5td|�d�|�ddd�|jd	|�ddd�t�5\}}t|dd��5}|jd
�ddd�i}|j	t
|j
|��d��5td|�d�|�ddd�|jd	|�ddd�y#1swY��xYw#1swY��xYw#1swY��xYw#1swY��xYw#1swY�TxYw#1swYyxYw)Nrr��utf-8��encodingz__all__ = [b'invalid_type']z\.__all__ must be strzfrom z	 import *sinvalid_typez%globals()[b'invalid_type'] = object()z\.__dict__ must be str)	�rer�open�write�assertRaisesRegex�	TypeError�escape�exec�assertNotIn)rOr�rHr�rI�globalss      r4�"test_from_import_star_invalid_typez.ImportTests.test_from_import_star_invalid_type}sP���
�
�,�4���d�C�'�2�a����5�6�3��G��'�'��b�i�i��o�.�.D�E���u�T�F�)�,�g�6��
���_�g�6���
�,�4���d�C�'�2�a����?�@�3��G��'�'��b�i�i��o�.�.E�F���u�T�F�)�,�g�6��
���_�g�6��
�3�2�����	�
��3�2�����	�
�su�E�D,�2E�%D8�6E�"E(�4E�2E(�8E�	E(�,D5	�1E�8E	�=E�E
�E	�E(�E%	�!E(�(E1c�`�|jt�5ddl}ddd�y#1swYyxYwr�)r�r��RAnDoM)rOr�s  r4�test_case_sensitivityz!ImportTests.test_case_sensitivity�s!���
�
�{�
+��,�
+�
+�r�c�2�ddlm}td�ddlm}y)Nr)�double_constz"test.test_import.data.double_const)�test.test_import.datar�r)rOr�s  r4�test_double_constzImportTests.test_double_const�s��	7��3�4�6r6c�(���fd�}tjjdtj�	|d�tj
j
d�rdD]
}||��tjd=y#tjd=wxYw)Nc�2��t|z}tdz}t|dd��5}td|d|��tjd�}tjd�}td	||��td
||��ddd�tt
jvrt
jt=tj�		tt�}�jjd
|z��j|jd
|z�tt�t!|�t!|�y#1swY��xYw#t$r!}�jd|�d|���Yd}~��d}~wwxYw#tt�t!|�t!|�wxYw)NrEr�r�r�z)# This tests Python's ability to import azfile.��filer�za =zb =zimport from z	 failed: z'module loaded (%s) but contents invalid)rr��print�random�	randrangerZr[r�r�r'r��failr��a�brr)	�ext�source�pycrIrrrzr3rOs	        �r4�test_with_extensionz4ImportTests.test_import.<locals>.test_with_extension�sL����c�\�F��6�/�C��f�c�G�4���A��7��,��$�$�T�*���$�$�T�*���e�Q�Q�'��e�Q�Q�'�
5�����$��K�K��'��'�'�)�

�H�$�V�,�C�� � �����=��C�E�� � �����=��C�E��v���v���s��15�4��#�H��I�I�S�#�F�G�G��H���v���v���s��s=�AD6�E�AE/�6D?�	E,�E'�"E/�'E,�,E/�/'FrrD�win)z.PYz.Pyz.pYrFz.PYWz.pYw)rZr��insertr��curdir�platform�
startswith)rOrrs`  r4�test_importzImportTests.test_import�sk���	�>	������2�9�9�%�	���&��|�|�&�&�u�-�H�C�'��,�I������������s�6A>�>Bc�`�|dz}t|dd��5}|jd�td�D]}|jd��|jd�ddd�	tj|�t|�tjjd	�tj�i}	t|�td
|zd|�tjd=t|dz�t|d
z�|j�	tj|=y#1swY��xYw#t|�wxYw#t$rYywxYw#tjd=t|dz�t|d
z�|j�	tj|=w#t$rYwwxYwxYw)NrDr�r�r�zd = [
i�z"",
�]r�zimport ����c�o)r�r��range�
py_compile�compilerrZr��appendr�r�rr��clearr[�KeyError)rOr.�filenamerI�i�	namespaces      r4�test_module_with_large_stackz(ImportTests.test_module_with_large_stack�sl���E�>���(�C�'�
2�a�
�G�G�I���5�\������ �"�
�G�G�C�L�	3�	�
���x�(��8��	��������#�#�%��	�	��H�%���V�#�T�9�5�������8�c�>�"��8�c�>�"�
�O�O��
��K�K��'�?3�
2��
�8���*�
��
��������8�c�>�"��8�c�>�"�
�O�O��
��K�K��'���
��
�sZ�AD"�!D.�7E
�D>�"D+�.
D;�>	E
�	E
�
>F-�F�F-�	F*�'F-�)F*�*F-c�z�tdz}t|dd��5}td|��ddd�tjjdtj�tj�ttjvrtjt=	dD]I}|jttt�|jttjd	|z��K	tjd=tt�y#1swY��xYw#tjd=tt�wxYw)
NrDr�r�r�za = 1/0r�r)�r��z'damaged module in sys.modules on %i try)rr�r�rZr�rr�rr�r�r[r��ZeroDivisionErrorr'r�rJ)rOrrIrs    r4�test_failing_import_sticksz&ImportTests.test_failing_import_sticks�s����%���
�&�#��
0�A��)�!�$�1�
	������2�9�9�%��#�#�%��S�[�[� ����F�#�	!����!�!�"3�Z��H�� � �����!J�Q�!N�P��
������� �!1�
0��������� �s�D�AD�D�"D:c���ddl}ddl}|j|||j�|j	t|jd��ddlm}|j||j|j�y)Nrr`)�test�test.support�assertIsr��
assertTruer��support)rO�xr!�ys    r4�test_import_name_bindingz$ImportTests.test_import_name_bindingsP�����
�
�a��q�z�z�*��������j�9�:�	!��
�
�a����q�z�z�2r6c��	d}ddlmcm}d}|dkrddlmcm}|dz
}|dkr�td�D]}ddlmcm}�
y#ddlmcm}wxYw)N.r�
rr�)�test.support.script_helperr%rr)rOr&rs   r4�test_issue31286zImportTests.test_issue31286sX��	3��A�2�2�
���"�f�2�2�
��F�A��"�f�
�q��A�2�2���
3�2�s�A�A
c�N�ttjzdz}t|dd��5}|j	d�ddd�t
jjdtj�	tt�}|jtt
j�|j|jdd�|j|jd	d�tt�t|dd��5}|j	d
�ddd�|j!t"t$j&|�t
jj)t�}|j+|d�|j|jdd�|j|jd	d�t
jd=tt�t-t�y#1swY���xYw#1swY��xYw#t
jd=tt�t-t�wxYw)
N�pyr�r�r�z
a = 1
b=2
rrz!module has wrong attribute valuesr�za = 10
b=20//0
z$expected module to be in sys.modulesr*)rr��extsepr�r�rZr�rrr'r�r[r�rrrJr�rr��reloadrur�r)rOrrIrzs    r4�test_failing_reloadzImportTests.test_failing_reload!s����"�)�)�#�d�*��
�&�#��
0�A�
�G�G�N�#�1�	������2�9�9�%�	��V�$�C��M�M�&�#�+�+�.����S�U�U�A�'J�K����S�U�U�A�'J�K�
�� ��f�c�G�4�����+�,�5�
���/��1A�1A�3�G��+�+�/�/�&�)�C�� � ��&L�M�
���S�U�U�B�(K�L����S�U�U�A�'J�K�������� ��6�N�C1�
0��"5�4��������� ��6�N�s1�G�2B
G3�<G'�BG3�G$�'G0�,G3�31H$c��tdz}t|dd��5}|jd�ddd�tjjdtj�	tt�}|j|jjd��t
j|�tjt=t|�tj �tt�}tjj#|j�\}}|j%|d�tjd=t't�ttjvrtjt=yy#1swY��UxYw#tjd=t't�ttjvrtjt=wwxYw)NrDr�r�r�ztest = None
rrE)rr�r�rZr�rr�rr'r$r`�endswith�remover[rr�r��splitextr�rJ)rOrrIrz�basers      r4�test_file_to_sourcezImportTests.test_file_to_sourceGs<���%���
�&�#��
0�A�
�G�G�O�$�1�	������2�9�9�%�	(��V�$�C��O�O�C�L�L�1�1�%�8�9��I�I�f�����F�#��F�#��'�'�)��V�$�C����(�(����6�I�D�#����S�&�)�������� �����$��K�K��'�%�#1�
0��������� �����$��K�K��'�%�s�E=�!CF
�=F�
AGc�^�tjjt�}t	j
�}	|j
|�|jt�5}t|�ddd�y#t$r#|jdj|��Y�UwxYw#1swYyxYw)Nzpath is not encodable to {})
r�r��abspathrrZ�getfilesystemencoding�encode�UnicodeEncodeErrorrNr�r�r�r')rOr�r�rs    r4�test_import_by_filenamez#ImportTests.test_import_by_filename_s����w�w���v�&���,�,�.��	J��K�K��!��
�
�{�
+�q��t��,�
+��"�	J��M�M�7�>�>�x�H�I�	J��
+�
+�s�A4�B#�4)B �B �#B,c��tjdttjd��}tj
|�y)Nr�z�            import sys
            class C:
               def __del__(self):
                  import importlib
            sys.argv.insert(0, C())
            )r�make_scriptrr�r��assert_python_ok)rO�testfns  r4�!test_import_in_del_does_not_crashz-ImportTests.test_import_in_del_does_not_crashis7���*�*�2�v�x���H�8���	�&�&�v�.r6c��tjjdtj�	t
dz}tjj|�}t|dd��5}	ddd�	tj|d�t#t
�tj$|�tjd=t't
�y#1swY�exYw#t$r|jd�Y�mt$rY}|jttdd�ttd	d�fvr�|jd
j!|��Yd}~��d}~wwxYw#tjd=t't
�wxYw)NrrDr�r�r�)���rDz-cannot set modification time to large integer�	EOVERFLOW�EINVALz2cannot set modification time to large integer ({}))rZr�rr�rrr��util�cache_from_sourcer��utime�
OverflowErrorrN�OSError�errno�getattrr�r'�statrJ)rOr�compiledrI�es     r4�test_timestamp_overflowz#ImportTests.test_timestamp_overflowts!��	������2�9�9�%�	!��e�^�F� �~�~�7�7��?�H��f�c�G�4���5�
^�����!;�<�
�v���G�G�H��������� �!5�4��!�
O��
�
�M�N��
^��7�7�7�5�+�t�#D�#*�5�(�D�#A�#C�C���
�
�R�Y�Y�Z[�\�]�]��	
^��������� �sZ�6E�&C�(E�1C�$E�C�E�E�2E�4E�<AE�E�E�E�"E:c�b�	tddg��y#t$r|jd�YywxYw)N�httpr�)�fromlistzfromlist must allow bogus names)r'r�r�r�s r4�test_bogus_fromlistzImportTests.test_bogus_fromlist�s/��	9��v���1���	9��I�I�7�8�	9�s��.�.c�z�ddg}tj|�}|j�\}}|jd|�y)N�-cz&del __builtins__.__import__; import ossImportError)r�spawn_python�communicater�)rO�args�popen�stdout�stderrs     r4�test_delete_builtins_importz'ImportTests.test_delete_builtins_import�s=���>�?���*�*�D�1���*�*�,�����
�
�n�f�-r6c�f�|jtd�5ddlm}ddd�y#1swYyxYw)Nz^No module named 'bogus'r)�foo)r�r��bogusr`)rOr`s  r4�/test_from_import_message_for_nonexistent_modulez;ImportTests.test_from_import_message_for_nonexistent_module�s#��
�
#�
#�K�1K�
L�!�M�
L�
L���'�0c�f�|jtd�5ddlm}ddd�y#1swYyxYw)Nz^cannot import name 'bogus'r)ra)r�r�r�ra)rOras  r4�,test_from_import_message_for_existing_modulez8ImportTests.test_from_import_message_for_existing_module�s#��
�
#�
#�K�1N�
O� �P�
O�
O�rcc�"�Gd�d�}d}|jt|�|�tj|<|j	t
�5}ddlm}ddd�|jtj�d�y#1swY�/xYw)Nc��eZdZd�Zy)�IImportTests.test_from_import_AttributeError.<locals>.AlwaysAttributeErrorc��t�r=)�AttributeError)rO�_s  r4�__getattr__zUImportTests.test_from_import_AttributeError.<locals>.AlwaysAttributeError.__getattr__�s��$�$r6N)r�r�r�rlrTr6r4�AlwaysAttributeErrorrh�s��
%r6rm�test_from_import_AttributeErrorr��does_not_existzScannot import name 'does_not_exist' from '<unknown module name>' (unknown location))�
addCleanuprrZr[r�r�rnrpr�r&r�)rOrm�module_namer�rps     r4rnz+ImportTests.test_from_import_AttributeError�sr��	%�	%�8�������,�#7�#9����K� �
�
�
�{�
+�r�F�,�	
����R�\�\�*�a�	c�,�
+�s�B�Bc�$�ttdd�5|jt�5ddlm}ddd�|jt
�5tjddd�ddd�y#1swY�@xYw#1swY�xYw#1swYyxYw)Nr�rro)rr�r�r�rprj)rOrps  r4�test_issue31492zImportTests.test_issue31492�se��
�r�:�t�
,��"�"�;�/�-�0��"�"�>�2��!�!�3�	-�
,�/�/��3�2��	-�
,�s9�B�A.�B�A:�B�.A7	�3B�:B	�?B�Bc�����d��tjjdtjj	tjjt�d��	d����fd�}td�D]�}tj��td�D�cgc]}tj|����}}	tj|�j�5tjd�ddd�tj j#dd�tj j#d	d����ʼn�	tjd=ycc}w#1swY�gxYw#tj j#dd�tj j#d	d�wxYw#tjd=wxYw)
Nc�n�|dk(r0|jjdk(rtjd�yyy)N�call�has_deadlockg�������?)�f_code�co_name�time�sleep)�frame�event�args   r4�delay_has_deadlockz8ImportTests.test_concurrency.<locals>.delay_has_deadlock�s-�����5�<�<�#7�#7�>�#I��
�
�3��$J�r6r�datac���tj���j�	ddl}tjd�y#t$r}|�Yd}~�&d}~wwxYwr�)rZ�settrace�wait�package�
BaseException)r�rPr�r~�excs  ���r4�runz)ImportTests.test_concurrency.<locals>.run�sF������/�0��
�
���"����T�"��%���C���s�A�	A�A�Ar*r�)�targetr�zpackage.submodule)rZr�rr��join�dirnamer`r�	threading�Event�Threadr�
start_threads�setr{r|r[r\)rOr�rr&�threadsr�r~r�s     @@@r4�test_concurrencyzImportTests.test_concurrency�s1���	 �	������2�7�7�<�<�������(A�6�J�K�	��C�
#��2�Y��!���)��AF�q��J��A�9�+�+�3�7���J�?�)�7�7�����K��
�
�1�
�L��K�K�O�O�I�t�4��K�K�O�O�$7��>��?��I��������K�K�K���K�K�O�O�I�t�4��K�K�O�O�$7��>�������sV�'8F,�E�<F,�? E'�E�5E'�=AF,�F,�F,�E$	� E'�'AF)�)F,�,F?�win32�Windows-specificc
�n�ddlm}|tj�}tj
j
d�j}tjjtjj|�djd|vrdnd��}tj�5}tjj|d�}tj|�tjj|tjj!tj"��}t%j&tj"|�t%j&||�t)j(tjjt)j*tj,�d��D]}t%j&||��t%j&||�d}	tj.D�
cic]$}
|
j1�tj.|
��&}	}
|d	zt2z|	d
<t5j6|dd	jdd
jtjj|��ddg�gt4j8|	tjj|���t%j&||�t5j6|ddgt4j8|	tjj|���ddd�ycc}
w#1swYyxYw)Nr)�GetModuleFileName�_sqlite3z
sqlite3{}.dll�_dr��DLLszvcruntime*.dll�;�
PYTHONPATHz-Scz	import oszp = os.add_dll_directory({!r})zimport _sqlite3zp.close)r]�env�cwd)�_winapir�rZ�	dllhandler�rG�	find_specr9r�r�r�r�r�r	�temp_dir�mkdir�basename�
executable�shutil�copy�globr��prefix�environ�upperr
�
subprocess�
check_call�STDOUT)rOr��dllname�pydname�depname�tmp�tmp2�pyexerIr��ks           r4�test_dll_dependency_importz&ImportTests.test_dll_dependency_import�s9��-�#�C�M�M�2���.�.�*�*�:�6�=�=���'�'�,�,��G�G�O�O�G�$��"�"�4�7�?�4��C�E���
�
�
!�S��7�7�<�<��V�,�D��H�H�T�N��G�G�L�L��b�g�g�&6�&6�s�~�~�&F�G�E��K�K�����.��K�K���%��Y�Y�r�w�w�|�|�D�K�K��
�
�,C�EU�V�W�����A�s�#�X�
�K�K���&��C�57�Z�Z�@�Z��1�7�7�9�b�j�j��m�+�Z�C�@� $�s�
�Z� 7�C���
�!�!��u�c�h�h��4�;�;�������0�2�%��(��#�"�(�(���G�G�O�O�E�*�

,�
�K�K���&��!�!�5�%�1B�"C�+5�+<�+<�(+�(*������(>�
@�?"�
!��A�"�
!�s �,EL+�)L&�)C4L+�&L+�+L4c���|jt�5}tjdd�ddd�|j	dtj��y#1swY�/xYw)Nr&s6'�Cuz"Frozen object named 'x' is invalid)r�r��_imp�get_frozen_objectr�r&r�)rOr�s  r4�test_issue105979zImportTests.test_issue105979sL��
�
�
�{�
+�r��"�"�3�(8�9�,��
�
�:��"�,�,�'�	)�,�
+�s�A�A$c�@�|jtd�5Gd�d�}tj|��ddd�|jtd�5Gd�d�}tj|��ddd�y#1swY�MxYw#1swYyxYw)Nzembedded null characterc��eZdZdZdZy)�2ImportTests.test_create_dynamic_null.<locals>.Spec�ab�abcN�r�r�r�rHr9rTr6r4�Specr�s�����r6r�c��eZdZdZdZy)�3ImportTests.test_create_dynamic_null.<locals>.Spec2r�r�Nr�rTr6r4�Spec2r�s����!�r6r�)r��
ValueErrorr��create_dynamic)rOr�r�s   r4�test_create_dynamic_nullz$ImportTests.test_create_dynamic_nulls���
�
#�
#�J�0I�
J�
�
�
�����'�	K��
#�
#�J�0I�
J�
"�
"�
�����(�	K�
J�
K�
J��K�
J�s�%B�%B�B�BN)�longlist)+r�r�r�r�r�r�r�r�r�r
r�r�r�r�r�r�rrrr(r,r1�skip_if_dont_write_bytecoder7r=rBrQrUr^rbrernrtr�requires_working_threadingr�r+�
skipUnlessrZr	r�r�r�rTr6r4r�r�@s<��&��<�F�K�h�����"-�+�7�*�7�'�R&�P!�(	3�3�"$�L!�(�!�(�.�	/�!�!�!�!�29��.��.�"�!�c� �	"��	"�1��0�0�2� �3� �D�X�������0�2D�E�*@�F�*@�X)�)r6r�c�f�eZdZejejdk(d�ejexse	d�d���Z
ejejdk(d�ejd���Z
ejejdk(d�ejd���Zd�Zy)	�FilePermissionTests�posix�%test meaningful only on posix systemsz$Emscripten's/WASI's umask is a stub.c���d}t|�5t�5\}}tjj	|�}t|�}tjj|�s|jd�t
j|�}ddd�ddd�|jttjj��td|z��y#1swY�WxYw#1swY�[xYw)N��4__import__ did not result in creation of a .pyc filei�)rrr�rGrHr'r�r��existsr�rNr��oct�S_IMODE�st_mode)rO�maskrHr��cached_pathr.�	stat_infos       r4�test_creation_modez&FilePermissionTests.test_creation_mode(s�����
��
��0�L�T�4�#�.�.�:�:�4�@�K���%�F��7�7�>�>�+�.��	�	�(�)�����,�I�
 1�
�	
����T�\�\�)�*;�*;�<�=��U�d�U�]�+�	-� 1�0��
�
�s#�C.�A3C"�C.�"C+	�'C.�.C7c��d}td�5t�5\}}tjj	|�}tj||�t|�t
jj|�s|jd�tj|�}ddd�ddd�|jttjj��t|��y#1swY�SxYw#1swY�WxYw)N�r�r��rrr�rGrHr��chmodr'r�r�r�rNr�r�r�r�)rO�moderHr�r�r�s      r4�test_cached_mode_issue_2051z/FilePermissionTests.test_cached_mode_issue_2051=s���
��
��
�� 1�\�d�D�#�.�.�:�:�4�@�K��H�H�T�4� ��t���7�7�>�>�+�.��	�	�(�)�����,�I�!2�
�	
����T�\�\�)�*;�*;�<�=�s�4�y�I�!2� 1��
�
�s#�D�B	C4�"D�4C=	�9D�D	c�"�d}td�5t�5\}}tjj	|�}tj||�t|�t
jj|�s|jd�tj|�}ddd�ddd�|dz}|jttjj��t|��y#1swY�XxYw#1swY�\xYw)N�r�r��r�)rOr�rHr�r�r�r1s       r4�test_cached_readonlyz(FilePermissionTests.test_cached_readonlyNs�����
��
�� 1�\�d�D�#�.�.�:�:�4�@�K��H�H�T�4� ��t���7�7�>�>�+�.��	�	�(�)�����,�I�!2�
��%�<������T�\�\�)�*;�*;�<�=�s�8�}�M�!2� 1��
�
�s#�D�B	C9�"D�9D	�>D�Dc���t�5\}}t|dd��5}|jd�ddd�tj|�}tj
||j|jdz
f�tj|d�t|�}|j|jd�tj|d�t|dd��5}|jd	�ddd�t|�tj�t|�}|j|jd
�t|�t|�tj�|dz}tj tj"j%|�|�t|�}|j|jd
�ddd�y#1swY���xYw#1swY��xYw#1swYyxYw)Nr�r�r�zx = 'original'
i�r��originalr�zx = 'rewritten'
�	rewrittenr)rr�r�r�rNrI�st_atime�st_mtimer�r'r�r&rr�r�r�renamerGrH)rOrHr�rI�s�m�
bytecode_onlys       r4�test_pyc_always_writablez,FilePermissionTests.test_pyc_always_writable_si���
�,�4���d�C�'�2�a����*�+�3�����
�A��H�H�T�A�J�J��
�
�9�(<�=�>��H�H�T�5�!��4� �A����Q�S�S�*�-��H�H�T�5�!��d�C�'�2�a����+�,�3��4�L��'�'�)��4� �A����Q�S�S�+�.��4�L��4�L��'�'�)� �3�J�M��I�I�i�n�n�6�6�t�<�m�L��4� �A����Q�S�S�+�.�3�
�2�2��3�2���
�s;�G'�G�B-G'�G�.CG'�G	�G'�G$	� G'�'G0N)r�r�r�r+r�r�rHrgrrr�r	�skip_unless_working_chmodr�r�r�rTr6r4r�r�$s����X������G�+�@�B��X�_�_�� ��.��
-�	�B�
-��X������G�+�@�B��(�(�J�)�B�J��X������G�+�@�B��(�(�N�)�B�N�/r6r�c��eZdZdZdZejje�Z	ejje	e�ejzdzZe
jje�Zd�Zd�Zd�Zd�Zd�Zd	�Zd
�Zy)�PycRewritingTests�unlikely_module_namez�
import sys
code_filename = sys._getframe().f_code.co_filename
module_filename = __file__
constant = 1
def func():
    pass
func_filename = func.__code__.co_filename
r.c���tjdd|_tjj	|j
d�|_tj|j�t|jdd��5}|j|j�ddd�tjjd|j�tj �y#1swY�HxYw)Nr�r�r�r)rZr��sys_pathr[r\rr�orig_moduler�r��dir_namer��	file_namer��
module_sourcerr�r�)rOrIs  r4r�zPycRewritingTests.setUp�s���������
��;�;�?�?�4�+;�+;�T�B���
�������
�$�.�.�#��
8�A�
�G�G�D�&�&�'�9�������4�=�=�)��#�#�%�9�
8�s�?C"�"C+c�N�|jtjdd|j�(|jtj|j
<nt
|j
�t|j�t|j�t|j�yr=)r�rZr�r�r[rrrrr��
compiled_namerr�r�s r4r�zPycRewritingTests.tearDown�sm���m�m���������'�,0�,<�,<�C�K�K��(�(�)��4�#�#�$��t�~�~���t�!�!�"��t�}�}�r6c�~�t�}t|j||�tj|jSr=)r�r'rrrZr[)rOrqs  r4�
import_modulezPycRewritingTests.import_module�s0��
�Y���4�#�#�R��,��{�{�4�+�+�,�,r6c�B�|j�}|j|j|j�|j|j|j�|j|j
|j�tj|j=|j�}|j|j|j�|j|j|j�|j|j
|j�yr=)	r�r��module_filenamer��
code_filename�
func_filenamerZr[rr�rOrzs  r4�test_basicszPycRewritingTests.test_basics�s���� � �"������,�,�d�n�n�=�����*�*�D�N�N�;�����*�*�D�N�N�;��K�K��(�(�)�� � �"������,�,�d�n�n�=�����*�*�D�N�N�;�����*�*�D�N�N�;r6c�J�tj|jd��|j�}|j	|j
|j�|j	|j|j�|j	|j|j�y�Nzanother_module.py)�dfile)rrr�r�r�r�r�r�rs  r4�test_incorrect_code_namez*PycRewritingTests.test_incorrect_code_name�ss�����4�>�>�1D�E�� � �"������,�,�d�n�n�=�����*�*�D�N�N�;�����*�*�D�N�N�;r6c��d}tj|j|��tj|j�t|j�}t
j�|j�}|j|j|�|j|j|�|j|j|�yr)
rrr�r�r4rr�r�r�r�r�r�r�)rOr��pyc_filerzs    r4�test_module_without_sourcez,PycRewritingTests.test_module_without_source�s���$�����4�>�>��8�
�	�	�$�.�.�!�"�4�>�>�2���#�#�%�� � �"������,�,�h�7�����*�*�F�3�����*�*�F�3r6c���tj|j�t|jd�5}|jd�}t
j|�}ddd�tj�}tjj}|jd�}|||<|jt|���}t|jd�5}|j!�t
j"||�ddd�|j�}|j%|j&j(|j(�y#1swY��xYw#1swY�VxYw)N�rb�r)�	co_consts�wb)rrr�r�r�r��marshal�load�listrr�r��__code__�index�replacer�r��dumpr��constant�co_filename)rOrI�header�code�	constants�foreign_code�posrzs        r4�test_foreign_codez#PycRewritingTests.test_foreign_code�s�����4�>�>�*�
�$�$�$�d�
+�q��V�V�B�Z�F��<�<��?�D�,�����(�	� �.�.�7�7���o�o�a� ��%�	�#���|�|�e�I�&6�|�7��
�$�$�$�d�
+�q�
�G�G�F�O��L�L��q�!�,�� � �"��������1�1�<�3K�3K�L�,�
+��,�
+�s�'E�(E�E�E!N)r�r�r�rrr�r�r�r9rr�r�r/r�r�rGrHr�r�r�r�rrrrrTr6r4r�r�~s~��
)�K��M��w�w���v�&�H������X�{�3�b�i�i�?�$�F�I��N�N�4�4�Y�?�M�&��-�
	<�<�	4�Mr6r�c�r�eZdZdZeZd�Zd�Zd�Ze	jejdk(d�d��Z
y)	�
PathsTests)r!utestäöüßutestéèu
test°³²c�r�tj|j�tjdd|_yr=)r�r�r�rZ�syspathr�s r4r�zPathsTests.setUp�s!��
��������x�x��{��r6c�h�t|j�|jtjddyr=)rr�r rZr�s r4r�zPathsTests.tearDown�s���t�y�y���l�l�����r6c�x�ttjj|jd�dd��5}|j	d�ddd�t
jj
|jdz�td�}|j|jd�td�y#1swY�hxYw)Nztest_trailing_slash.pyr�r�r�z testdata = 'test_trailing_slash'�/�test_trailing_slash)r�r�r�r�r�rZrr'r��testdatar)rOrIrzs   r4r$zPathsTests.test_trailing_slash�s���
�"�'�'�,�,�t�y�y�*B�C���)�,-�
�G�G�6�7�)�	������	�	�#�
�&��.�/��������'<�=��$�%�
)�)�s�B0�0B9r�r�c���ttjj|jd�d�5}|j	d�ddd�tj�tjj|j�}ddl}|j�}|d}d|�d|�d�}||ddz
}	tj|�t"jj%d|�	t'd
�}|j-j.d
�|j1|j2j5|�|j2�t7d
�y#1swY��xYw#t$rU}|jtjtjtjfvr|j!d	|����d}~wwxYw#t($r!}|j+d|�d|���Yd}~��d}~wwxYw)
Nztest_unc_path.pyr�ztestdata = 'test_unc_path'rz\\�\�$r�z#cannot access administrative share �
test_unc_pathz&could not import 'test_unc_path' from z: )r�r�r�r�r�r�r�r9�socket�gethostname�listdirrKrL�EPERM�EACCES�ENOENTrNrZrr'r�r�r�r%r$r`r
r)	rOrIr�r*�hn�drive�uncrPrzs	         r4�
test_UNC_pathzPathsTests.test_UNC_path�st��
�"�'�'�,�,�t�y�y�*<�=�s�
C�q�
�G�G�0�1�D��#�#�%��w�w���t�y�y�)���
�
�
�
!���Q�����'���t�A�B�x���	��J�J�s�O�	������3��	"��_�-�C�	
�������7�������/�/��4�c�l�l�C����3D�
C���	��w�w�5�;�;����e�l�l�C�C��
�
��N�O���		���	"��I�I��a�!�
"�
"��	"�s<�E�7E"�-G�E�"	G�+AF;�;G�	G-�G(�(G-N)r�r�r��SAMPLESrr�r�r�r$r+r�rZr	r3rTr6r4rr�sK��)�G��D�#�#�
&��X�������0�2D�E� �F� r6rc�F�eZdZd�ZeZd�Zd�Zd�Zd�Zd�Z	d�Z
d�Zd	�Zy
)�RelativeImportTestsc��td�y)Nztest.relimport)rr�s r4r�zRelativeImportTests.tearDowns���� r6c�F�ddlm}|jt|d��y)Nr�)�	relimportr6)r�r9r$r�)rOr9s  r4�test_relimport_starz'RelativeImportTests.test_relimport_stars�� �����	�+@�A�Br6c�@���fd�}tdd���|�tdd���|�tdd���|jt|�tdd���|jt|�tt����|jt|�y)Nc���td��y)Nzfrom . import relimport)r�)rqs�r4�check_relativez:RelativeImportTests.test_issue3221.<locals>.check_relatives����*�B�/r6r!ztest.notarealmodule)�__package__r�znotarealpkg.notarealmoduler`)r>)�dictr�r��objectr�)rOr=rqs  @r4�test_issue3221z"RelativeImportTests.test_issue3221s����	0��f�/D�
E�����f�/K�
L�����e�.C�
D�����-�~�>��e�.J�
K�����-�~�>��f�h�
'�����)�^�4r6c�4�tjdddd�y)Nz-W�ignorerWzfoo = 1; from . import foo)r�assert_python_failurer�s r4�)test_parentless_import_shadowed_by_globalz=RelativeImportTests.test_parentless_import_shadowed_by_global5s���+�+�D�(�D�(�	*r6c��|jt�5ddlm}|j	d�ddd�y#1swYyxYw)Nr)�sepz>explicit relative import triggered an implicit absolute import)r�r�r�rGr�)rOrGs  r4�#test_absolute_import_without_futurez7RelativeImportTests.test_absolute_import_without_future:s2���
�
�{�
+���I�I�1�
2�,�
+�
+�s	�7�Ac���tjjtjjt�dd�}tdd�5t
|�5|jt�5ddl	}ddd�|jdtj�|jdtj�ddd�ddd�y#1swY�ZxYw#1swY�xYw#1swYyxYw)Nr��package2�
submodule1�
submodule2r)
r�r�r�r�r`rrr�r�rKr�rZr[)rOr�rKs   r4�test_import_from_non_packagez0RelativeImportTests.test_import_from_non_packageCs����w�w�|�|�B�G�G�O�O�H�5�v�z�J��
�\�<�
0�-��2E��"�"�;�/�!�0����\�3�;�;�7����\�3�;�;�7�	3F�
0�
0�/�/��3F�2E��
0�
0�s=�C'�C�1C�6AC�>C'�C�C�C$	� C'�'C0c�:�tddd�5ttjj	tjjt�d��5ddl}|jjddd�ddd�y#1swY�xYw#1swYyxYw)NrJzpackage2.submodule1zpackage2.submodule2r�r)
rrr�r�r�r�r`�package2.submodule1rKrL)rOrJs  r4�!test_import_from_unloaded_packagez5RelativeImportTests.test_import_from_unloaded_packageKsf��
�Z�!6�8M�
N�
�2�7�7�<�<�������(A�6�J�
K�&����*�*�L�O�
N�
K�
K��O�
N�s$�AB�B�4B�B	�
B�Bc��tjjtjjt�d�}tdd�5t
|�5ddlm}|j|jd�ddlm}|j|jd�ddd�ddd�tdd�5t
|�5ddlm}|j|jd�ddlm}|j|jd�ddd�ddd�y#1swY�xYw#1swY��xYw#1swY�*xYw#1swYyxYw)Nr��package3zpackage3.submoduler��	submodule�rebound)r�r�r�r�r`rrrRrTr��attr�package3.submodule�rOr�rTs   r4�test_rebindingz"RelativeImportTests.test_rebindingQs����w�w�|�|�B�G�G�O�O�H�5�v�>��
�Z�!5�
6�
�d�8K�*����Y�^�^�Y�7�2����Y�^�^�Y�7�	9L�
6�
�Z�!5�
6�
�d�8K�2����Y�^�^�Y�7�*����Y�^�^�Y�7�	9L�
6�
6�9L�8K��
6�
6��
9L�8K��
6�
6��J�D)�AD�D)�;E�AD5�E�D&	�"D)�)D2�5D>	�:E�E
c��tjjtjjt�d�}tdd�5t
|�5ddlm}|j|jd�ddlm}|j|jd�ddd�ddd�tdd�5t
|�5ddlm}|j|jd�ddlm}|j|jd�ddd�ddd�y#1swY�xYw#1swY��xYw#1swY�*xYw#1swYyxYw)Nr��package4zpackage4.submodulerrTrSr9)r�r�r�r�r`rr�package4.submodulerTr�rVr\rXs   r4�test_rebinding2z#RelativeImportTests.test_rebinding2`s����w�w�|�|�B�G�G�O�O�H�5�v�>��
�Z�!5�
6�
�d�8K�2����Y�^�^�[�9�*����Y�^�^�[�9�	9L�
6�
�Z�!5�
6�
�d�8K�*����Y�^�^�X�6�2����Y�^�^�[�9�	9L�
6�
6�9L�8K��
6�
6��
9L�8K��
6�
6�rZN)
r�r�r�r�r�r:rArErHrMrPrYr^rTr6r4r6r6
s5��!��E�C�
5�:*�
2�8�+�
8�:r6r6c��eZdZd�Zy)�OverridingImportBuiltinTestsc�@�ddl}d�}|j|�|�ttdd��5|j|�d�ddd�t	t�dd��5|j|�|�ddd�y#1swY�@xYw#1swYyxYw)Nrc��ddl}|Sr��r�rcs r4r`z?OverridingImportBuiltinTests.test_override_builtin.<locals>.fooss
����Ir6r'c��y�N�rT�r&s r4�<lambda>zDOverridingImportBuiltinTests.test_override_builtin.<locals>.<lambda>xs��!r6rfc��yrerTrgs r4rhzDOverridingImportBuiltinTests.test_override_builtin.<locals>.<lambda>~s��1r6)r�r�r�builtinsrr�)rOr�r`s   r4�test_override_builtinz2OverridingImportBuiltinTests.test_override_builtinos}���	�	
������#�
�x��|�
<����S�U�A�&�=��w�y�,��
=����S�U�B�'�>�
=�
=�
<��>�
=�s�B�'B�B�BN)r�r�r�rkrTr6r4r`r`ns��(r6r`c�>�eZdZd�Zd�Zd�Zed��Zeje
jdk(d�eejejejed�d������Zed	��Zed
��Zd�Zed��Zed
��Zd�Zd�Zy)�PycacheTestsc�b�tt�td�t|j�y)NrG)rrrrrr�s r4�_cleanzPycacheTests._clean�s���v���}���t�{�{�r6c�8�tdz|_|j�t|jdd��5}t	d|��ddd�t
jjdtj�tj�y#1swY�LxYw)NrDr�r�r�z/# This is a test file written by test_import.pyr�r)rrror�r�rZr�rr�rr�r�)rO�fps  r4r�zPycacheTests.setUp�sc���u�n������
�
�$�+�+�s�W�
5���C�"�M�6�������2�9�9�%��#�#�%�6�
5�s�B�Bc��tjdtjk(sJd��tjd=|j	�y)NrzUnexpected sys.path[0])rZr�r�rror�s r4r�zPycacheTests.tearDown�s6���x�x��{�b�i�i�'�A�)A�A�'��H�H�Q�K����
r6c��|jtjjd��t	t
�|j
tjjd��tjj|j�}|j
tjj|�dj|t
��y)NrGz*bytecode file {!r} for {!r} does not exist)�assertFalser�r�r�r'rr$r�rGrHrr��rO�pyc_paths  r4�test_import_pyc_pathz!PycacheTests.test_import_pyc_path�s�����������
�6�7��6����������}�5�6��>�>�3�3�D�K�K�@����������x�0� � &��x�� 8�	:r6r�r�zumask is a stubc��td�5tt�ddd�|jtj
j
d��tjj|j�}|jtj
j
|�dj|t��y#1swY��xYw)N�rGz"bytecode file {!r} for {!r} exists)
rr'rr$r�r�r�r�rGrHrrtr�rus  r4�test_unwritable_directoryz&PycacheTests.test_unwritable_directory�s�����
��v�����������}�5�6��>�>�3�3�D�K�K�@�����������1�!�!'���&�!9�	;�	�
�s�B?�?Cc��tt�tjj	|j
�}|j
tjj|��tj|j
�tt�tj�|jttt�yr=)r'rr�rGrHrr$r�r�r�r4rr�r�r�)rOrs  r4�test_missing_sourcez PycacheTests.test_missing_source�sr��	�6���>�>�3�3�D�K�K�@����������x�0�1�
�	�	�$�+�+���v���#�#�%����+�z�6�:r6c	� �tt�t|j�}t	j
|j�t
t�tj�tt�}	|j|jtjjt	j�tjj|���t	j
|�y#t	j
|�wxYwr=)r'rrrr�r4rr�r�r�r`r�r��getcwd�relpath�rOrr�s   r4�test_missing_source_legacyz'PycacheTests.test_missing_source_legacy�s���	�6��"�4�;�;�/��
�	�	�$�+�+���v���#�#�%��v���	 ����Q�Z�Z��W�W�\�\�"�)�)�+�r�w�w���x�7P�Q�
S�
�I�I�h���B�I�I�h��s
�7A)C6�6D
c��tt�}tjj	tdz�}|j|jtjjtj�|��y)NrD)r'rr�rGrHr��
__cached__r�r�r�r~)rOr�rs   r4�test___cached__zPycacheTests.test___cached__�sM���v����>�>�3�3�F�U�N�C��������r�w�w�|�|�B�I�I�K��'J�Kr6c	��tt�t|j�}t	j
|j�t
t�tj�tt�}|j|jtjjt	j�tjj|���yr=)r'rrrr�r4rr�r�r�r�r�r�r~rr�s   r4�test___cached___legacy_pycz'PycacheTests.test___cached___legacy_pyc�s���	�6��"�4�;�;�/��
�	�	�$�+�+���v���#�#�%��v��������������b�i�i�k�2�7�7�?�?�8�3L�M�	Or6c���d�}tjd�|j|�ttjjdd�d�5	ddd�ttjjdd�d�5	ddd�t
j�td�}tjjtjjdd��}|j|jtjjtj�|��tjjtjjdd��}|jtjdjtjjtj�|��y#1swY���xYw#1swY��ZxYw)Nc�F�td�td�td�y�N�pep3147�pep3147.foo�rrrTr6r4�cleanupz5PycacheTests.test_package___cached__.<locals>.cleanup�����9���=�!��9�r6r��__init__.pyr
�foo.pyr�)r�r�rqr�r�r�r�r�r'rGrHr�r�r~rZr[�rOr�r��init_pyc�foo_pycs     r4�test_package___cached__z$PycacheTests.test_package___cached__�s4��	�	��������� �
�"�'�'�,�,�y�-�8�$�
?��@�
�"�'�'�,�,�y�(�3�T�
:��;��#�#�%��}�%���>�>�3�3��G�G�L�L��M�2�4��������r�w�w�|�|�B�I�I�K��'J�K��.�.�2�2�2�7�7�<�<�	�8�3T�U��������]�3�>�>������b�i�i�k�7�;�	=�@�
?��
:�
:�s�G�G"�G�"G,c�H�d�}tjd�|j|�ttjjdd�d�5	ddd�ttjjdd�d�5	ddd�t
j�td�}td�td�t
j�td�}tjjtjjdd��}|j|jtjjtj�|��tjjtjjdd��}|jtj djtjjtj�|��y#1swY���xYw#1swY���xYw)Nc�F�td�td�td�yr�r�rTr6r4r�z>PycacheTests.test_package___cached___from_pyc.<locals>.cleanupr�r6r�r�r
r�r�)r�r�rqr�r�r�r�r�r'rrGrHr�r�r~rZr[r�s     r4� test_package___cached___from_pycz-PycacheTests.test_package___cached___from_pyc�sZ��	�	��������� �
�"�'�'�,�,�y�-�8�$�
?��@�
�"�'�'�,�,�y�(�3�T�
:��;��#�#�%��}�%���}���y���#�#�%��}�%���>�>�3�3��G�G�L�L��M�2�4��������r�w�w�|�|�B�I�I�K��'J�K��.�.�2�2�2�7�7�<�<�	�8�3T�U��������]�3�>�>������b�i�i�k�7�;�	=�@�
?��
:�
:�s�H
�H�
H�H!c�
�tt�tt�t|jdd��5}td|��ddd�tt�}|j
|jd�y#1swY�5xYw)Nrr�r�zx = 5r�rf)r'rrr�rr�r�r&)rOrqr�s   r4�test_recompute_pyc_same_secondz+PycacheTests.test_recompute_pyc_same_seconds[��	�6���v��
�$�+�+�s�W�
5���'��#�6��v���������a� �6�
5�s�A9�9BN)r�r�r�ror�r�r�rwr+r�r�rHr	r��skip_if_dac_overridergrrzr|r�r�r�r�r�r�rTr6r4rmrm�s����
&��
!�:�!�:��X������G�+�@�B� ��(�(��#�#��X�_�_�]�$5�6�	;�7�$�)�!�B�	;�!�	;�!�	;�!� �!� �$L�!�
O�!�
O�!�=�!�=�,=�6!r6rmc��eZdZdZedzZd�Zd�Zeje	e
d�xse
j�dk\d�ejd���Zy	)
�TestSymbolicallyLinkedPackage�samplez-taggedc���tj|j�tj|j�tj
dd|_tj|j�|jtj|j�tj
j|jd�}tj|�tj
j|�sJ�tj|j|jd��|jtj|j�tj �|j#tj
j%|j�d�tj
j'tj
j|jd��sJ�y)Nr�T)�target_is_directory)r	r�tagged�package_namerZr��
orig_sys_pathr�r�rqr��create_empty_filer��symlinkrr�r�r��isdir�isfile)rO�	init_files  r4r�z#TestSymbolicallyLinkedPackage.setUp(s.��������%�����*�*�+� �X�X�a�[���	����������	�(�(�$�+�+�6��G�G�L�L����m�<�	��#�#�I�.��w�w�~�~�i�(�(�(�	�
�
�4�;�;�� 1� 1�t�L����	�(�(�$�*;�*;�<��#�#�%���������t�'8�'8�9�4�@��w�w�~�~�b�g�g�l�l�4�+<�+<�m�L�M�M�Mr6c�>�|jtjddyr=)r�rZr�r�s r4r�z&TestSymbolicallyLinkedPackage.tearDown?s���(�(�����r6�getwindowsversion)�rzWindows Vista or later requiredc�R�dgtjddtjj|j�sJ�tjjtjj|jd��sJ�t
j|j�y)N�.r�)rZr�r�r�r�r�r�r�r�s r4�test_symlinked_dir_importablez;TestSymbolicallyLinkedPackage.test_symlinked_dir_importableCsp���e�������w�w�~�~�d�/�/�0�0�0��w�w�~�~�b�g�g�l�l�4�+<�+<�m�L�M�M�M�	���� 1� 1�2r6N)r�r�r�r�r�r�r�r+r�r�rZr�r	�skip_unless_symlinkr�rTr6r4r�r�$sv���L�
�I�
%�F�N�.)��X����C�,�-�-�	-� �3� � �"�f�,�)�+��"�"�3�#�	+�
3r6r�c�$�eZdZd�Zd�Zd�Zd�Zy)�ImportlibBootstrapTestsc�L�tjd}|j|�y)N�_frozen_importlib)rZr[r$rs  r4�test_frozen_importlibz-ImportlibBootstrapTests.test_frozen_importlibVs���k�k�-�.������r6c�4�ddlm}tjd}|j	||�|j|jd�|j|jd�|j|jjd�|j�y)Nr)�
_bootstrapr�zimportlib._bootstrapr�z
_bootstrap.py)r�r�rZr[r#r�r�r>r$r`r3)rOr�rzs   r4�"test_frozen_importlib_is_bootstrapz:ImportlibBootstrapTests.test_frozen_importlib_is_bootstrapZsl��(��k�k�-�.���
�
�c�:�&�������'=�>�������+�6�������-�-�o�>����Mr6c�4�ddlm}tjd}|j	||�|j|jd�|j|jd�|j|jjd�|j�y)Nr)�_bootstrap_external�_frozen_importlib_externalzimportlib._bootstrap_externalr�z_bootstrap_external.py)r�r�rZr[r#r�r�r>r$r`r3)rOr�rzs   r4�4test_frozen_importlib_external_is_bootstrap_externalzLImportlibBootstrapTests.test_frozen_importlib_external_is_bootstrap_externalbsn��1��k�k�6�7���
�
�c�.�/�������'F�G�������+�6�������-�-�.F�G����Vr6c��ddlm}tjd}|j	|j
|j
�y)Nr)�	machineryr�)r�r�rZr[r#�
ModuleSpec)rOr�rzs   r4�test_there_can_be_only_onez2ImportlibBootstrapTests.test_there_can_be_only_onejs.��	(��k�k�-�.���
�
�i�*�*�C�N�N�;r6N)r�r�r�r�r�r�r�rTr6r4r�r�Rs���N�W�<r6r�c�"�eZdZdZd�Zd�Zd�Zy)�GetSourcefileTestsz�Test importlib._bootstrap_external._get_sourcefile() as used by the C API.

    Because of the peculiarities of the need of this function, the tests are
    knowingly whitebox tests.

    c��tjd�5}d|_tdz}tdz}|j	t|�|�ddd�y#1swYyxYw)N�*importlib._bootstrap_external._path_isfileTrErD�r�patch�return_valuerr�r)rO�_path_isfiler��expects    r4�test_get_sourcefilez&GetSourcefileTests.test_get_sourcefile}sO���Z�Z�D�
E��(,�L�%��F�?�D��e�^�F����_�T�2�F�;�	F�
E�
E�s�5A�Ac��tjd�5}d|_tdz}|j	t|�|�ddd�y#1swYyxYw)Nr�FrEr�)rOr�r�s   r4�test_get_sourcefile_no_sourcez0GetSourcefileTests.test_get_sourcefile_no_source�sF���Z�Z�D�
E��(-�L�%��F�?�D����_�T�2�D�9�F�
E�
E�s�,A�Ac�L�tdz}|jt|�|�y)Nz.bad_ext)rr�r)rOr�s  r4�test_get_sourcefile_bad_extz.GetSourcefileTests.test_get_sourcefile_bad_ext�s#���
�"�������.��5r6N)r�r�r�r�r�r�r�rTr6r4r�r�ss���<�:�6r6r�c��eZdZd�Zd�Zdd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zed��Zej(ed�d��Zy)�ImportTracebackTestsc��tjt�tjdd|_tjj
dt�yr�)r�r�rrZr��old_pathrr�s r4r�zImportTracebackTests.setUp�s/��
�����������
�������6�"r6c�\�|jtjddtt�yr=)r�rZr�rrr�s r4r�zImportTracebackTests.tearDown�s���m�m�������v�r6c��tjjt||z�}t	|dd��5}|j|�ddd�|j
t|�tj�|S#1swY�5xYw)Nr�r�r�)
r�r�r�rr�r�rqrr�r�)rOrz�contentsr�fnamerIs      r4�
create_modulez"ImportTracebackTests.create_module�sa�������V�S�3�Y�/��
�%��w�
/�1�
�G�G�H��0������$��#�#�%���	0�
/�s�A<�<Bc�:�g}|rL|jj}|j}|r||dk7r|j|�|j}|r�L|jt
|�t
|�|�t||�D]\}}|j||��y)Nr)	�tb_frameryrr�tb_nextr��len�zipr�)rO�tb�files�
deduped_filesr�fn�pats       r4�assert_tracebackz%ImportTracebackTests.assert_traceback�s����
���;�;�%�%�D��!�!�B� �B�-��*;�$;��$�$�R�(����B��	
����]�+�S��Z��G��=�%�0�G�B���M�M�#�r�"�1r6c��	ddl}|jd�|j	t
g�y#t$r}|j}Yd}~�2d}~wwxYw)Nr�#ImportError should have been raised)�nonexistent_xyzzyr�r��
__traceback__r�r`)rOr�rPr�s    r4�test_nonexistent_modulez,ImportTracebackTests.test_nonexistent_module�sF��	=�$�
�I�I�;�<����b�8�*�-��	�	!����B��	!�s�/�	A�A	�	Ac���|jdd�	ddl}|jd�|jtdg�y#t$r}|j}Yd}~�3d}~wwxYw)Nr`zimport nonexistent_xyzzyrr�r�)r�r`r�r�r�r�r`�rOr`rPr�s    r4�test_nonexistent_module_nestedz3ImportTracebackTests.test_nonexistent_module_nested�sZ�����5�"<�=�	=��
�I�I�;�<����b�8�X�"6�7��	�	!����B��	!���A�	A!�A�A!c���|jdd�	ddl}|jd�|jtdg�y#t$r}|j}Yd}~�3d}~wwxYw)Nr`�1/0r�)ZeroDivisionError should have been raisedr��r�r`r�rr�r�r`r�s    r4�test_exec_failurez&ImportTracebackTests.test_exec_failure�sZ�����5�%�(�	C��
�I�I�A�B����b�8�X�"6�7��	!�	!����B��	!�r�c���|jdd�|jdd�	ddl}|jd�|jtddg�y#t$r}|j}Yd}~�4d}~wwxYw)	Nr`z
import bar�barr�rr�r��bar.pyr�r�s    r4�test_exec_failure_nestedz-ImportTracebackTests.test_exec_failure_nested�sl�����5�,�/����5�%�(�	C��
�I�I�A�B����b�8�X�x�"@�A��	!�	!����B��	!�s�A�	A4�A/�/A4c���|jdd�	ddl}|jd�|jtg�y#t$r}|j}Yd}~�2d}~wwxYw)Nr`zinvalid syntax is invalidrz#SyntaxError should have been raised)r�r`r��SyntaxErrorr�r�r`r�s    r4�test_syntax_errorz&ImportTracebackTests.test_syntax_error�sW�����5�"=�>�	=��
�I�I�;�<����b�8�*�-��	�	!����B��	!�s�A�	A �
A�A c�$�d}|jt|�tjj	t
|�}tj|�tjj	|d�}t|dd��5}|j|�ddd�tjj	|d�}t|dd��5}|j|�ddd�tj�||fS#1swY�ixYw#1swY�-xYw)N�_parent_foor�r�r�r�r�)rqrr�r�r�rr�r�r�r�r�)rO�parent�child�pkg_name�pkg_path�	init_pathrI�bar_paths        r4�_setup_broken_packagez*ImportTracebackTests._setup_broken_package�s��� �������)��7�7�<�<���1��
������G�G�L�L��=�9�	�
�)�S�7�
3�q�
�G�G�F�O�4��7�7�<�<��(�3��
�(�C�'�
2�a�
�G�G�E�N�3��#�#�%��(�"�"�
4�
3��3�
2�s�C:�D�:D�Dc���|jdd�\}}	ddl}|jd�|jt|g�y#t$r}|j}Yd}~�3d}~wwxYw)Nr�r�rr��r��_parent_foo.barr�rr�r�r`�rOr�r�r�rPr�s      r4�test_broken_submodulez*ImportTracebackTests.test_broken_submodule�sa��"�8�8��U�C��	�8�	C�"�
�I�I�A�B����b�8�X�"6�7��	!�	!����B��	!���A�	A$�A�A$c���|jdd�\}}	ddlm}|jd�|j
t|g�y#t$r}|j
}Yd}~�3d}~wwxYw)Nr�r�r�r�r��r�r�r�r�rr�r�r`�rOr�r�r�rPr�s      r4�test_broken_fromz%ImportTracebackTests.test_broken_froms`��"�8�8��U�C��	�8�	=�'�
�I�I�;�<����b�8�X�"6�7��	!�	!����B��	!���A�	A&�A!�!A&c���|jdd�\}}	ddl}|jd�|jt|g�y#t$r}|j}Yd}~�3d}~wwxYw)Nr�r�rr�rrs      r4�test_broken_parentz'ImportTracebackTests.test_broken_parentsa��"�8�8���C��	�8�	C�"�
�I�I�A�B����b�8�Y�"7�8��	!�	!����B��	!�rc���|jdd�\}}	ddlm}|jd�|j
t|g�y#t$r}|j
}Yd}~�3d}~wwxYw)Nr�r�rrr�rrs      r4�test_broken_parent_fromz,ImportTracebackTests.test_broken_parent_fromsa��"�8�8���C��	�8�	C�'�
�I�I�A�B����b�8�Y�"7�8��	!�	!����B��	!�r
c��|jdd�tjd}dt|j�vr|jj
}nd}	d�}||j_	ddl}|jd�|jtdtg�|�
|j`y||j_y#t$r}|j}Yd}~�Xd}~wwxYw#|�
|j`w||j_wxYw)	Nr`r�r��load_modulec��ddzy)NrrrT)rZs r4�exec_modulez9ImportTracebackTests.test_import_bug.<locals>.exec_module*s	���!�r6rr�z<frozen importlib)r�rZr[�vars�SourceLoaderrr`r�rr�r�r`)rOr��old_exec_modulerr`rPr�s       r4�test_import_bugz$ImportTracebackTests.test_import_bugs���	
���5�"�%��K�K� <�=�	��D��!7�!7�8�8�'�4�4�@�@�O�"�O�	E�
�1<�I�"�"�.�
G���	�	�E�F��!�!�"�x�1D�h�&O�P��&��*�*�6�5D�	�&�&�2��%�
%��_�_���
%���&��*�*�6�5D�	�&�&�2�s6�C!�,B?�0.C!�?	C�C�C!�C�C!�!"Dzneed TESTFN_UNENCODABLEc��tjdtd�}|jt|�|dd}tj
dd|zd��y)Nr��pass���rWzmod = __import__(%a)F)�
__isolated)rr?rrqrr@)rO�pynamerHs   r4�test_unencodable_filenamez.ImportTracebackTests.test_unencodable_filename:sM���*�*�2�/A�6�J�������'��c�r�{���&�&�t�-C�d�-J�27�	9r6N)rD)r�r�r�r�r�r�r�r�r�r�r�r�r�rr	rrr
rr+r�rrrTr6r4r�r��s���#�
��
#�.�8�8�	B�.�
#�8�8�9�9��E��E�4�X���+�-F�G�9�H�9r6r�c�R�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zy
)�CircularImportTestszQSee the docstrings of the modules being imported for the purpose of the
    test.c��ttjj��D]%}|j	d�s�tj|=�'y)zSMake sure no modules pre-exist in sys.modules which are being used to
        test.z&test.test_import.data.circular_importsN)rrZr[�keysr
)rO�keys  r4r�zCircularImportTests.tearDownJs9������(�(�*�+�C��~�~�F�G��K�K��$�,r6c�N�	ddl}y#t$r|jd�YywxYw)Nrz/circular import through relative imports failed)�,test.test_import.data.circular_imports.basicr�r��rOr!s  r4�test_directzCircularImportTests.test_directQs)��	I�?���	I��I�I�G�H�	I����$�$c�N�	ddl}y#t$r|jd�YywxYw)Nrz@relative import in module contributing to circular import failed)�/test.test_import.data.circular_imports.indirectr�r�r$s  r4�
test_indirectz!CircularImportTests.test_indirectWs*��	'�B���	'��I�I�&�
'�	'�r&c�N�	ddl}y#t$r|jd�YywxYw)Nrz-circular import involving a subpackage failed)�1test.test_import.data.circular_imports.subpackager�r�r$s  r4�test_subpackagez#CircularImportTests.test_subpackage^s)��	G�D���	G��I�I�E�F�	G�r&c��	ddlmcmcmcm}ddlm}|j|jj�y#t
$r|j
d�Y�IwxYw)Nrz9circular import with rebinding of module attribute failed)rG)
�0test.test_import.data.circular_imports.rebindingrr��circular_imports�	rebindingr�r��-test.test_import.data.circular_imports.subpkgrGr#)rOr0rGs   r4rYz"CircularImportTests.test_rebindingdsJ��	S�P�P�	G��
�
�d�i�i����0���	S��I�I�Q�R�	S�s�>�A�Ac�N�	ddl}y#t$r|jd�YywxYw)Nrz9circular import with binding a submodule to a name failed)�.test.test_import.data.circular_imports.bindingr�r�r$s  r4�test_bindingz CircularImportTests.test_bindingls)��	S�A���	S��I�I�Q�R�	S�r&c��ddl}ddl}yr�)�*test.test_import.data.circular_imports.use�-test.test_import.data.circular_imports.sourcer$s  r4�test_crossreference1z(CircularImportTests.test_crossreference1rs��9�<r6c��|jt�5}ddl}ddd�tj�}|jd|�|jd|�|jd|�|jd|�y#1swY�gxYw)Nrz-test.test_import.data.circular_imports.source�spamzpartially initialized modulezcircular import)r�rjr7r&r�r�)rOr�r!�errmsgs    r4�test_crossreference2z(CircularImportTests.test_crossreference2vsl��
�
�
�~�
.�"�@�/��R�\�\�"���
�
�E�v�N��
�
�f�f�%��
�
�4�f�=��
�
�'��0�
/�
.�s�B�B
c��|jt�5}ddl}ddd�|jdt	j
��y#1swY�/xYw)Nrz�cannot import name 'b' from partially initialized module 'test.test_import.data.circular_imports.from_cycle1' (most likely due to a circular import))r�r��2test.test_import.data.circular_imports.from_cycle1r�r&r��rOr�r!s   r4�test_circular_from_importz-CircularImportTests.test_circular_from_importsB��
�
�
�{�
+�r�E�,��
�
�
5�
�����		
�,�
+���A	�	Ac��|jt�5}ddl}ddd�|jdt	j
��y#1swY�/xYw)Nrz�cannot access submodule 'parent' of module 'test.test_import.data.circular_imports.subpkg2' (most likely due to a circular import))r�rj�5test.test_import.data.circular_imports.subpkg2.parentr�r&r�r?s   r4� test_absolute_circular_submodulez4CircularImportTests.test_absolute_circular_submodule�sB��
�
�
�~�
.�"�H�/��
�
�
5�
�����		
�/�
.�rAc��|jtd�|jtd�ddlmcmcm}|j
t�5ddlm}ddd�|jt|�t�|jt�t�|jt�5d|_ddd�y#1swY�mxYw#1swYyxYw)Nz test.test_import.data.unwritablez"test.test_import.data.unwritable.xrrg�*)rqr� test.test_import.data.unwritablerr��
unwritable�assertWarns�
ImportWarningr&�assertNotEqualr(r r�r�rj)rOrHr&s   r4�test_unwritable_modulez*CircularImportTests.test_unwritable_module�s������� B�C����� D�E�=�=�
�
�
�m�
,�:�-�	
���D��,�j�9�����a��*�-�
�
�
�~�
.��J�L�/�
.�-�
,��
/�
.�s�C�0C
�C
�
CN)r�r�r�r�r�r%r)r,rYr4r8r<r@rDrLrTr6r4rrEsA��
�%�I�'�G�1�S�=�1�
�
�r6rc�.�eZdZedddd��Zedd��Zej
�D���cic]	\}}||��c}}}Zded<eje
ed�d	�d
��Zd d�Z
d!dddd
�d�Zd!ddd�d�Zd!dd�d�Zddd�d�Zdd�d�Zd�Zed��Zed��Zej0edud�d��Zej0edud�d��Zej0edud�d��Zd�Zed��Zd�Ze ed���Z!ycc}}}w)"�SubinterpImportTestsFT)�
allow_fork�
allow_exec�
allow_threads�allow_daemon_threadsr�)�use_main_obmalloc�gilrrTr�zrequires os.pipe()c��tj�\}}|jtj|�|jtj|�t	td�rtj
|d�||fS)N�set_blockingF)r�r�rqr�r�rV)rOr�r�s   r4r�zSubinterpImportTests.pipe�sV���w�w�y���1�������!�$�������!�$��2�~�&��O�O�A�u�%��1�v�
r6Nc
��d}|�d|�d�}|r%tjd|�d|�d|�d|�d|�d	��Stjd
|�d|�d|�d	��S)
Nr�zZ
                import _imp
                _imp._override_multi_interp_extensions_check(�)
                z�
                from importlib.util import spec_from_loader, module_from_spec
                from importlib.machinery import ExtensionFileLoader
                import os, sys
                z.
                loader = ExtensionFileLoader(z, z*)
                spec = spec_from_loader(a4, loader)
                try:
                    module = module_from_spec(spec)
                    loader.exec_module(module)
                except ImportError as exc:
                    text = 'ImportError: ' + str(exc)
                else:
                    text = 'okay'
                os.write(z(, text.encode('utf-8'))
                z0
                import os, sys
                z1
                try:
                    import z�
                except ImportError as exc:
                    text = 'ImportError: ' + str(exc)
                else:
                    text = 'okay'
                os.write()r�r�)rOrH�fdr�check_override�
override_texts      r4�
import_scriptz"SubinterpImportTests.import_script�s����
��%�!>�>L�=M�N��M���?�?�(��� .�.2�X�R��|�D)�)-��1����$��
�"�?�?�(��� � �6�"�
���
$�
�

r6)�check_singlephase_setting�check_singlephase_override�isolatedc�4�t|�tdi|j�|r|jn|j�d|i��}|j�\}}|j
||||�}	t|	fi|��}
|j|
d�tj|d�S)a{
        Try importing the named module in a subinterpreter.

        The subinterpreter will be in the current process.
        The module will have already been imported in the main interpreter.
        Thus, for extension/builtin modules, the module definition will
        have been loaded already and cached globally.

        "check_singlephase_setting" determines whether or not
        the interpreter will be configured to check for modules
        that are not compatible with use in multiple interpreters.

        This should always return "okay" for all modules if the
        setting is False (with no override).
        �check_multi_interp_extensionsr�drT)r'r?�
RUN_KWARGS�ISOLATED�NOT_ISOLATEDr�r\rr�r�r�)rOrHrr]r^r_�kwargsr�r�r�r�s           r4�run_herezSubinterpImportTests.run_here�s���(	�4���
��o�o�
� (�t�}�}�d�.?�.?�
�+D�
���y�y�{���1��#�#�D�!�X�$>�@��+�6�<�V�<������a� ��w�w�q�#��r6��strictr_c�R�|j||||��}|j|d�y)N�r]r_�okay�rgr�)rOrHrrir_�outs      r4�check_compatible_herez*SubinterpImportTests.check_compatible_heres3���m�m�D�(�6<�%-����	
����g�&r6�r_c�x�|j||d|��}|j|jd�d|�d��y)NTrkr��ImportError: module �, does not support loading in subinterpreters)rgr�r�)rOrHrr_rns     r4�check_incompatible_herez,SubinterpImportTests.check_incompatible_heresJ���m�m�D�(�6:�%-����	
����J�J�w��"�4�&�(T�U�	
r6c�L�tdi|j�|r|jn|j�d|i��}t	j
dt
jd|�d|�d|�d|j|d��d|�d	���\}}}|j|d
�|j|d�y)
NrarWzH
            import _testcapi, sys
            assert (
                z0 in sys.builtin_module_names or
                z( not in sys.modules
            ), repr(zL)
            ret = _testcapi.run_in_subinterp_with_config(
                �sys.stdout.fileno()�,
                **�=,
            )
            assert ret == 0, ret
            r6rlrT)
r?rcrdrerr@r�r�r\r�)rOrHrir_rfrkrnr3s        r4�check_compatible_freshz+SubinterpImportTests.check_compatible_freshs���
�
��o�o�
� (�t�}�}�d�.?�.?�
�+1�
��
$�4�4�T�8�?�?�P��������H���#�#�D�*?�@�C�D��(�
�L�<����3��	
����c�"�����g�&r6c�l�tdi|j�|r|jn|j�ddi��}t	j
dt
jd|�d|�d|j|d��d|�d	�	��\}}}|j|d
�|j|jd�d|�d
��y)NraTrWz6
            import _testcapi, sys
            assert z not in sys.modules, zK
            ret = _testcapi.run_in_subinterp_with_config(
                rvrwrxr6r�rrrsrT)r?rcrdrerr@r�r�r\r�r�)rOrHr_rfrkrnr3s       r4�check_incompatible_freshz-SubinterpImportTests.check_incompatible_fresh5s����
��o�o�
� (�t�}�}�d�.?�.?�
�+/�
��
$�4�4�T�8�?�?�P��8�0���9��#�#�D�*?�@�C�D��(�
�L�<����3��	
����c�"�����J�J�w��"�4�&�(T�U�	
r6c��d}t|�|j|�d��5|j|d��ddd�|j|�d��5|j|d��ddd�y#1swY�:xYw#1swYyxYw)Nr��: not strictF�ri�: strict, not freshT)r;�subTestro�rOr.s  r4�test_builtin_compatz(SubinterpImportTests.test_builtin_compatMs{�������
�\�\�V�H�L�1�
2��&�&�v�e�&�<�3�
�\�\�V�H�$7�8�
9��&�&�v�d�&�;�:�
9�3�
2��
9�
9�s�A/�A;�/A8�;Bc��d}t|d��t|�jjdk7rt	j
|�d���|j
|�d��5|j|d��ddd�|j
|�d	��5|j|d��ddd�y#1swY�:xYw#1swYyxYw)
Nr�Tr7r$z is unexpectedly not frozenr}Fr~r)r@r'r)r9r+r,r�ror�s  r4�test_frozen_compatz'SubinterpImportTests.test_frozen_compatWs���$���v�D�)��f��&�&�-�-��9��#�#�v�h�.I�$J�K�K�
�\�\�V�H�L�1�
2��&�&�v�e�&�<�3�
�\�\�V�H�$7�8�
9��&�&�v�d�&�;�:�
9�3�
2��
9�
9�s�B+�B7�+B4�7Cc�~�d}t|�|j|�d��5|j|d��ddd�|j|�d��5|j|�ddd�|j|�d��5|j	|�ddd�y#1swY�fxYw#1swY�DxYw#1swYyxYw)NrYr}Fr~r�: strict, fresh)r>r�rortr{r�s  r4�!test_single_init_extension_compatz6SubinterpImportTests.test_single_init_extension_compatbs���#���&�!�
�\�\�V�H�L�1�
2��&�&�v�e�&�<�3�
�\�\�V�H�$7�8�
9��(�(��0�:�
�\�\�V�H�O�4�
5��)�)�&�1�6�
5�	3�
2��
9�
9��
5�
5�s#�B�B'�B3�B$�'B0�3B<z$test requires _testmultiphase modulec��d}t|�|j|�d��5|j|d��ddd�|j|�d��5|j|d��ddd�|j|�d��5|j|d��ddd�y#1swY�jxYw#1swY�FxYw#1swYyxYw)N�_testmultiphaser}Fr~rTr�)r>r�roryr�s  r4� test_multi_init_extension_compatz5SubinterpImportTests.test_multi_init_extension_compatms���#���&�!�
�\�\�V�H�L�1�
2��&�&�v�e�&�<�3�
�\�\�V�H�$7�8�
9��&�&�v�d�&�;�:�
�\�\�V�H�O�4�
5��'�'��t�'�<�6�
5�	3�
2��
9�
9��
5�
5��#�B�B+�B7�B(�+B4�7Cc��d}tj}t||�}tjj||�}tjj
|�}|j|�|tj|<t|�|j|�d��5|j||d��ddd�|j|�d��5|j||d��ddd�|j|�d��5|j||d��ddd�y#1swY�lxYw#1swY�GxYw#1swYyxYw)	N�_test_non_isolatedz
: isolatedTrpz: not isolatedFr}r~)r�r`rr�rG�spec_from_loader�module_from_specrrZr[r>r�rtro�rO�modnamerr*�specr.s      r4�-test_multi_init_extension_non_isolated_compatzBSubinterpImportTests.test_multi_init_extension_non_isolated_compatys��'��"�+�+��$�W�h�7���~�~�.�.�w��?�����0�0��6�����6�"�%����G���&�!�
�\�\�W�I�Z�0�
1��(�(��(�T�(�J�2�
�\�\�W�I�^�4�
5��(�(��(�U�(�K�6�
�\�\�W�I�\�2�
3��&�&�w���&�G�4�
3�	2�
1��
5�
5��
3�
3�s$�!D!�D-�D9�!D*�-D6�9Ec	���dD�]=}|j|��5tj}t||�}tj
j
||�}tj
j|�}|j|�|tj|<t|�|j|�d��5|j||d��ddd�|j|�d��5|j||dd��ddd�|j|�d	��5|j||dd��ddd�ddd���@y#1swY�yxYw#1swY�SxYw#1swY�-xYw#1swY��pxYw)
N)�_test_shared_gil_only�"_test_no_multiple_interpreter_slot)r�z: isolated, strictTrpz: not isolated, strictFrhz: not isolated, not strict)r�r�r`rr�rGr�r�rrZr[r>rtror�s      r4�4test_multi_init_extension_per_interpreter_gil_compatzISubinterpImportTests.test_multi_init_extension_per_interpreter_gil_compat�sW��>�G����g��.�*�3�3��,�W�h�?�� �~�~�6�6�w��G��"���8�8��>���"�"�6�*�'-����G�$�!�&�)��\�\�W�I�-?�"@�A��0�0��(�:>�1�@�B��\�\�W�I�-C�"D�E��.�.�w��6:�U�/�L�F��\�\�W�I�-G�"H�I��.�.���%�%�/�I�J�!/�.�>�B�A��F�E��J�I��!/�.�sT�BE)�8E�
E)�)E�?E)�E�1E)�E�
E)�E�E)�E&�"E)�)E3	c��d}t|�|j|�d��5|j|d��ddd�|j|�d��5|j|d��ddd�|j|�d��5|j|d��ddd�y#1swY�jxYw#1swY�FxYw#1swYyxYw)Nr�r}Fr~rTr��rBr�roryr�s  r4�test_python_compatz'SubinterpImportTests.test_python_compat�s������F�#�
�\�\�V�H�L�1�
2��&�&�v�e�&�<�3�
�\�\�V�H�$7�8�
9��&�&�v�d�&�;�:�
�\�\�V�H�O�4�
5��'�'��t�'�<�6�
5�	3�
2��
9�
9��
5�
5�r�c�n���d�t����fd�}��fd�}�jd�5|dd�ddd��jd�5|dd�ddd��jd	�5|dd
�ddd��jd�5|dd�ddd��jd
�5|dd�ddd��jd�5|dd
�ddd�y#1swY��xYw#1swY��xYw#1swY��xYw#1swY�txYw#1swY�]xYw#1swYyxYw)NrYc�R���j�||��}�j|d�y�N)r]r^rlrm��setting�overridernr.rOs   ��r4�check_compatiblez_SubinterpImportTests.test_singlephase_check_with_setting_and_override.<locals>.check_compatible�s1����-�-��*1�+3� ��C�

���S�'�*r6c�R���j�||��}�j|d�yr�)rgrKr�s   ��r4�check_incompatiblezaSubinterpImportTests.test_singlephase_check_with_setting_and_override.<locals>.check_incompatible�s1����-�-��*1�+3� ��C�

����W�-r6z(config: check enabled; override: enabledTrz+config: check enabled; override: use configrz)config: check enabled; override: disabledrz)config: check disabled; override: enabledFz,config: check disabled; override: use configz*config: check disabled; override: disabled)r>r�)rOr�r�r.s`  @r4�0test_singlephase_check_with_setting_and_overridezESubinterpImportTests.test_singlephase_check_with_setting_and_override�s����#���&�!�	+�	.��\�\�D�
E��t�Q�'�F�
�\�\�G�
H��t�Q�'�I�
�\�\�E�
F��T�2�&�G��\�\�E�
F��u�a�(�G�
�\�\�H�
I��U�A�&�J�
�\�\�F�
G��U�B�'�H�
G�F�
E��
H�
H��
F�
F��G�
F��
I�
I��
G�
G�sG�
C/�
C;�3
D�
D�9
D�
D+�/C8�;D�D�D�D(�+D4c��d}t|�|j|�d��5|j|dd��ddd�|j|�d��5|j|dd��ddd�y#1swY�;xYw#1swYyxYw)Nr�rTrhr�r�r�s  r4�test_isolated_configz)SubinterpImportTests.test_isolated_config�s}�����F�#�
�\�\�V�H�$7�8�
9��&�&�v�d�T�&�J�:�
�\�\�V�H�O�4�
5��'�'��t�d�'�K�6�
5�:�
9��
5�
5�s�A1�A=�1A:�=Bc�~�tjd�}tj�}|j	tj
�5tj||�ddd�|j	tj
�5tj||�ddd�y#1swY�HxYw#1swYyxYw)NzU
            import _testsinglephase
            print(_testsinglephase)
            )r�r�rk�creater��RunFailedErrorr�)rOr�r�s   r4�test_disallowed_reimportz-SubinterpImportTests.test_disallowed_reimport�s������"���!�'�'�)��
�
�
�}�;�;�
<��$�$�X�v�6�=�
�
�
�}�;�;�
<��$�$�X�v�6�=�
<�=�
<��
<�
<�s�	B'�B3�'B0�3B<)NNr=)"r�r�r�r?rcrd�itemsrer+r�r�r�r�r\rgrortryr{r�r
r�rir�rgr�r�r�r�r�r�r�rlr�)�.0r��vs000r4rNrN�s�������"�	�J���
��H�*2���)9�:�)9���A�A�1�u�H�)9�:�L��L����X�����V�,�.B�C��D��#�J"�+0�,0��"�H
'�%*�',�
'�
�u�
�6;�U�'�2:?�
�0<��<��<��2��2��X�_�_�_��,�.T�U�	=�V�	=��X�_�_�_��,�.T�U�H�V�H�&�X�_�_�_��,�.T�U�I�V�I�:=�� (�� (�DL���
7���
7��i	;s�DrNc���eZdZe�fd��Zejejd�j�zZe�fd��Z
�xZS)�TestSinglePhaseSnapshotc���t�|�|�}|jdd�|_|j	�|_t
|j
�|_|j�|_t|d�r|j�|_|S)Nrr��initialized_count)�superr{�sum�summed�look_up_self�lookeduprp�lookedup_id�state_initializedr�r��
init_count)ryrzrO�	__class__s   �r4r{z#TestSinglePhaseSnapshot.from_module�su����w�"�3�'���g�g�a��m����(�(�*��
��d�m�m�,���!$�!6�!6�!8����3�+�,�!�3�3�5�D�O��r6a�
        snapshot['module'].update(dict(
            int_const=mod.int_const,
            str_const=mod.str_const,
            _module_initialized=mod._module_initialized,
        ))
        snapshot.update(dict(
            summed=mod.sum(1, 2),
            lookedup_id=id(mod.look_up_self()),
            state_initialized=mod.state_initialized(),
            init_count=mod.initialized_count(),
            has_spam=hasattr(mod, 'spam'),
            spam=getattr(mod, 'spam', None),
        ))
        c�F��t�|�|�}|js|`|`|Sr=)r�r��has_spamr:)ryr�rOr�s   �r4r�zTestSinglePhaseSnapshot.parses'����w�}�T�"���}�}��	��M��r6)r�r�r�r�r{rnr�r�r��rstripr��
__classcell__)r�s@r4r�r��sW�������!�,�,��x���@�0
��V�X��K� ���r6r�c��eZdZdZed��Zed��Zd�Zed��Zd�Z	d�Z
d�Zd	�Zd
�Z
d ddd
�d�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zed��Zed��ed���Zed��Zy)!�SinglephaseInitTestsrYc��tjj|j�}ddlm}|j|_t|j�|_
|j|usJ�|j�y)Nr)r)r�rGr��NAME�importlib.machineryrr9�FILEr(r*�LOADER�clean_up)ryr�rs   r4�
setUpClasszSinglephaseInitTests.setUpClasssV���~�~�'�'����1��;��;�;����$�+�+�&��
��z�z�0�0�0�0�	���r6c��t�yr=rd)rys r4�
tearDownClassz"SinglephaseInitTests.tearDownClass%s�� �"r6c�$�|j�yr=)r�r�s r4r�zSinglephaseInitTests.tearDown)s���
�
�r6c�f�|j}|j}|tjvrqt	tj|d�rCtj|j
|k(sJ�tj|j
�tj|=tj||�y)Nr])	r�r�rZr[r�r`r]r^r_)ryrHrs   r4r�zSinglephaseInitTests.clean_up-s����x�x���8�8���3�;�;���s�{�{�4�(�*:�;��{�{�4�(�1�1�X�=�=�=����D�!�0�0�2����D�!��)�)�$��9r6c�6�����fd�}�j|�y)Nc�F��tj��j�yr=)r^r_r�)rHrOs��r4r�z9SinglephaseInitTests.add_module_cleanup.<locals>.clean_up=s����-�-�d�D�I�I�>r6)rq)rOrHr�s`` r4�add_module_cleanupz'SinglephaseInitTests.add_module_cleanup<s���	?�	
����!r6c��ddlm}|j||�}tjj|||��}||�S)z+
        Load an extension module.
        r)�_load)r*)�importlib._bootstrapr�r�r�rG�spec_from_file_location)rOrHr�r�r*r�s      r4�
_load_dynamicz"SinglephaseInitTests._load_dynamicBsD��
	/����T�4�(���~�~�5�5�d�D�=C�6�E���T�{�r6c�0�	|j}||vsJ�|j||j�}|j	||j��|||<t
j||tj|���S#t$rix}|_Y��wxYw�N�rHr.�snapshot)
�already_loadedrjr�r�r��valuesrvrwr�r{)rOrHr�rzs    r4rzSinglephaseInitTests.loadPs���	6�!�0�0�N��>�)�)�)�� � ��t�y�y�1������n�3�3�5�6�"��t���$�$���,�8�8��=�
�	
��
�	6�35�5�N�T�0�	6�s�B�B�Bc���tj||usJ�|j|jk(sJ�|j||j�}tj||tj|���Sr�)	rZr[rxr�r�rvrwr�r{)rOrHrz�reloadeds    r4�re_loadzSinglephaseInitTests.re_load_sl���{�{�4� �C�'�'�'��|�|�s�|�|�+�+�+��%�%�d�D�I�I�6���$�$���,�8�8��B�
�	
r6c����tjd���tj�tjd����fd�}�j|��S)NFrpzI
            import sys
            import _testinternalcapi
            c
���tj�tjd�j�d�j
�d���tj��y)Nz
                name = z�
                if name in sys.modules:
                    sys.modules.pop(name)._clear_globals()
                _testinternalcapi.clear_extension(name, rX)rkr�r�r�r�r��destroy)r�rOs��r4r�z9SinglephaseInitTests.add_subinterpreter.<locals>.clean_upqsY����$�$�X�x���D��	�	�}�%9�:>���
�F�	@�0�
�
�!�!�(�+r6)rkr�r�r�r�rq)rOr�r�s` @r4�add_subinterpreterz'SinglephaseInitTests.add_subinterpreterksK��� �'�'��7��� � ��8�?�?�<�,�	�	,�	
����!��r6NF�r~rc��|j}|r|�dnd}d|�d|j�d�}	|j}tj|||d||��}	tj|d|	��S#t$rct	j
�x\}}x}|_|j
tj|�|j
tj|�Y��wxYw)	Nzimport _testinternalcapir�z
                z^
                mod._clear_globals()
                _testinternalcapi.clear_extension(name, rXT)r�r}r~rr�)r�r��_piperjr�r�rqr�r�r�rvrw)
rOr�r~rrH�import_r�r�r�r�s
          r4�import_in_subinterpz(SinglephaseInitTests.import_in_subinterp|s����y�y���4<�4D�0�"�G���	�9�9=���
�F��K�	)��:�:�D�+�9�9�����!�#�
:�
���$�$����
�	
���	)�')�w�w�y�0�D�A�q�0�4�$�*��O�O�B�H�H�a�(��O�O�B�H�H�a�(�	)�s�A(�(A)C�Cc��d}|j}|sd}|jj}|j|jj|j�|j|j
|j�|j|jj|j�|s)|jt|jt��|j|jd�|j|jd�|j|jt �|j#|jd�|j}|j|j$d�|j&�<|j|j&t �|j#|j&d�|rw|j|j(|j*�|j|j,|j*�|j/t0�5|j2ddd�y|j5|j6|�|j5|j8|�y#1swYyxYw)NFTi�zsomething differentrr)r.r�r�r)rHr`r�r9r$�
issubclass�errorr-�	int_const�	str_const�assertIsInstance�_module_initialized�float�
assertGreaterr�r�r�rprtr�rjr:r#r�rs)rO�loadedr_rz�snaps     r4�check_commonz!SinglephaseInitTests.check_common�s������m�m����H��/�/�(�(�C�������*�*�F�K�K�8�������t�y�y�1�������,�,�d�i�i�8���O�O�J�s�y�y�)�<�=��������-�������(=�>����c�5�5�u�=����3�2�2�A�6�����������a�(��!�!�-��!�!�$�"8�"8�%�@����t�5�5�q�9��
���T�-�-�t�w�w�7����T�^�^�T�W�W�5��"�"�>�2��	�	�3�2�
�M�M�$�-�-��-��M�M�$�+�+�s�+�	3�2�s�!
I0�0I9c���|j|jj|j�|j	|j
j|j�yr=)r�r.r�rHr#r�r��rOr�s  r4�check_directz!SinglephaseInitTests.check_direct�s<��������/�/����=��
�
�f�o�o�.�.��
�
�>r6c��||jusJ�|j|jk7sJ�|j|jj|j�|j	|j
j|j�yr=)r.r�rHrKr#r�r�)rOr��origs   r4�check_indirectz#SinglephaseInitTests.check_indirect�sd���6�=�=�(�(�(��}�}����+�+�+����F�M�M�2�2�F�K�K�@��
�
�f�o�o�.�.��
�
�>r6c��|j}|j|jd�|j|jt
�|j
|jd�|j|j|�yr�)r��assertIsNotr�r�r��intr�r�)rOr��expected_init_countr�s    r4�check_basicz SinglephaseInitTests.check_basic�s`����������/�/��6����d�o�o�s�3����4�?�?�A�.�������*=�>r6c��yr=rTr�s  r4�check_with_reinitz&SinglephaseInitTests.check_with_reinit�s��	
r6c��|j}|j|jd�|j|jj|j
�y)zU
        The module had not been loaded before (at least since fully reset).
        rN)r�r�r�r.r�r�)rOr�r�s   r4�check_freshz SinglephaseInitTests.check_fresh�sH������
	
������!�,�	
������8�8��/�/�	1r6c�b�|j}|j|j|jj�|j|j|jj�|j|j|jjdz�|j|j
j|j�|j|j|jj�|j|j|jj�y)zp
        The module had been loaded before and then reset
        (but the module global state wasn't).
        rN�r�rKrpr�r�r.r�r�)rOr�r6�prevr�s     r4�check_semi_freshz%SinglephaseInitTests.check_semi_fresh�s���
����
	
���D�G�G�T�]�]�%5�%5�6����D�G�G�T�]�]�%5�%5�6�������$�-�-�*B�*B�Q�*F�G�	
������8�8��/�/�	1����D�2�2� �M�M�;�;�	=����D�2�2� �M�M�;�;�	=r6c��|j}|j|j|jj�|j|j|jj�|j|j
j|j�|j|j|jj�y)zD
        The module had been loaded before and never reset.
        Nr)rOr�r6r�s    r4�check_copiedz!SinglephaseInitTests.check_copied	s�������
	
���D�G�G�T�]�]�%5�%5�6�������$�-�-�*B�*B�C�	
������8�8��/�/�	1�����/�/����8�8�	:r6c�F�|j|j�}|j}|j�}|j�|j�}|j
�}|j
|d�|j|d�|j|d�y)Nrr)rr�r.r�r]r�r�r�)rOr�rY�init_before�
init_afterr�s      r4�test_cleared_globalsz)SinglephaseInitTests.test_cleared_globals	s������4�9�9�%��!�=�=��8�&�8�8�:��'��'�'�)�7�%�7�7�9�
�7�%�7�7�9�
����;��*�����Q�'�����R�(r6c��d|_|j}d}|j|�5|j|�}|j	|�|j|�|j
||�ddd�j}|j�d�}|j|�|dz
}|j|�5|j|�}|j	|�|j||�|j
||�|j|j�|j�|j|j�|�ddd�|j}|j�d�}|j|�|dz
}|j|�5|j|�}|j	|�|j|�|j
||�|j|j�|�|j|j�|�ddd�|j�d�}|j|�|j|�5|j|�}|j	|�|j|jjd�|j|�|j!|�|j|j�|�|j|j�|�ddd�|j�d�}|j|�|j|�5|j|�}|j#|jj$�|j	|�|j'|jjd�|j|�|j!|�|j|j�|�|j|j�|�ddd�y#1swY���xYw#1swY���xYw#1swY��xYw#1swY��;xYw#1swYyxYw)Nr�_basic_wrapper�_basic_copy�_with_reinit�_with_state)�maxDiffr�r�rr�r�r�r.r�r�r#r�r�r�r�r�r�rq�_clear_module_stater�)rOrHr�r��basic�basic_lookedups      r4�
test_variantsz"SinglephaseInitTests.test_variants'	s�������y�y����
�\�\�$�
��Y�Y�t�_�F����f�%����f�%����V�%8�9� ��
�
���)�)��N�+������%��q� ��
�\�\�$�
��Y�Y�t�_�F����f�%������.����V�%8�9�
�M�M�%�,�,�.��
�
�>����U�4�4�6�8K�L� � �����)�)��K�(������%��q� ��
�\�\�$�
��Y�Y�t�_�F����f�%����f�%����V�%8�9�
�M�M�%�,�,�.��?����U�4�4�6�8K�L� ��)�)��L�)������%�
�\�\�$�
��Y�Y�t�_�F����f�%��M�M�&�/�/�;�;�T�B����f�%��"�"�6�*�
�M�M�%�,�,�.��?����U�4�4�6�8K�L� ��)�)��K�(������%�
�\�\�$�
��Y�Y�t�_�F��O�O�F�M�M�=�=�>����f�%����V�_�_�>�>��E����f�%��"�"�6�*�
�M�M�%�,�,�.��?����U�4�4�6�8K�L� �
� �
�� �
��& �
�� �
��  �
�s@�AP�7BP�BP(�B+P5�5CQ�P�P%�(P2�5P?�Qc��d|_|j|j�d�|j�d�fD�]�}|j|�|j|�5|j	|�}|j||j�}|j|�|j|�|jt|jj�|jj�|j|jjj|jj�|j|jjj|j�|j|jj |jjj �|j#|j|j�|j#|jj|jj�|j#|jj$|jj$�|j|jj&|jj&�|j|jj(|jj(�|j#|jj*|j�ddd����y#1swY���xYw)Nrr
)rr�r�r�rr�r.r�r�rprxr�rrrqr)rHr�r#r�r�r�rs)rOrHr�r�s    r4�test_basic_reloadedz(SinglephaseInitTests.test_basic_reloaded{	s-�����
�I�I��y�y�k��(��y�y�k��%�
�D�

�#�#�D�)����d�#����4����<�<��f�m�m�<���!�!�&�)��!�!�(�+�� � ��F�M�M�$:�$:�!;�!'���!6�!6�8�� � ����!3�!3�!<�!<�!'���!7�!7�9�� � ����!9�!9�!>�!>��
�
�N�� � ����!9�!9�!)�!2�!2�!5�!5�!>�!>�@��
�
�h�o�o�v�}�}�=��
�
�h�o�o�6�6��
�
�8N�8N�O��
�
�h�/�/�8�8�$�o�o�6�6�8�� � ��!2�!2�!D�!D�!'���!B�!B�D�� � ��!2�!2�!=�!=�!'���!;�!;�=��
�
�h�/�/�6�6����H�;$�#�

�$�#�s
�JK6�6L	c���d|_|j|j�}|j�d�df|j�d�dffD�]\}}|j|�|j	||��5|j|�}|r%|j|jj�|j||j�}|r%|j|jj�|j|�|j|�|jt|jj�|jj�|j|jjj|jj�|j|jj j"|j"�|j|jj$|jjj$�|j'|j|j�|j)|jj|jj�|j+|jj,|j�|jj.�'|j+|jj.d�n:|j1|jj.|jj.�|j+|jj2|j�ddd���y#1swY��xYw)NrFrT)rH�	has_state)rrr�r�r�rqr.rr�r�r�rprxr�rrrqr)rHr�r�rKr#r�r�r�rs)rOrrHrr�r�s      r4�test_with_reinit_reloadedz.SinglephaseInitTests.test_with_reinit_reloaded�	sz������	�	�$�)�)�$���	�	�{�,�
'��/��	�	�{�+�
&��-� 
�O�D�)�
�#�#�D�)����4�9��=����4�����O�O�F�M�M�$E�$E�F��<�<��f�m�m�<����O�O�H�O�O�$G�$G�H��!�!�&�)��!�!�(�+�� � ��F�M�M�$:�$:�!;�!'���!6�!6�8�� � ����!3�!3�!<�!<�!'���!7�!7�9�� � ����!9�!9�!>�!>��
�
�N�� � ����!9�!9�!)�!2�!2�!5�!5�!>�!>�@�� � ����&�-�-�@��#�#�H�O�O�$<�$<�$*�M�M�$:�$:�<��
�
�h�/�/�8�8�(�/�/�J��?�?�4�4�<��M�M�(�"3�"3�"E�"E�t�L��&�&�x�'8�'8�'J�'J�'-���'H�'H�J��
�
�h�/�/�6�6����H�A>�=� 
�
>�=�s
�0KM�M 	c��|j|j�}|j}d|_|j	|�|j|�|j
�}|j
�}|j�}|j	|�|j||�|j|�}|j	|�|j||�|j|�}|j	|�|j||�y)Nz&spam, spam, spam, spam, eggs, and spam)	rr�r.r:r�rr�r�r)rO�main_loadedrY�	interpid1�	interpid2r�s      r4�.test_basic_multiple_interpreters_main_no_resetzCSinglephaseInitTests.test_basic_multiple_interpreters_main_no_reset�	s����i�i��	�	�*��&�-�-�� H������+�&�����%��+�+�-�	��+�+�-�	��)�)�+�����&�!����&�+�.��)�)�)�4�����&�!����&�+�.��)�)�)�4�����&�!����&�+�.r6zArerun not possible; module state is never cleared (see gh-102251))rRc��ttd�rtjd��|j	�}|j	�}|j|j�}|jj�tj|j|j�|jd��}|j|�|j|�|j|�}|j|�|j|||�|j|�}|j|�|j!||�y)N�
getobjectszcrashes on Py_TRACE_REFS buildsz�
            # Attrs set after loading are not in m_copy.
            mod.spam = 'spam, spam, mash, spam, eggs, and spam'
        )r~)r�rZr+r,r�rr�r.r]r^r_r�r�r�rrr)rOrr�loaded_mainr6�loaded_interp1�loaded_interp2s       r4�1test_basic_multiple_interpreters_deleted_no_resetzFSinglephaseInitTests.test_basic_multiple_interpreters_deleted_no_reset
s��
�3��%��#�#�$E�F�F��+�+�-�	��+�+�-�	��i�i��	�	�*�����)�)�+��)�)�$�)�)�T�Y�Y�?��'�'�4�'�
��	
���$��������1�1�)�<�����.�)����n�k�4�@��1�1�)�<�����.�)����.�.�9r6c��|j�}|j�}|jdd��}|j|�|j|�|j|d��}|j|�|j|�|j|d��}|j|�|j|�y)Nz�
            # Attrs set after loading are not in m_copy.
            mod.spam = 'spam, spam, mash, spam, eggs, and spam'
            Tr�)r)r�r�r�r)rOrrr�s    r4�+test_basic_multiple_interpreters_reset_eachz@SinglephaseInitTests.test_basic_multiple_interpreters_reset_eachh
s����+�+�-�	��+�+�-�	��)�)���*�
��	
���&�!����� ��)�)�)��)�F�����&�!����� ��)�)�)��)�F�����&�!����� r6r=) r�r�r�r�r�r�r�r�r�r�r�rr�r�r�r�r�r�r�r�rrrr
rrrrlrrVr$r&rTr6r4r�r�s���D������#��#���	:��	:�"��

�
��""
�'+�(-�"
�L!,�F?�
?�?�
�

1�=�,:�,)�RM�h(I�T,I�h�:/��:/�F�X�Y��@:��Z�@:�R�0!��0!r6r��__main__)`rjrLr�r��importlib.utilr��importlib._bootstrap_externalrr�rrrrrr�rr�r�rNr�rZr�r�r{rvr+rr^r�r"r	r
rrr
rrrr�test.support.import_helperrrrrrrr�test.support.os_helperrrrrrr�test.test_importlib.utilrr rYr�r��_xxsubinterpretersrkr�rg�dont_write_bytecoder�r5r;r>r@rBrJrVrarirlrwrn�TestCaser�r�r�rr6r`rmr�r�r�r�rrNr�r�r��mainrTr6r4�<module>r1s��������9����	��
�
���
���������"�=�=�=� � � �4�4�&�)�,�������.�
.�h�o�o����4�6��
�6%*�A�',�7�$(�?�).�4���&��*:� �
J�=�`(�U�*�*�`(�Fa)�(�#�#�a)�H�V/�(�+�+�V/��V/�rVM��)�)�VM�r3 ��"�"�3 �l^:�(�+�+�^:�B(�8�#4�#4�(�(_!�8�$�$�_!�D+3�H�$5�$5�+3�\�<�h�/�/�<��<�@�6��*�*�6��6�Bm9�8�,�,�m9�`Y�(�+�+�Y�xK7�8�,�,�K7�\
#�n�#�L�C
!�8�,�,�C
!��C
!�Z�z���H�M�M�O���sS���������O������M��s6�:J�?J�J"�J�J�J�J�"J-�,J-