
    daf
                         d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlmZ d dl	m
Z
  G d dej                        Zedk(  r ej                          yy)    N)cache_from_source)create_empty_filec                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)
TestImportc                 ^   d| _         | j                   t        j                  v rS| xj                   t        j                  t
        j                        z  c_         | j                   t        j                  v rS| j                   dz   | _        t        j                  j                  | g|i | y )NPACKAGE_z.foo)package_namesysmodulesrandomchoicestringascii_lettersmodule_nameunittestTestCase__init__)selfargskws      >/root/Python-3.12.4/Lib/test/test_importlib/test_pkg_import.pyr   zTestImport.__init__   s    &3;;.v/C/C!DD 3;;.,,v5""45$5"5    c                     | j                   | j                  fD ]&  }|t        j                  v st        j                  |= ( y )N)r	   r   r
   r   )r   r   s     r   remove_moduleszTestImport.remove_modules   s:     --t/?/?@ 	-Kckk)KK,	-r   c                    t        j                         | _        t        j                  j                  | j                         t        j                  j                  | j                  | j                        | _	        t        j                  | j                         t        t        j                  j                  | j                  d             t        j                  j                  | j                  d      | _        y )Nz__init__.pyzfoo.py)tempfilemkdtemptest_dirr
   pathappendosjoinr	   package_dirmkdirr   module_pathr   s    r   setUpzTestImport.setUp   s     ((*&77<<(,(9(9;
!!""'',,t'7'7GH77<<(8(8(Cr   c                 &   t        j                  | j                         | j                  t        j
                  j                  | j                        d       t        j
                  j                  | j                         | j                          y )Nr   )	shutilrmtreer   assertNotEqualr
   r   countremover   r&   s    r   tearDownzTestImport.tearDown#   sS    dmm$CHHNN4==91=&r   c                    t        | j                        }t        j                  j	                  |      rt        j
                  |       t        | j                  dd      5 }|j                  |       d d d        y # 1 sw Y   y xY w)Nwzutf-8)encoding)r   r%   r!   r   existsr-   openwrite)r   contentscompiled_pathfs       r   rewrite_filezTestImport.rewrite_file)   sc    )$*:*:;77>>-(IIm$$""C': 	aGGH	 	 	s   "A==Bc                    | j                  d       t        | j                         t        d      # t        $ r Y nw xY w| j                  | j                  t        j                         | j                  t        t        j                  | j                     d             d}|t        t              v r8|t        j                  t        j                         z  }|t        t              v r8| j                  |       t        | j                         t        d      # t"        $ r Y nw xY w| j                  d|z         t        | j                        j$                  }| j'                  t)        ||      d       y )NforzFailed to induce SyntaxErrorfooazFailed to induce NameError.z%s = 1   )r8   
__import__r   RuntimeErrorSyntaxErrorassertNotInr
   r   assertFalsehasattrr	   dir__builtins__r   r   r   r   	NameErrorr;   assertEqualgetattr)r   varmodules      r   test_package_import__semanticsz)TestImport.test_package_import__semantics0   s/   
 	% (() !?@@  D ))3;;7T->->!?GH S&&6==!5!566C S&& 	#(() !>?? $
 	(S.)D,,-11-q1s   2 	>>=D 	D)(D)N)	__name__
__module____qualname__r   r   r'   r.   r8   rK    r   r   r   r      s!    6-
D2r   r   __main__)r!   r
   r)   r   r   r   r   importlib.utilr   test.support.os_helperr   r   r   rL   mainrO   r   r   <module>rT      sO    	 
      , 4@2"" @2F zHMMO r   