+
    Bi/                     X   ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIH	t	 ] P                  R 4       t] P                  R 4       t ! R R]P                  4      t ! R R]4      t ! R	 R
]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R ]4      t ! R! R"]4      t ! R# R$]4      t ! R% R&]4      t]R'8X  d   ]P@                  ! 4        R# R# )(    N)utilc               #    "   \         P                  p \         P                  P                  4       p Rx  V \         n        \         P                  P                  4        \         P                  P	                  V4       R#   T \         n        \         P                  P                  4        \         P                  P	                  T4       i ; i5i)z
Make sure sys.modules is the same object and has the same content
when exiting the context as when entering.

Similar to importlib.test.util.uncache, but doesn't require explicit
names.
N)sysmodulescopyclearupdate)sys_modules_savedsys_modules_copys     >/usr/lib/python3.14/test/test_importlib/test_namespace_pkgs.pysys_modules_contextr      s      {{'')-'+, (+,s   /CB  A
C A
C

Cc            	   +  l  "   V P                  R\        P                  4       V P                  R\        P                  4       \        P
                  ! R/ V B pT;_uu_ 4        \        4       ;_uu_ 4        Rx  RRR4       RRR4       R#   + '       g   i     L; i  + '       g   i     R# ; i5i)z
Save import state and sys.modules cache and restore it on exit.
Typical usage:

>>> with namespace_tree_context(path=['/tmp/xxyy/portion1',
...         '/tmp/xxyy/portion2']):
...     pass
	meta_path
path_hooksN )
setdefaultr   r   r   r   import_stater   )kwargsimport_contexts   , r   namespace_tree_contextr   '   si      k3==1
lCNN3&&00N	,.. /..s6   A!B4#B 6B	;B 
B4BB  B1	+	B4c                      a  ] tR t^8t o Rt]P                  P                  ]P                  P                  ]	4      R4      t
R tRtV tR# )NamespacePackageTestz^
Subclasses should define self.root and self.paths (under that root)
to be added to sys.path.
namespace_pkgsc                    V P                    Uu. uF-  p\        P                  P                  V P                  V4      NK/  	  upV n        V P                  \        V P
                  R 7      4       R# u upi ))pathN)pathsosr   joinrootresolved_pathsenterContextr   )selfr   s   & r   setUpNamespacePackageTest.setUp?   sV    6:jj
6@dBGGLLD)j
 	0d6I6IJK
s   3A1)r    N)__name__
__module____qualname____firstlineno____doc__r   r   r   dirname__file__r   r#   __static_attributes____classdictcell____classdict__s   @r   r   r   8   s:      77<<13CDDL L    r   c                   8   a  ] tR t^Ft o R.tR tR tR tRtV t	R# )SingleNamespacePackageportion1c                Z    ^ RI pV P                  VP                  P                  R4       R# r   Nportion1 foo onefoo.oneassertEqualoneattrr"   foos   & r   test_simple_package*SingleNamespacePackage.test_simple_packageI       '9:r0   c                    V P                  \        4      ;_uu_ 4        ^ RIpRRR4       R#   + '       g   i     R# ; ir   NassertRaisesImportErrorfoo.twor<   s   & r   test_cant_import_other-SingleNamespacePackage.test_cant_import_otherM   %    {++ ,+++   ->	c                D    ^ RI pV P                  \        V4      R4       R# )r   Nz <module 'foo' (namespace) from [)r8   assertStartsWithreprr<   s   & r   test_simple_repr'SingleNamespacePackage.test_simple_reprQ   s    d3i)KLr0   r   N)
r%   r&   r'   r(   r   r>   rG   rN   r,   r-   r.   s   @r   r2   r2   F   s"     LE;M Mr0   r2   c                   ,   a  ] tR t^Vt o R.tR tRtV tR# )DynamicPathNamespacePackager3   c                   ^ RI pV P                  VP                  P                  R4       V P	                  \
        4      ;_uu_ 4        ^ RIpRRR4       \        P                  P                  \        P                  P                  V P                  R4      4       ^ RIpV P                  VP                  P                  R4       R#   + '       g   i     L; i)r   Nr6   portion2portion2 foo two)r8   r9   r:   r;   rD   rE   rF   r   r   appendr   r   r   twor<   s   & r   test_dynamic_path-DynamicPathNamespacePackage.test_dynamic_pathY   s    '9:{++ , 	TYY
;< 	'9: ,+s   CC	r   N)r%   r&   r'   r(   r   rW   r,   r-   r.   s   @r   rQ   rQ   V   s     LE; ;r0   rQ   c                   ,   a  ] tR t^it o R.tR tRtV tR# )CombinedNamespacePackagesboth_portionsc                    ^ RI p^ RIpV P                  VP                  P                  R4       V P                  VP
                  P                  R4       R# r   Nzboth_portions foo oneboth_portions foo twor8   rF   r9   r:   r;   rV   r<   s   & r   test_imports&CombinedNamespacePackages.test_importsl   s:    '>?'>?r0   r   Nr%   r&   r'   r(   r   r`   r,   r-   r.   s   @r   rZ   rZ   i   s     E@ @r0   rZ   c                   .   a  ] tR t^st o RR.tR tRtV tR# )SeparatedNamespacePackagesr3   rS   c                    ^ RI p^ RIpV P                  VP                  P                  R4       V P                  VP
                  P                  R4       R# )r   Nr6   rT   r_   r<   s   & r   r`   'SeparatedNamespacePackages.test_importsv   s:    '9:'9:r0   r   Nrb   r.   s   @r   rd   rd   s   s     $E; ;r0   rd   c                   ,   a  ] tR t^}t o R.tR tRtV tR# )-SeparatedNamespacePackagesCreatedWhileRunningr3   c           	        \         P                  ! 4       ;_uu_ 4       p\        P                  P	                  V4       ^ RIpV P                  VP                  P                  R4       V P                  \        4      ;_uu_ 4        ^ RIpRRR4       \        P                  P                  VR4      p\        P                  ! V4       \        P                  P                  VR4      p\        VRRR7      ;_uu_ 4       pVP!                  R4       RRR4       V P                  \        4      ;_uu_ 4        ^ RIpRRR4       \"        P$                  ! 4        ^ RIpV P                  VP&                  P                  R	4       RRR4       R#   + '       g   i     EL
; i  + '       g   i     L; i  + '       g   i     L; i  + '       g   i     R# ; i)
r   Nr6   r=   zjust_created.pywzutf-8)encodingzattr = "just_created foo"zjust_created foo)tempfileTemporaryDirectoryr   r   rU   r8   r9   r:   r;   rD   rE   foo.just_createdr   r   mkdiropenwrite	importlibinvalidate_cachesjust_created)r"   temp_dirr=   namespace_pathmodule_pathfiles   &     r   test_invalidate_cachesDSeparatedNamespacePackagesCreatedWhileRunning.test_invalidate_caches   s1   ((**h HHOOH%SWW\\+=> "";//' 0
  WW\\(E:NHH^$'',,~7HIKk399T

67 : "";//' 0 '')#S--224FG7 +* 0// :9 0/+ +**sV   A'GF	
A4G>F	%G5F2	:AGF	GF/*G2G=GG	r   N)r%   r&   r'   r(   r   ry   r,   r-   r.   s   @r   rh   rh   }   s     LEH Hr0   rh   c                   :   a  ] tR t^t o RR.tR tR tR tRtV t	R# )%SeparatedOverlappingNamespacePackagesr3   r[   c                    ^ RI p^ RIpV P                  VP                  P                  R4       V P                  VP
                  P                  R4       R# r   Nr6   r^   r_   r<   s   & r   test_first_path_wins:SeparatedOverlappingNamespacePackages.test_first_path_wins   :    '9:'>?r0   c                    \         P                  P                  4        ^ RIp^ RIpV P                  VP                  P                  R4       V P                  VP                  P                  R4       R# r]   )	r   r   reverser8   rF   r9   r:   r;   rV   r<   s   & r   test_first_path_wins_again@SeparatedOverlappingNamespacePackages.test_first_path_wins_again   sJ    '>?'>?r0   c                    ^ RI p^ RIpV P                  VP                  P                  R4       V P                  VP
                  P                  R4       R# r~   )rF   r8   r9   r:   r;   rV   r<   s   & r   +test_first_path_wins_importing_second_firstQSeparatedOverlappingNamespacePackages.test_first_path_wins_importing_second_first   r   r0   r   N)
r%   r&   r'   r(   r   r   r   r   r,   r-   r.   s   @r   r|   r|      s'     )E@@@ @r0   r|   c                   2   a  ] tR t^t o R.tR tR tRtV tR# )SingleZipNamespacePackagetop_level_portion1.zipc                Z    ^ RI pV P                  VP                  P                  R4       R# r5   r7   r<   s   & r   r>   -SingleZipNamespacePackage.test_simple_package   r@   r0   c                    V P                  \        4      ;_uu_ 4        ^ RIpRRR4       R#   + '       g   i     R# ; irB   rC   r<   s   & r   rG   0SingleZipNamespacePackage.test_cant_import_other   rI   rJ   r   N	r%   r&   r'   r(   r   r>   rG   r,   r-   r.   s   @r   r   r      s     %&E; r0   r   c                   .   a  ] tR t^t o RR.tR tRtV tR# )SeparatedZipNamespacePackagesr   rS   c                F   ^ RI p^ RIpV P                  VP                  P                  R4       V P                  VP
                  P                  R4       V P                  RVP                  P                  4       V P                  RVP
                  P                  4       R# )r   Nr6   rT   r   .zip)	r8   rF   r9   r:   r;   rV   assertInr+   assertNotInr<   s   & r   r`   *SeparatedZipNamespacePackages.test_imports   sm    '9:'9:.0@0@A!1!12r0   r   Nrb   r.   s   @r   r   r      s     %z2E3 3r0   r   c                   2   a  ] tR t^t o R.tR tR tRtV tR# )SingleNestedZipNamespacePackage#nested_portion1.zip/nested_portion1c                Z    ^ RI pV P                  VP                  P                  R4       R# r5   r7   r<   s   & r   r>   3SingleNestedZipNamespacePackage.test_simple_package   r@   r0   c                    V P                  \        4      ;_uu_ 4        ^ RIpRRR4       R#   + '       g   i     R# ; irB   rC   r<   s   & r   rG   6SingleNestedZipNamespacePackage.test_cant_import_other   rI   rJ   r   Nr   r.   s   @r   r   r      s     23E; r0   r   c                   .   a  ] tR t^t o RR.tR tRtV tR# )#SeparatedNestedZipNamespacePackagesr   rS   c                   ^ RI p^ RIpV P                  VP                  P                  R4       V P                  VP
                  P                  R4       \        P                  P                  RR4      pV P                  W!P                  P                  4       V P                  RVP
                  P                  4       R# )r   Nr6   rT   znested_portion1.zipnested_portion1r   )r8   rF   r9   r:   r;   rV   r   r   r   r   r+   r   )r"   r=   fns   &  r   r`   0SeparatedNestedZipNamespacePackages.test_imports   s    '9:'9:WW\\/1BCb''**+!1!12r0   r   Nrb   r.   s   @r   r   r      s     2J?E3 3r0   r   c                   .   a  ] tR t^t o . ROtR tRtV tR# )LegacySupportc                &   ^ RI pV P                  \        4      ;_uu_ 4        ^ RIpRRR4       V P	                  RVP
                  4       V P                  R\        VP                  4      P                  4       4       R#   + '       g   i     La; i)r   N__init__	namespace)
r8   rD   rE   rF   r   r+   r   str
__loader__lowerr<   s   & r   +test_non_namespace_package_takes_precedence9LegacySupport.test_non_namespace_package_takes_precedence   s[    {++ ,j#,,/c#..&9&?&?&AB ,+s   B  B	r   N)not_a_namespace_pkgr3   rS   r[   )r%   r&   r'   r(   r   r   r,   r-   r.   s   @r   r   r      s     LEC Cr0   r   c                   4   a  ] tR t^t o RR.tR tR tRtV tR# )DynamicPathCalculationproject1project2c                H   ^ RI pV P                  \        VP                  4      ^4       V P                  \        VP                  P                  4      ^4       ^ RIpV P                  \        VP                  4      ^4       V P                  \        VP                  P                  4      ^4       V P                  VP                  P                  P                  R4       V P                  VP                  P                  P                  R4       V P                  \        4      ;_uu_ 4        ^ RIpRRR4       V P                  \        VP                  4      ^4       V P                  \        VP                  P                  4      ^4       R#   + '       g   i     Lf; i)r   Nparent child oneparent child two)parent.child.oner9   len__path__childparent.child.twor:   r;   rV   rD   rE   parent.child.threer"   parents   & r   test_project3_fails*DynamicPathCalculation.test_project3_fails   s   V__-q1V\\223Q7V__-q1V\\223Q7))..0BC))..0BC{++% , 	V__-q1V\\223Q7	 ,+s   .FF!	c                >   ^ RI pV P                  \        VP                  4      ^4       V P                  \        VP                  P                  4      ^4       ^ RIpV P                  \        VP                  4      ^4       V P                  \        VP                  P                  4      ^4       V P                  VP                  P                  P                  R4       V P                  VP                  P                  P                  R4       V P                  \        4      ;_uu_ 4        ^ RIpRRR4       \        P                  P                  \        P                  P!                  V P"                  R4      4       ^ RIpV P                  \        VP                  4      ^4       V P                  \        VP                  P                  4      ^4       V P                  VP                  P$                  P                  R4       R#   + '       g   i     L; i)r   Nr   r   project3zparent child three)r   r9   r   r   r   r   r:   r;   rV   rD   rE   r   r   r   rU   r   r   r   threer   s   & r   test_project3_succeeds-DynamicPathCalculation.test_project3_succeeds  s_   V__-q1V\\223Q7V__-q1V\\223Q7))..0BC))..0BC{++% , 	TYY
;<! 	V__-q1V\\223Q7++002FG ,+s   .HH	r   N)	r%   r&   r'   r(   r   r   r   r,   r-   r.   s   @r   r   r      s      $E8"H Hr0   r   c                   8   a  ] tR tRt o R.tR tR tR tRtV t	R# )ZipWithMissingDirectoryi  zmissing_directory.zipc                Z    ^ RI pV P                  VP                  P                  R4       R# r5   r7   r<   s   & r   test_missing_directory.ZipWithMissingDirectory.test_missing_directory*  r@   r0   c                2    ^ RI pV P                  VR4       R# )r   Nr:   )r=   assertNotHasAttrr<   s   & r   test_missing_directory2/ZipWithMissingDirectory.test_missing_directory2.  s    c5)r0   c                Z    ^ RI pV P                  VP                  P                  R4       R# )r   Nzmissing_directory foo two)bar.twor9   rV   r;   )r"   bars   & r   test_present_directory.ZipWithMissingDirectory.test_present_directory2  s    'BCr0   r   N)
r%   r&   r'   r(   r   r   r   r   r,   r-   r.   s   @r   r   r     s#     $%E;*D Dr0   r   c                   ,   a  ] tR tRt o R.tR tRtV tR# )"ModuleAndNamespacePackageInSameDiri7  module_and_namespace_packagec                F    ^ RI pV P                  VP                  R4       R# )r   Nz	in module)a_testr9   r;   )r"   r   s   & r   $test_module_before_namespace_packageGModuleAndNamespacePackageInSameDir.test_module_before_namespace_package:  s     	k2r0   r   N)r%   r&   r'   r(   r   r   r,   r-   r.   s   @r   r   r   7  s     +,E3 3r0   r   c                   8   a  ] tR tRt o R.tR tR tR tRtV t	R# )ReloadTestsiA  r3   c                    ^ RI p\        P                  ! V4      pV P                  VP                  P
                  R4       R# r5   )r8   rr   reloadr9   r:   r;   r<   s   & r   r>   ReloadTests.test_simple_packageD  s.    s#'9:r0   c                0   ^ RI pV P                  \        4      ;_uu_ 4        ^ RIpRRR4       \        P
                  ! V4      pV P                  \        4      ;_uu_ 4        ^ RIpRRR4       R#   + '       g   i     LR; i  + '       g   i     R# ; irB   )r=   rD   rE   rF   rr   r   r<   s   & r   rG   "ReloadTests.test_cant_import_otherI  s_    {++ ,s#{++ ,+ ,+ ,++s   A1"B1B	B	c                   ^ RI pV P                  \        4      ;_uu_ 4        ^ RIpRRR4       \        P
                  P                  \        P
                  P                  V P                  R4      4       \        P                  ! V4      p^ RIpV P                  VP                  P                  R4       R#   + '       g   i     L; i)r   NrS   rT   )r8   rD   rE   rF   r   r   rU   r   r   r   rr   r   r9   rV   r;   r<   s   & r   rW   ReloadTests.test_dynamic_pathQ  sz    {++ , 	TYY
;<s# 	'9: ,+s   B88C	r   N)
r%   r&   r'   r(   r   r>   rG   rW   r,   r-   r.   s   @r   r   r   A  s      LE;
; ;r0   r   c                   >   a  ] tR tRt o R.tR tR tR tR tRt	V t
R# )	LoaderTestsi_  r3   c                    ^ RI pV P                  VP                  VP                  P                  4       V P                  VP                  4       R# rB   )r=   r9   r   __spec__loaderassertIsNotNoner<   s   & r   !test_namespace_loader_consistency-LoaderTests.test_namespace_loader_consistencyb  s5    )<)<=S^^,r0   c                    ^ RI pV P                  VP                  P                  4       V P                  VP                  4       R# rB   )r=   assertIsNoner   originr+   r<   s   & r   !test_namespace_origin_consistency-LoaderTests.test_namespace_origin_consistencyh  s/    #,,--.#,,'r0   c                    ^ RI p\        P                  P                  V P                  RR4      pV P                  VP                  ^ ,          V4       R# )r   Nr3   r=   )r=   r   r   r   r   r9   r   )r"   r=   expected_paths   &  r   test_path_indexableLoaderTests.test_path_indexablen  s7    TYY
EBa-8r0   c                   ^ RI pV P                  \        VP                  \        P
                  P                  4      4       V P                  \        VP                  \        P                  P                  4      4       R# rB   )	r=   
assertTrue
isinstancer   rr   abcLoader	machineryNamespaceLoaderr<   s   & r   test_loader_abcLoaderTests.test_loader_abct  sI    
3>>9==3G3GHI
3>>93F3F3V3VWXr0   r   N)r%   r&   r'   r(   r   r   r   r   r   r,   r-   r.   s   @r   r   r   _  s'     LE-(9Y Yr0   r   __main__)!
contextlibrr   importlib.abcimportlib.machineryr   r   rl   unittesttest.test_importlibr   contextmanagerr   r   TestCaser   r2   rQ   rZ   rd   rh   r|   r   r   r   r   r   r   r   r   r   r   r%   mainr   r0   r   <module>r     sb       	 
   $ - -$   L8,, LM1 M ;"6 ;&@ 4 @;!5 ;H4H HD@,@ @.	 4 		3$8 	3	&: 	
3*> 
3C( C*H1 *HZD2 D03)= 3;& ;<Y& Y6 zMMO r0   