
    daf<#                        d dl mZ  ej                  d      Z ej                  d      Zd dlZd dlZd dlZd dlm	Z	 d dl
Z
d dlZd dlZ G d d      Z G d d	e      Z ej                  eee
      \  ZZ G d de      Z ej                  eee
      \  ZZ G d d      Z ej                  ee      \  ZZedk(  r e
j2                          yy)    )util	importlibzimportlib.machineryN)
ModuleTypec                   f    e Zd ZdZdZdZd Zd Zd Zd Z	d Z
d Zd	 Zd
 Zd Zd Zd Zd Zd Zy)FinderTestszTests for PathFinder.Nc                     d}t        j                         5  | j                  | j                  |             d d d        y # 1 sw Y   y xY w)N<test module>)r   import_stateassertIsNonefind)selfmodules     @/root/Python-3.12.4/Lib/test/test_importlib/import_/test_path.pytest_failurezFinderTests.test_failure   s?       	1dii/0	1 	1 	1s   !AA
c                     d}d}t        j                  |      }t        j                  ||i|g      5  | j                  |      }| j	                  ||       d d d        y # 1 sw Y   y xY w)Nr	   <test path>path_importer_cachepathr   	mock_specr
   r   check_foundr   r   r   importerfounds        r   test_sys_pathzFinderTests.test_sys_path   si     !>>&)D(3C%)F, 	.IIf%EUH-	. 	. 	.s   $A!!A*c                     d}d}t        j                  |      }t        j                  ||i      5  | j                  ||g      }| j	                  ||       d d d        y # 1 sw Y   y xY w)Nr	   r   r   r   r   s        r   	test_pathzFinderTests.test_path'   sf     !>>&)D(3CD 	.IIftf-EUH-	. 	. 	.s   &A!!A*c                     d}d}t        j                  |      }t        j                  ||i|g      5  | j                  | j	                  dg              d d d        y # 1 sw Y   y xY w)Nr   r   r   )r   r   r
   r   r   )r   r   r   r   s       r   test_empty_listzFinderTests.test_empty_list1   sb    >>&)D(3C%)F, 	7dii"56	7 	7 	7s   "AA(c                    d}d}t        j                  |      }t        j                  ||      }t        j                  |g      5  | j	                  ||g      }| j                  ||       | j                  |t        j                         | j                  t        j                  |   |       d d d        y # 1 sw Y   y xY w)Nr	   r   r   )
path_hooks)
r   r   mock_path_hookr
   r   r   assertInsysr   assertIs)r   r   r   r   hookr   s         r   test_path_hookszFinderTests.test_path_hooks:   s     !>>&)""4(;4&1 	CIIftf-EUH-MM$ 7 78MM#11$7B		C 	C 	Cs   A)B::Cc                 4   d}t        j                  i g |g      5  t        j                  d      5 }t        j                  dt
               t        j                  dt               | j                  | j                  d             | j                  t        j                  |          | j                  t        |      d       | j                  t        |d	   j                  t
                     d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)
N
bogus_path)r   r$   r   T)recordalwaysignoreos   )r   r
   warningscatch_warningssimplefilterImportWarningDeprecationWarningr   r   r'   r   assertEquallen
assertTrue
issubclasscategory)r   
path_entryws      r   test_empty_path_hooksz!FinderTests.test_empty_path_hooksG   s     "
2"%/L2 	K((5 K%%h>%%h0BC!!$))D/2!!#"9"9*"EF  Q+
1R5>>= IJK	K 	KK K	K 	Ks#   DB>D1DD	DDc                    d}d}t        j                  |      }t        j                  t        j                         |      }t        j
                  |g|g      5  | j                  |      }| j                  ||       | j                  t        j                         t        j                         d d d        y # 1 sw Y   y xY w)N r	   r#   r   r$   )r   r   r%   r0   getcwdr
   r   r   r&   r'   r   )r   r   r   r   r)   r   s         r   %test_path_importer_cache_empty_stringz1FinderTests.test_path_importer_cache_empty_stringU   s     >>&)""299;BTFv> 	@IIf%EUH-MM"))+s'>'>?	@ 	@ 	@s   AB;;Cc                    t         j                  d d  }|j                  dd        t         j                  j	                         }|j                  d d        t        j                   | j                  j                  j                  | j                  j                  j                          g}t               }t         j                  j                  d|      }	 t!        j"                  t         j$                  d d  |||      5  | j                  j'                  d      }| j)                  |t*               d d d        ||ur|t         j                  d<   y y # 1 sw Y   "xY w# ||ur|t         j                  d<   w w xY w)Nr   email)	meta_pathr   r   r$   )r'   r   insertr   copypop	zipimportzipimporter	machinery
FileFinder	path_hookr   _bootstrap_external_get_supported_file_loadersobjectmodulesr   r
   rG   import_moduleassertIsInstancer   )r   new_pathnew_path_importer_cachenew_path_hooksmissingrF   r   s          r   test_None_on_sys_pathz!FinderTests.test_None_on_sys_path`   s@    88A;4 "%"9"9">">"@##D$/#//=$..33==#~~AA]]_ab (1		-""S]]1-=(07N.<> : 55g>%%fj9: G#',G$ $: : G#',G$ $s$   *E  2E2E EE E9c                 $    G d d      }d}t        j                  | |       i      5  | j                  | j                  j                  j                  d|g             d d d         |       }| j                  j                  dt              |_        t        j                  ||i      5  | j                  j                  j                  d|g      }d d d        | j                  |j                         y # 1 sw Y   xY w# 1 sw Y   2xY w)Nc                       e Zd ZdZddZy):FinderTests.test_finder_with_find_spec.<locals>.TestFinderNc                     | j                   S N)spec)r   fullnametargets      r   	find_speczDFinderTests.test_finder_with_find_spec.<locals>.TestFinder.find_specz   s    yy     r_   )__name__
__module____qualname__r`   rc    rd   r   
TestFinderr]   x   s    D!rd   ri   ztesting pathr   whatever)
r   r
   r   rM   
PathFinderrc   
ModuleSpec
__loader__r`   r8   )r   ri   r   success_findergots        r   test_finder_with_find_specz&FinderTests.test_finder_with_find_specw   s    	! 	! D*,3GH 	MNN--77
TFKM	M $"nn77
JOD.3IJ 	J..++55j4&IC	Jn112	M 	M
	J 	Js   7C:-(D:DDc                 L   t        j                         }| j                  t         j                  |       t	        j
                         }	 t        j                  |       	 t        j                  |       t        j                  dg      5  | j                  | j                  j                  j                  d             d d d        y # t        $ r | j                  d       Y qw xY w#  t        j                  |       t        j                  |        xY w# 1 sw Y   y xY w)Nz/platform does not allow the deletion of the cwdrA   )r   rj   )r0   rC   
addCleanupchdirtempfilemkdtemprmdirOSErrorskipTestr   r
   r   rM   rk   rc   )r   old_dirnew_dirs      r   test_deleted_cwdzFinderTests.test_deleted_cwd   s    ))+'*""$	HHW9! RD) 	Odnn77AA*MN	O 	O  9 8 99	HHWHHW	O 	Os6   
C*  C
 5D
C'$C* &C''C* *-DD#c                 V    G d d      }t         j                  j                  d      }dt               | |       i}t	        j
                  |      5  | j                  j                  j                          d d d        | j                  ||   j                         y # 1 sw Y   (xY w)Nc                       e Zd Zd Zd Zy)>FinderTests.test_invalidate_caches_finders.<locals>.FakeFinderc                     d| _         y )NFcalledr   s    r   __init__zGFinderTests.test_invalidate_caches_finders.<locals>.FakeFinder.__init__   s	    #rd   c                     d| _         y )NTr   r   s    r   invalidate_cacheszPFinderTests.test_invalidate_caches_finders.<locals>.FakeFinder.invalidate_caches   s	    "rd   N)re   rf   rg   r   r   rh   rd   r   
FakeFinderr~      s    $#rd   r   finder_to_invalidateleave_aloner   )r0   r   abspathrR   r   r
   rM   rk   r   r:   r   )r   r   keycaches       r   test_invalidate_caches_findersz*FinderTests.test_invalidate_caches_finders   s    	# 	# ggoo45#z|<59 	:NN%%779	:c
))*	: 	:s   %BB(c                     dd i}t        j                  |      5  | j                  j                  j	                          d d d        | j                  t        |      d       y # 1 sw Y   %xY w)N	clear_outr   r   )r   r
   rM   rk   r   r8   r9   )r   r   s     r   %test_invalidate_caches_clear_out_Nonez1FinderTests.test_invalidate_caches_clear_out_None   sY    d#59 	:NN%%779	:UQ'	: 	:s   %A$$A-c                      G d d      }d |       i}t        j                  |      5  | j                  j                  j	                          d d d        | j                  |i        y # 1 sw Y   xY w)Nc                       e Zd Zd Zy)NFinderTests.test_invalidate_caches_clear_out_relative_path.<locals>.FakeFinderc                      y r_   rh   r   s    r   r   z`FinderTests.test_invalidate_caches_clear_out_relative_path.<locals>.FakeFinder.invalidate_caches   s    rd   N)re   rf   rg   r   rh   rd   r   r   r      s    rd   r   relative_pathr   )r   r
   rM   rk   r   r8   )r   r   r   s      r   .test_invalidate_caches_clear_out_relative_pathz:FinderTests.test_invalidate_caches_clear_out_relative_path   sc    	 	 !*,/59 	:NN%%779	:#	: 	:s   %A**A3)re   rf   rg   __doc__r   r   r   r   r   r!   r*   r?   rD   rZ   rp   r{   r   r   r   rh   rd   r   r   r      sT    DK1	..7CK	@-.3O,+($rd   r   c                       e Zd Zd Zd Zy)FindModuleTestsc                 n     | j                   j                  j                  |i |}|d S |j                  S r_   )rM   rk   rc   loader)r   argskwargsr`   s       r   r   zFindModuleTests.find   s6    2t~~((22DCFC|t44rd   c                 (    | j                  ||       y r_   )r(   r   r   r   s      r   r   zFindModuleTests.check_found   s    eX&rd   Nre   rf   rg   r   r   rh   rd   r   r   r      s    5'rd   r   )r   rM   c                       e Zd Zd Zd Zy)FindSpecTestsc                 N     | j                   j                  j                  |i |S r_   )rM   rk   rc   )r   r   r   s      r   r   zFindSpecTests.find   s$    2t~~((22DCFCCrd   c                 <    | j                  |j                  |       y r_   )r(   r   r   s      r   r   zFindSpecTests.check_found   s    ellH-rd   Nr   rh   rd   r   r   r      s    D.rd   r   c                       e Zd Zd Zy)PathEntryFinderTestsc                     G d d      }t        j                  |j                  gt        j                  d d  z   |g      5  t        j                         5  t        j                  dt               | j                  j                  j                  d       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nc                   (    e Zd ZdZd Zedd       Zy)GPathEntryFinderTests.test_finder_with_failing_find_spec.<locals>.Finderrp   c                 .    || j                   k7  rt        y r_   )path_locationImportError)r   r   s     r   r   zPPathEntryFinderTests.test_finder_with_failing_find_spec.<locals>.Finder.__init__   s    4---%% .rd   Nc                      y r_   rh   )ra   rb   s     r   rc   zQPathEntryFinderTests.test_finder_with_failing_find_spec.<locals>.Finder.find_spec   s    rd   r_   )re   rf   rg   r   r   staticmethodrc   rh   rd   r   Finderr      s     8M&  rd   r   rB   r/   r   )r   r
   r   r'   r   r3   r4   r5   r6   rM   rk   rc   )r   r   s     r   "test_finder_with_failing_find_specz7PathEntryFinderTests.test_finder_with_failing_find_spec   s    	 	 V%9%9$:388A;$F+1(4 	A((* A%%h>))33K@A	A 	AA A	A 	As%   B4A B(B4(B1	-B44B=N)re   rf   rg   r   rh   rd   r   r   r      s    Ard   r   )rM   __main__)test.test_importlibr   import_importlibr   rM   r0   r'   rt   typesr   unittestr3   rK   r   r   	test_bothFrozen_FindModuleTestsSource_FindModuleTestsr   Frozen_FindSpecTestsSource_FindSpecTestsr   Frozen_PEFTestsSource_PEFTestsre   mainrh   rd   r   <module>r      s    $!D!!+.	!D!!"78	 	 
     k$ k$\'k ' DNN?i9M.K . T^^MY)LA A. T^^(I> zHMMO rd   