Your IP : 216.73.216.196


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

�

�#�jx3����ddlZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZe	jd�Z
dZGd�dej�Zedk(rej$�yy)	�N)�	os_helper)�
import_helper)�check_warnings�	_testcapic��eZdZd�Zd�Zd�Zd�Zd�Zd�Zdd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zdd�Zd�Zd�Zy)�ImportTestsc��tj�}|j|tj	t
jjd��y)N�little)r�PyImport_GetMagicNumber�assertEqual�int�
from_bytes�	importlib�util�MAGIC_NUMBER)�self�magics  �A/opt/alt/python312/lib64/python3.12/test/test_capi/test_import.py�test_getmagicnumberzImportTests.test_getmagicnumbers9���1�1�3���������	���(C�(C�X�N�	P�c��tj�}|j|tjj
�y�N)r�PyImport_GetMagicTagr�sys�implementation�	cache_tag)r�tags  r�test_getmagictagzImportTests.test_getmagictags,���,�,�.������c�0�0�:�:�;rc�l�tj�}|j|tj�yr)r�PyImport_GetModuleDict�assertIsr�modules)rr"s  r�test_getmoduledictzImportTests.test_getmoduledicts"���2�2�4���
�
�g�s�{�{�+rc�:�dD]�}|j|��5|j|tj�tj|}||�}|j	|t
j�|j||�ddd���y#1swY��xYw)N)�osr�test�unittest��name)�subTest�assertInrr"�assertIsInstance�types�
ModuleTyper!)r�
import_moduler)�
old_module�modules     r�check_import_loaded_modulez&ImportTests.check_import_loaded_modulesw��5�D����4��(��
�
�d�C�K�K�0� �[�[��.�
�&�t�,���%�%�f�e�.>�.>�?��
�
�f�j�1�)�(�6�(�(�s�A.B�B	c��ttj�}	dD]�}|j|��5tjj	|d�||�}|j|tj�|j|tj|�|j|j|�ddd���	tjj�tjj|�y#1swY��xYw#tjj�tjj|�wxYw)N)�colorsys�mathr()
�dictrr"r*�popr,r-r.r!r�__name__�clear�update)rr/�old_modulesr)r1s     r�check_import_fresh_modulez%ImportTests.check_import_fresh_module(s����3�;�;�'��
	,�,���\�\�t�\�,��K�K�O�O�D�$�/�*�4�0�F��)�)�&�%�2B�2B�C��M�M�&�#�+�+�d�*;�<��$�$�V�_�_�d�;�-�,�-�
�K�K�����K�K���{�+�-�,��
�K�K�����K�K���{�+�s#�D�BD�:
D�D	�D�?Ec�p�tj}|j|�d}|j|tj
�|j
||�t�|j
|d�t�|j
|t��t�|jt|g�y�N�nonexistent�)r�PyImport_GetModuler2�assertNotInrr"r!�KeyError�object�assertRaises�	TypeError)r�	getmoduler?s   r�test_getmodulezImportTests.test_getmodule6s����0�0�	��'�'�	�2�#������c�k�k�2��
�
�i��,�h�7��
�
�i��m�X�.��
�
�i���)�8�4����)�Y��3rc�L�dg}|r|jd�|D]�}|j|��5|j|tj�	||�}|j|tj�|j|j|�|j|tj|�tjj|d�	ddd���|j|�y#tjj|d�wxYw#1swY��
xYw)Nr?��r()
�appendr*rBrr"r,r-r.rr8r!r7r2)r�
add_module�
accept_nonstr�namesr)r1s      r�check_addmodulezImportTests.check_addmoduleDs��������L�L��!��D����4��(�� � ��s�{�{�3�0�'��-�F��)�)�&�%�2B�2B�C��$�$�V�_�_�d�;��M�M�&�#�+�+�d�*;�<��K�K�O�O�D�$�/�)�(��	
�'�'�
�3���K�K�O�O�D�$�/��)�(�s$�!D�A'C4�7 D�4"D�D�D#	c�x�tj}|j|d��|jt|g�y)NT)rM)r�PyImport_AddModuleObjectrOrErF)r�addmoduleobjects  r�test_addmoduleobjectz ImportTests.test_addmoduleobjectWs2��#�<�<�����_�D��A����)�_�b�9rc�t�tj}|j|�|jt|d�y�NrJ)r�PyImport_AddModulerOrE�UnicodeDecodeError)r�	addmodules  r�test_addmodulezImportTests.test_addmodule_s.���0�0�	����Y�'����,�i��Arc��|j|�|j|�|jt|d�|jt|d�yr>)r2r<rE�ModuleNotFoundError�
ValueError)rr/s  r�check_import_funczImportTests.check_import_funcgsC���'�'�
�6��&�&�}�5����-�}�m�L����*�m�R�8rc��tj}|j|�|jt|d�|jt
|t�y)N�os)r�PyImport_Importr]rErF�SystemError�NULL)r�import_s  r�test_importzImportTests.test_importms?���+�+�����w�'����)�W�e�4����+�w��5rc�t�tj}|j|�|jt|d�yrU)r�PyImport_ImportModuler]rErW)r�importmodules  r�test_importmodulezImportTests.test_importmoduleus.�� �6�6�����|�,����,�l�G�Drc�t�tj}|j|�|jt|d�yrU)r�PyImport_ImportModuleNoBlockr]rErW)r�importmodulenoblocks  r�test_importmodulenoblockz$ImportTests.test_importmodulenoblock}s1��'�D�D�����2�3����,�.A�7�Krc��tjjd�}	|j|d�d�|j|d�d�|tjd<|j|d�d�|j|d�d�|j|d�d�y#|tjd<wxYw)N�	zipimport�rrr?r@)rr"r7r)r�import_frozen_module�
old_zipimports   r�check_frozen_importzImportTests.check_frozen_import�s���������4�
�	5����1�+�>��B�
���1�+�>��B�'4�C�K�K��$�	
���-�e�4�a�8����-�m�<�a�@����-�b�1�1�5��(5�C�K�K��$�s�0B-�-Cc�t�tj}|j|�|jt|d�yrU)r�PyImport_ImportFrozenModulerrrErW)r�importfrozenmodules  r�test_importfrozenmodulez#ImportTests.test_importfrozenmodule�s1��&�B�B��� � �!3�4����,�.@�'�Jrc��tj}|j|�|j|d�d�|j|t�d�y)Ns	zipimportr)r�!PyImport_ImportFrozenModuleObjectrrrrb)r�importfrozenmoduleobjects  r�test_importfrozenmoduleobjectz)ImportTests.test_importfrozenmoduleobject�sI��#,�#N�#N� �� � �!9�:����1�,�?��C����1�$�7��;rc�2��tj�|j�fd��|jt�dt
t
t
�|jt�dt
t
t
�|jt�dt
t
t
�y)Nc�2���|ttt�Sr�rb)r)�importmoduleexs �r�<lambda>z1ImportTests.test_importmoduleex.<locals>.<lambda>�s���N�4��t�T�,Rrr?r@rJ)r�PyImport_ImportModuleExr]rEr[rbr\rW)rr~s @r�test_importmoduleexzImportTests.test_importmoduleex�sj���"�:�:�����R�S����-�~�}�d�TX�Z^�_����*�n�b�$��d�K����,�n�g�t�T�SW�Xrc
���|j�fd��|jt�dtttd�|jt�dtttd�t
rz|j
�dt�ttd�tjd�|j
�dt�ttd	�tjd
�|jt�dtttd�|jt�5|jt�dittd�ddd�|jt�dgttd�y#1swY�-xYw)
Nc�4���|tttd�S)Nrr})r)�importmodulelevels �rrz5ImportTests.check_importmodulelevel.<locals>.<lambda>�s���,=�d�D�$�PT�VW�,Xrr?rr@rdroztest.test_capi.test_import�	test_capi�ztest.test_capir%���)r]rEr[rbr\�__package__r!�globalsrr"�assertWarns�
ImportWarningrCrF�rr�s `r�check_importmodulelevelz#ImportTests.check_importmodulelevel�s������X�Y����-�/@�-�QU�W[�]a�cd�e����*�&7��T�4��q�Q���M�M�+�M�7�9�d�D�RS�T��+�+�&B�C�
E��M�M�+�K���D�$�PQ�R��+�+�&6�7�
9����*�&7��t�T�4�QS�T�
�
�
�m�
,����h�(9�=�"�d�TX�Z[�\�-����)�%6�
�r�4�QU�WX�Y�-�
,�s� $E0�0E9c	��tj}|j|�|jt|dt
t
t
d�y)NrJr)r�PyImport_ImportModuleLevelr�rErWrbr�s  r�test_importmodulelevelz"ImportTests.test_importmodulelevel�s<��%�@�@���$�$�%6�7����,�.?��$�PT�VZ�\]�^rc	���tj}|j|�|jt|dt
t
t
d�|jt|t
t
t
t
d�y)Nr_r)r� PyImport_ImportModuleLevelObjectr�rErFrbr\r�s  r�test_importmodulelevelobjectz(ImportTests.test_importmodulelevelobject�sU��%�F�F���$�$�%6�7����)�%6��t�T�4�QR�S����*�&7��t�T�4�QR�Src���d}	|j|tj�tj	|�}|jt
|d��tddd�}|||g|���}|j||�|j|jd�tjj|d�|jjS#tjj|d�wxYw)N�test_import_executecode�attr�attr = 1�<test>�execro)rBrr"rrV�assertFalse�hasattr�compiler!rr�r7�__spec__�origin)r�execute_code�argsr)r1�code�module2s       r�check_executecodemodulez#ImportTests.check_executecodemodule�s���(��	(����T�3�;�;�/��1�1�$�7�F����W�V�V�4�5��:�x��8�D�"�4��5��5�G��M�M�'�6�*�
���V�[�[�!�,��K�K�O�O�D�$�'����%�%�%��
�K�K�O�O�D�$�'�s�BC�"C1c��tj}|j|�tddd�}|j	t
|d|�y�Nr�r�r�rJ)r�PyImport_ExecCodeModuler�r�rErW)r�execcodemoduler�s   r�test_executecodemodulez"ImportTests.test_executecodemodule�s>��"�:�:���$�$�^�4��z�8�V�4�����,�n�g�t�Lrc��tj}|j|t�d}|j||�}|j	|t
jjtj|���tj}|rT|j||�}|j	|t
jjtj|���tddd�}|jt|d|t�y)Nspathnamer�r�r�rJ)r�PyImport_ExecCodeModuleExr�rbrr%�path�abspath�fsdecoder�TESTFN_UNDECODABLEr�rErW)r�execcodemoduleex�pathnamer�r�s     r�test_executecodemoduleexz$ImportTests.test_executecodemoduleex�s���$�>�>��	
�$�$�%5�t�<����-�-�.>��I��������������X�1F�!G�H��/�/����1�1�2B�H�M�F����V�R�W�W�_�_�R�[�[��5J�%K�L��z�8�V�4�����,�.>���t�Trc��|j|tt�d}|j||t�}|j|tjjtj|���|j|t|�}|sB|j|tjjtj|���tj}|r�|rtj|�}|j||t�}|j|tjjtj|���|j|t|�tjjt�}tjj|�}|j|t|�}|s|j||�yy)Nr�)r�rbrr%r�r�r�rr�rr�cache_from_source�__file__�source_from_cache)r�execute_code_funcrDr�r��pyc_filename�py_filenames       r�check_executecode_pathnamesz'ImportTests.check_executecode_pathnamessY��	
�$�$�%6��d�C����-�-�.?��4�P��������������X�1F�!G�H��-�-�.?��x�P������V�R�W�W�_�_�R�[�[��5J�%K�L��/�/�����;�;�x�0���1�1�2C�X�t�T�F����V�R�W�W�_�_�R�[�[��5J�%K�L��(�(�):�D�(�K�!�~�~�7�7��A���n�n�6�6�|�D���-�-�.?��|�T������V�[�1�rc��tj}|j|�tddd�}|j	t
|d|tt�yr�)r�$PyImport_ExecCodeModuleWithPathnamesr�r�rErWrb�rr�r�s   r�#test_executecodemodulewithpathnamesz/ImportTests.test_executecodemodulewithpathnamessG��%�J�J���(�(�):�;��z�8�V�4�����,�.?��$�PT�VZ�[rc��tj}|j|d��tddd�}|j	t
|g|tt�y)NT)rDr�r�r�)r�PyImport_ExecCodeModuleObjectr�r�rErFrbr�s   r�test_executecodemoduleobjectz(ImportTests.test_executecodemoduleobject(sI��%�C�C���(�(�):�4�(�H��z�8�V�4�����)�%6��D�$��MrN)F)r8�
__module__�__qualname__rrr#r2r<rHrOrSrYr]rdrhrlrrrvrzr�r�r�r�r�r�r�r�r�r��rrrrs���P�<�
,�
2�,�4�4�&:�B�9�6�E�L�6�"K�<�Y�Z� _�T�&�&M�U�,2�8\�Nrr�__main__)�importlib.utilr�os.pathr%rr-r'�test.supportrr�test.support.warnings_helperrr/rrb�TestCaserr8�mainr�rr�<module>r�se����
���"�&�7�'�M�'�'��4�	���`N�(�#�#�`N�T	�z���H�M�M�O�r