
    daf                     :   d dl Z d dl mZ d dl m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      Z G d dej                        Z G d	 d
ej                  ej                         Z G d dej                        Zedk(  r ej(                          yy)    N)abc)util)threading_helperc                       e Zd Zd Zd Zy)CollectInitc                      || _         || _        y N)argskwargs)selfr
   r   s      8/root/Python-3.12.4/Lib/test/test_importlib/test_lazy.py__init__zCollectInit.__init__   s    	    c                     | S r	    r   modules     r   exec_modulezCollectInit.exec_module   s    r   N)__name__
__module____qualname__r   r   r   r   r   r   r      s    r   r   c                       e Zd Zd Zd Zy)LazyLoaderFactoryTestsc                     t         j                  j                  t              } |ddd      }|j                  }| j                  d|j                         | j                  ddi|j                         y )Nmodule namemodule pathkw)r   )r   r   )r   
LazyLoaderfactoryr   loaderassertEqualr
   r   )r   r   lazy_loaderr    s       r   	test_initz LazyLoaderFactoryTests.test_init   s^    //))+6 m]tD##7E$v}}5r   c                     | j                  t              5  t        j                  j	                  t
               d d d        y # 1 sw Y   y xY wr	   )assertRaises	TypeErrorr   r   r   objectr   s    r   test_validationz&LazyLoaderFactoryTests.test_validation#   s7    y) 	,OO##F+	, 	, 	,s   $AAN)r   r   r   r#   r)   r   r   r   r   r      s    6,r   r   c                   L    e Zd ZdZdZdZdZdj                  e      ZddZ	d Z
y)	TestingImporterlazy_loader_testchangedNr   zattr = 42; __name__ = {!r}c                 t    || j                   k7  ry t        j                  |t        j                  |             S r	   )module_namer   spec_from_loaderr   )r   namepathtargets       r   	find_speczTestingImporter.find_spec1   s/    4###$$T4??4+@AAr   c                     t        j                  d       t        | j                  |j                         || _        | xj                  dz  c_        y )Ng{Gz?   )timesleepexecsource_code__dict__loaded
load_countr   s     r   r   zTestingImporter.exec_module6   s7    

4Tv/1r   r	   )r   r   r   r/   mutated_namer<   r=   formatr:   r4   r   r   r   r   r+   r+   )   s1    $KLFJ.55lCKB
r   r+   c                       e Zd Zd ZddZd Zd Zd Zd Zd Z	d	 Z
d
 Zd Zd Z ej                         d        Zd Zy)LazyLoaderTestsc                     | j                  t              5  t        j                  t               d d d        y # 1 sw Y   y xY wr	   )r%   r&   r   r   r'   r(   s    r   r#   zLazyLoaderTests.test_init?   s1    y) 	$OOF#	$ 	$ 	$s	   9ANc                    |
t               }|||_        t        j                  t         j                  t        j
                  |            }|j                  j                  |      }|#t        j                  t         j                        }||_
        |j                  |_        |j                  j                  |       | j                  |j                         |S r	   )r+   r:   r   r0   r/   r   r    create_moduletypes
ModuleType__spec__
__loader__r   assertIsNoner<   )r   r:   r    specr   s        r   
new_modulezLazyLoaderTests.new_moduleD   s    >$&F"!,F$$_%@%@%)__V%<>**40>%%o&A&ABF KK'&--(r   c                    t               }|j                  J t        j                  |j                        5  t        j
                  |g      5  t        j                  |j                        }d d d        d d d        | j                  |j                         | j                  j                  |       | j                  |j                         | j                  ||j                         y # 1 sw Y   xY w# 1 sw Y   xY w)N)	meta_path)r+   r<   	test_utiluncacher/   import_state	importlibimport_modulerI   r!   rH   assertIsNotNone)r   importerr   s      r   test_e2ezLazyLoaderTests.test_e2eU   s    "$&&&x334 	G''8*= G"001E1EFG	G 	(//***H5X__-1G G	G 	Gs#   C; C/0C;/C8	4C;;Dc                 x    | j                         }| j                  t        j                  |j                         y r	   )rK   r!   r+   r>   r   r   s     r   test_attr_unchangedz#LazyLoaderTests.test_attr_unchangedb   s*     "55vGr   c                 j    | j                         }d|_        | j                  d|j                         y )N*   )rK   new_attrr!   r   s     r   test_new_attrzLazyLoaderTests.test_new_attrh   s)    "V__-r   c                 j    | j                         }d|_        | j                  d|j                         y )Nbogus)rK   r   r!   r   s     r   test_mutated_preexisting_attrz-LazyLoaderTests.test_mutated_preexisting_attrn   s+     "!&//2r   c                 j    | j                         }d|_        | j                  d|j                         y )N   )rK   attrr!   r   s     r   test_mutated_attrz!LazyLoaderTests.test_mutated_attru   s+     "FKK(r   c                 ^    | j                         }|`| j                  t        |d             y )Nra   )rK   ra   assertFalsehasattrr   s     r   test_delete_eventual_attrz)LazyLoaderTests.test_delete_eventual_attr|   s(    "K01r   c                 ^    | j                         }|`| j                  t        |d             y )Nr   )rK   r   rd   re   r   s     r   test_delete_preexisting_attrz,LazyLoaderTests.test_delete_preexisting_attr   s(    "O45r   c                    t        j                  t        j                        5  t	        j
                  t        j                        }|t        j                  t        j                  <   | j                         }| j                  t        d      5  |j                   d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nsubstituted)rN   rO   r+   r/   rE   rF   sysmodulesrK   assertRaisesRegex
ValueErrorr   )r   fresh_moduler   s      r   test_module_substitution_errorz.LazyLoaderTests.test_module_substitution_error   s    ::; 	  ++O,G,GHL7CCKK334__&F''
MB   		  	    		  	 s$   A+B9B-B9-B6	2B99Cc                     t        j                  t        j                        5  | j	                         }|t
        j                  t        j                  <   |j                   d d d        y # 1 sw Y   y xY wr	   )rN   rO   r+   r/   rK   rk   rl   r   r   s     r   test_module_already_in_sysz*LazyLoaderTests.test_module_already_in_sys   sR    ::; 	__&F7=CKK334OO		 	 	s   >A++A4c                 6   t        j                  t        j                        5  t               }| j	                  |      | j                  |j                  d        G d dt        j                        }fd}g }t        d      D ],  }|j                   ||      x}       |j                          . |D ]-  }|j                          | j                  |j                         / | j                  |j                  d       d d d        y # 1 sw Y   y xY w)	N)r    r   c                   "     e Zd ZdZ fdZ xZS )<LazyLoaderTests.test_module_load_race.<locals>.RaisingThreadNc                 ^    	 t         |           y # t        $ r}|| _        Y d }~y d }~ww xY wr	   )superrun	Exceptionexc)r   rz   	__class__s     r   rx   z@LazyLoaderTests.test_module_load_race.<locals>.RaisingThread.run   s*    '$ '#&'s    	,',)r   r   r   rz   rx   __classcell__)r{   s   @r   RaisingThreadru      s    ' 'r   r}   c                       j                   S r	   )ra   )r   s   r   access_modulez<LazyLoaderTests.test_module_load_race.<locals>.access_module   s    {{"r      )r3   r6   )rN   rO   r+   r/   rK   r!   r=   	threadingThreadrangeappendstartjoinrI   rz   )r   r    r}   r   threads_threadr   s          @r   test_module_load_racez%LazyLoaderTests.test_module_load_race   s    ::; 	3$&F__F_3FV..2'	 0 0 '# G1X m)LLvM
 " .!!&**-.
 V..27	3 	3 	3s   C!DDc                    t         j                  D cg c]  }|j                  d      s| }}t        j                  | 5  t        j                  d      }t        j                  |j                        }||_        t        j                  |      }|t         j                  d<   |j                  |       |j                  d      }| j                  |i        d d d        y c c}w # 1 sw Y   y xY w)Njsonz{})rk   rl   
startswithrN   rO   r   r4   r   r    module_from_specr   loadsr!   )r   r1   json_modulesrJ   r    r   	test_loads          r   "test_lazy_self_referential_modulesz2LazyLoaderTests.test_lazy_self_referential_modules   s     *-P8OPP- 	,>>&)D__T[[1F DK**40F"(CKKv& T*IY+	, 	, Q	, 	,s   C#C#BC((C1)NN)r   r   r   r#   rK   rU   rW   r[   r^   rb   rf   rh   rp   rr   r   requires_working_threadingr   r   r   r   r   rA   rA   =   s_    $
"2H.3)26
  10023 33<,r   rA   __main__)rQ   r   r   rk   r7   r   rE   unittesttest.supportr   test.test_importlibrN   r   TestCaser   MetaPathFinderLoaderr+   rA   r   mainr   r   r   <module>r      s       
     ) 1 ,X.. ,"c((#** (H,h'' H,V zHMMO r   