
    daf=                    `   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	m
Z
mZ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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Zd dlmZ d dlZd dlZd dlmZ d dlmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z& d dl'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z. d dl/m0Z0m1Z1m2Z2m3Z3 d d	lm4Z4 d d
lm5Z5 d dl6m7Z7 d dlm8Z8 	 d dl9Z9	 d dl;Z;	 d dl<Z= ej~                  ej                  d      ZAd ZBdddZCdddZDdddZEdddZFd ZGd ZHe9e9ddZId ZJd ZK G d dej                        ZM G d dej                        ZOeA G d  d!ej                               ZP G d" d#ej                        ZQ G d$ d%ej                        ZR G d& d'ej                        ZS G d( d)ej                        ZT G d* d+ej                        ZU G d, d-ej                        ZVe" G d. d/ej                               ZWe" G d0 d1ej                               ZX G d2 d3ej                        ZY G d4 d5ej                        ZZ G d6 d7ej                        Z[ G d8 d9eM      Z\eJ G d: d;ej                               Z]e^d<k(  r ej                          yy# e:$ r dZ9Y w xY w# e:$ r dZ;Y w xY w# e>$ r dZ=Y w xY w)=    N)_get_sourcefile)BuiltinImporterExtensionFileLoaderFrozenImporterSourceFileLoader)mock)	os_helper)
STDLIB_DIR	swap_attr	swap_itemcpython_onlyis_emscriptenis_wasirun_in_subinterprun_in_subinterp_with_config)forgetmake_legacy_pycunlinkunloadready_to_importDirsOnSysPathCleanImport)TESTFNrmtree
temp_umaskTESTFN_UNENCODABLE)script_helper)threading_helper)uncache)
ModuleTypez*test meaningful only when writing bytecodec                    t        | t              rt        |       } t        dt        dt
        dt        di}|}t        |t              sJ |       ||   }| j                  j                  }t        |t              st        |      }||   }||k7  r4d| d| j                   }|rt        j                  |      t        |      | S )Nbuilt-in	extensionfrozenzpure Pythonzexpected module to be z, got )
isinstancestr
__import__r   r   r   r   type__spec__loaderunittestSkipTest	Exception)moduler*   skipMODULE_KINDSexpectedactualerrs          4/root/Python-3.12.4/Lib/test/test_import/__init__.py_require_loaderr5   ;   s    &#F# 	[-	L Hh%/x/%H%H__##Ffd#f&!F&xjv6GH##C((nM    Fr/   c                z    t        | t        |      } | j                  j                  dk(  sJ | j                         y )Nr"   )r5   r   r)   originr.   r/   s     r4   require_builtinr;   V   s1    V_d;F??!!Z/@@/r6   c                &    t        | t        |       y N)r5   r   r:   s     r4   require_extensionr>   Z   s    F/6r6   Tc                z    t        | t        |      } | j                  j                  dk(  sJ | j                         y )Nr$   )r5   r   r)   r9   r:   s     r4   require_frozenr@   ]   s1    V^T:F??!!X->v>-r6   c                &    t        | t        |       y r=   )r5   r   r:   s     r4   require_pure_pythonrB   a   s    F,d3r6   c                 ^    | dz   | dz   | dz   | dz   fD ]  }t        |        t        d       y )N.py.pyc.pywz	$py.class__pycache__)r   r   )namefs     r4   remove_filesrJ   d   sC    UlVmVm[ "  	q		
 =r6   c                       fd}|S )zSkip rerunning for a particular test.

    WARNING: Use this decorator with care; skipping rerunning makes it
    impossible to find reference leaks. Provide a clear reason for skipping the
    test using the 'reason' parameter.
    c                      d fd}|S )NFc                 @    r| j                          |        dy )NT)skipTest)self_has_runfuncreasons    r4   wrapperz'no_rerun.<locals>.deco.<locals>.wrapperv   s    f%JHr6    )rQ   rS   rP   rR   s   ` @r4   decozno_rerun.<locals>.decot   s    	 r6   rT   )rR   rU   s   ` r4   no_rerunrV   m   s     Kr6   )_origc                     t         j                  j                  dd        | j                          t	        j
                  d| j                         dd l}y )N_testsinglephaser   )sysmodulespop_clear_globals_testinternalcapiclear_extension__file__rY   )rW   rY   s     r4   restore__testsinglephasera      s;     	*D1))*<ennMr6   c                     t        | t              s| fd} t        |       }  t        j                  t
        du d      |       S )zADecorator to skip if single-phase init modules are not supported.c                 F    	  ||       t                S # t                w xY wr=   ra   )rO   _meths     r4   methz'requires_singlephase_init.<locals>.meth   s    +T{(*(*s     Nz%test requires _testsinglephase module)r%   r(   r   r+   skipIfrY   rf   s    r4   requires_singlephase_initri      sL    dD!! 	+
 DD8??+t3BDDHJ Jr6   c                 F     t        j                  t        du d      |       S )z>Decorator to skip a test if subinterpreters are not supported.Nzsubinterpreters required)r+   rg   _interpretersrh   s    r4   requires_subinterpretersrl      s)    78??=D0577;= =r6   c                      e Zd ZdZ edj                               Zed        Z e	j                  d      Z e	j                  d      j                         Z e	j                  d      j                         Z e	j                  d      j                         Zedd	dd	d
d       Zed        Zedddd       Zed        Zy)ModuleSnapshota?  A representation of a module for testing.

    Fields:

    * id - the module's object ID
    * module - the actual module or an adequate substitute
       * __file__
       * __spec__
          * name
          * origin
    * ns - a copy (dict) of the module's __dict__ (or None)
    * ns_id - the object ID of the module's __dict__
    * cached - the sys.modules[mod.__spec__.name] entry (or None)
    * cached_id - the object ID of the sys.modules entry (or None)

    In cases where the value is not available (e.g. due to serialization),
    the value will be None.
    z#id module ns ns_id cached cached_idc           
         |j                   j                  }t        j                  j	                  |      } | t        |      |t        j                  di |j                  t        |j                        |t        |            S )N)idr.   nsns_idcached	cached_idrT   )	r)   rH   rZ   r[   getrp   typesSimpleNamespace__dict__)clsmodrH   rs   s       r4   from_modulezModuleSnapshot.from_module   se    ||  &#w$$4s||4S\\"j
 	
r6   z
        {imports}

        name = {name!r}

        {prescript}

        mod = {name}

        {body}

        {postscript}
        z
        import sys
        a  
        # Capture the snapshot data.
        cached = sys.modules.get(name)
        snapshot = dict(
            id=id(mod),
            module=dict(
                __file__=mod.__file__,
                __spec__=dict(
                    name=mod.__spec__.name,
                    origin=mod.__spec__.origin,
                ),
            ),
            ns=None,
            ns_id=id(mod.__dict__),
            cached=None,
            cached_id=id(cached) if cached else None,
        )
        zL
        # Clean up the module.
        sys.modules.pop(name, None)
        NF)	prescriptimport_first
postscriptpostcleanupc                   |du r| j                   }nVt        |t              rDt        j                  |      j                         }| j                   t        j                  z   |z   }nd}|r#t        j                  |      j                         nd}|r#t        j                  |      j                         nd}|r|r|t        j                  dz  z   |z   }n|}|r|t        j                  d|       z  }| j                  j                  | j                  j                         ||j                         | j                  j                         |      S )NT    zq

                # Now import the module.
                assert name not in sys.modules
                import )importsrH   r|   bodyr~   )CLEANUP_SCRIPTr%   r&   textwrapdedentstriposlinesepSCRIPTformatIMPORTSSCRIPT_BODY)ry   rH   r|   r}   r~   r   s         r4   build_scriptzModuleSnapshot.build_script   s%    $,,KS)"//+6<<>K,,rzz9KGKK:CHOOI.446	<FX__Z0668B
'"**q.8;F
(
 . v	*! " "I zz  KK%%'oo'&&(! ! 
 	
r6   c                     t        j                  |      }|d   }t        j                  di |d   |d<   t        j                  di ||d<    | di |S )Nr.   r)   rT   )jsonloadsrv   rw   )ry   textrawrz   s       r4   parsezModuleSnapshot.parse  sW    jj(m//B#j/BJ--44HzSzr6   )pipec                F   || j                  ||||      S t        j                         }	 | j                  ||||      |\  }}t        j                  |       t        j                  |       S # |\  }}t        j                  |       t        j                  |       w xY wr=   )_from_subinterpr   r   close)ry   rH   interpidr   script_kwdsrws          r4   from_subinterpzModuleSnapshot.from_subinterp  s    &&tXt[IIwwy	&&tXt[IDAqHHQKHHQK DAqHHQKHHQKs   A/ /1B c                    |\  }}t        j                  d| d      }|j                  d      }|r(t        j                  |      j                         }||z  }|j	                         |d<    | j
                  |fi |}	|t        |	      }
|
dk7  r$t        |
 d      t        j                  ||	       t        j                  |d      }| j                  |j                               S )Nzq
            # Send the result over the pipe.
            import json
            import os
            os.write(z., json.dumps(snapshot).encode())

            r~   r   z != 0  )r   r   ru   lstripr   r   r   AssertionErrorrk   
run_stringr   readr   decode)ry   rH   r   r   script_kwargsr   r   r~   _postscriptscriptretr   s               r4   r   zModuleSnapshot._from_subinterp   s    1 __ * S 	& 
 $''5"//+6==?K+%J&0&6&6&8l#!!!$8-8 "6*Cax$uE]33$$Xv6 wwq$yy''r6   r=   )__name__
__module____qualname____doc__tuplesplit_fieldsclassmethodr{   r   r   r   r   r   r   r   r   r   r   r   rT   r6   r4   rn   rn      s   $ 9??ABG

 

 X__  F hoo  UW  "(// # " UW# $ %X__ &  UW 
 #"' $!&	#
 #
J   	 	 	 ( (r6   rn   c                   h   e Zd Zd Zd Zd Zd Zd Zd Ze	d        Z
d Zd	 Zd
 Zd Zd Zd Zd#dZd Zd Zd Zd Zed        Zd Zd Zed        Zd Ze	d        Zd Zd Zd Ze	d        Z  e!jD                         d        Z# e$jJ                  e&jN                  dk(  d      d         Z(d! Z)y")$ImportTestsc                 J    t        t               t        j                          y r=   )rJ   r   	importlibinvalidate_cachesrO   s    r4   setUpzImportTests.setUpB  s    V##%r6   c                 "    t        t               y r=   )r   r   r   s    r4   tearDownzImportTests.tearDownF  s	    vr6   c                 `    | j                  t              5  dd l}d d d        y # 1 sw Y   y xY wNr   )assertRaisesModuleNotFoundError(something_that_should_not_exist_anywhererO   r   s     r4   &test_import_raises_ModuleNotFoundErrorz2ImportTests.test_import_raises_ModuleNotFoundErrorI  s)    23 	<;	< 	< 	<   $-c                 d    | j                  t              5  ddlm} d d d        y # 1 sw Y   y xY w)Nr   )blah)r   r   r   r   )rO   r   s     r4   :test_from_import_missing_module_raises_ModuleNotFoundErrorzFImportTests.test_from_import_missing_module_raises_ModuleNotFoundErrorM  s-    23 	FE	F 	F 	F   &/c                 d    | j                  t              5  ddlm} d d d        y # 1 sw Y   y xY w)Nr   )r   )r   ImportErrorr   r   r   s     r4   0test_from_import_missing_attr_raises_ImportErrorz<ImportTests.test_from_import_missing_attr_raises_ImportErrorQ  s,    {+ 	KJ	K 	K 	Kr   c                    t        d      5  dd l}| j                  t              5 }ddlm} d d d        d d d        | j                  j                  j                  d       | j                  |j                  j                  j                         | j                  t        |j                        d       y # 1 sw Y   xY w# 1 sw Y   xY w)Nr   r   i_dont_existz7cannot import name 'i_dont_exist' from 'os' \(.*os.py\))r   r   r   r   r   assertEqual	exceptionrH   pathr`   assertRegexr&   )rO   r   cmr   s       r4   /test_from_import_missing_attr_has_name_and_pathz;ImportTests.test_from_import_missing_attr_has_name_and_pathU  s     	,"";/ ,2+,	, 	**D1**BKK8R\\*,fg	, ,	, 	,s!   CB9C9C	>CCc                    dd l }| j                  t              5 }ddl m} d d d        | j	                  j
                  j                  d       t        |d      rV| j	                  |j
                  j                  |j                         | j                  t        |j
                        d       y | j	                  t        |j
                        d       y # 1 sw Y   xY w)Nr   r   	_testcapir`   zCcannot import name 'i_dont_exist' from '_testcapi' \(.*\.(so|pyd)\)zEcannot import name 'i_dont_exist' from '_testcapi' (unknown location))r   r   r   r   r   r   rH   hasattrr   r`   r   r&   )rO   r   r   r   s       r4   2test_from_import_missing_attr_has_name_and_so_pathz>ImportTests.test_from_import_missing_attr_has_name_and_so_path^  s    {+ 	/r.	/**K89j)R\\..	0B0BCBLL!V
 BLL!W	/ 	/s   CC c                     | j                  t              5 }ddlm} d d d        | j	                  j
                  j                  d       | j                  |j
                  j                         y # 1 sw Y   UxY w)Nr   r   _warning)	r   r   r   r   r   r   rH   assertIsNoner   rO   r   r   s      r4   &test_from_import_missing_attr_has_namez2ImportTests.test_from_import_missing_attr_has_namep  s^    {+ 	.r-	. 	**J7",,++,		. 	.s   A11A:c                     | j                  t              5 }ddlm} d d d        | j	                  j
                  j                  ddh       | j                  |j
                         y # 1 sw Y   MxY w)Nr   r   	posixpathntpath)r   r   os.pathr   assertInr   rH   assertIsNotNoner   s      r4   /test_from_import_missing_attr_path_is_canonicalz;ImportTests.test_from_import_missing_attr_path_is_canonicalw  sY    {+ 	-r,	-bll''+x)@AR\\*	- 	-s   A))A2c                    dd l }t               5 \  }}t        |dd      5 }|j                  d       d d d        i }| j	                  t
        |j                  |       d      5  t        d| d|       d d d        | j                  d	|       d d d        t               5 \  }}t        |dd      5 }|j                  d
       d d d        i }| j	                  t
        |j                  |       d      5  t        d| d|       d d d        | j                  d	|       d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   TxY w# 1 sw Y   y xY w)Nr   r   utf-8encodingz__all__ = [b'invalid_type']z\.__all__ must be strzfrom z	 import *s   invalid_typez%globals()[b'invalid_type'] = object()z\.__dict__ must be str)	rer   openwriteassertRaisesRegex	TypeErrorescapeexecassertNotIn)rO   r   rH   r   rI   globalss         r4   "test_from_import_star_invalid_typez.ImportTests.test_from_import_star_invalid_type}  s|    	7,4dC'2 7a567G''biio..DE 7 uTF),g67 _g6	7  	7,4dC'2 Aa?@AG''biio..EF 7 uTF),g67 _g6	7 	77 77 7		7 	7A A7 7		7 	7su   ED,2E%D86E"E(4E2E(8E	E(,D5	1E8E	=EEE	E(E%	!E((E1c                 `    | j                  t              5  dd l}d d d        y # 1 sw Y   y xY wr   )r   r   RAnDoM)rO   r   s     r4   test_case_sensitivityz!ImportTests.test_case_sensitivity  s*     {+ 		 	 	r   c                 2    ddl m} t        d       ddl m} y )Nr   )double_constz"test.test_import.data.double_const)test.test_import.datar   r   )rO   r   s     r4   test_double_constzImportTests.test_double_const  s     	7346r6   c                 (     fd}t         j                  j                  dt        j                         	  |d       t         j
                  j                  d      rdD ]
  } ||        t         j                  d= y # t         j                  d= w xY w)Nc                 2   t         | z   }t         dz   }t        |dd      5 }t        d| d|       t        j                  d      }t        j                  d      }t        d	||       t        d
||       d d d        t         t
        j                  v rt
        j                  t         = t        j                          	 	 t        t               }j                  j                  d|z         j                  |j                  d|z         t        t                t!        |       t!        |       y # 1 sw Y   xY w# t        $ r!}j                  d| d|       Y d }~d }~ww xY w# t        t                t!        |       t!        |       w xY w)NrE   r   r   r   z)# This tests Python's ability to import azfile.filer   za =zb =zimport from z	 failed: z'module loaded (%s) but contents invalid)r   r   printrandom	randrangerZ   r[   r   r   r'   r   failr   abr   r   )	extsourcepycrI   r   r  rz   r3   rO   s	           r4   test_with_extensionz4ImportTests.test_import.<locals>.test_with_extension  sS   c\F6/CfcG4 (A7,$$T*$$T*eQQ'eQQ'( $KK''')H$V,C   =CE  =CE vvs1( ( # HIIS#FGGH vvss=   AD6E A E/ 6D?	E,E'"E/ 'E,,E/ /'Fr   rD   win)z.PYz.Pyz.pYrF   z.PYWz.pYw)rZ   r   insertr   curdirplatform
startswith)rO   r  r  s   `  r4   test_importzImportTests.test_import  so    	> 	299%	&||&&u-H -C',- s   6A> >Bc                 `   |dz   }t        |dd      5 }|j                  d       t        d      D ]  }|j                  d        |j                  d       d d d        	 t        j                  |       t        |       t        j                  j                  d	       t        j                          i }	 t        |       t        d
|z   d |       t        j                  d= t        |dz          t        |dz          |j                          	 t        j                  |= y # 1 sw Y   xY w# t        |       w xY w# t        $ r Y y w xY w# t        j                  d= t        |dz          t        |dz          |j                          	 t        j                  |= w # t        $ r Y w w xY wxY w)NrD   r   r   r   zd = [
i  z"",
]r   zimport co)r   r   range
py_compilecompiler   rZ   r   appendr   r   r   r   clearr[   KeyError)rO   r.   filenamerI   i	namespaces         r4   test_module_with_large_stackz(ImportTests.test_module_with_large_stack  sx   E> (C'2 	aGGI5\ ! !GGCL			 x(8 	##%		H%V#T95 8c>"8c>" OOKK'?	 	 8*   8c>"8c>" OOKK' sZ   AD"!D. 7E D> "D+.D;>	E
	E
>F-FF-	F*'F-)F**F-c                 z   t         dz   }t        |dd      5 }t        d|       d d d        t        j                  j                  dt        j                         t        j                          t         t        j                  v rt        j                  t         = 	 dD ]I  }| j                  t        t        t                | j                  t         t        j                  d	|z         K 	 t        j                  d= t        t                y # 1 sw Y   xY w# t        j                  d= t        t                w xY w)
NrD   r   r   r   za = 1/0r   r   )   r      z'damaged module in sys.modules on %i try)r   r   r   rZ   r   r  r   r  r   r   r[   r   ZeroDivisionErrorr'   r   rJ   )rO   r  rI   r  s       r4   test_failing_import_sticksz&ImportTests.test_failing_import_sticks  s    %&#0 	%A)!$	%
 	299%##%S[[ F#	! P!!"3ZH  !JQ!NPP
  !	% 	%  s   DAD D"D:c                     dd l }dd l}| j                  |||j                         | j	                  t        |j                  d             dd lm} | j                  ||j                  |j                         y )Nr   r`   )testtest.supportassertIsr   
assertTruer   support)rO   xr!  ys       r4   test_import_name_bindingz$ImportTests.test_import_name_binding  sP    aqzz*j9: 	!aqzz2r6   c                     	 d}dd l mc m} d}|dk  rdd l mc m} |dz  }|dk  rt        d      D ]  }dd l mc m}  y # dd l mc m} w xY w)N.r   
   r  r   )test.support.script_helperr%  r   r  )rO   r&  r  s      r4   test_issue31286zImportTests.test_issue31286  s]    	3A22 "f22FA "f
 q 	3A22	3 32s   A Ac                 N   t         t        j                  z   dz   }t        |dd      5 }|j	                  d       d d d        t
        j                  j                  dt        j                         	 t        t               }| j                  t         t
        j                         | j                  |j                  dd       | j                  |j                  d	d       t        t                t        |dd      5 }|j	                  d
       d d d        | j!                  t"        t$        j&                  |       t
        j                  j)                  t               }| j+                  |d       | j                  |j                  dd       | j                  |j                  d	d       t
        j                  d= t        t                t-        t                y # 1 sw Y   xY w# 1 sw Y   xY w# t
        j                  d= t        t                t-        t                w xY w)Npyr   r   r   z
a = 1
b=2
r   r  z!module has wrong attribute valuesr   za = 10
b=20//0
z$expected module to be in sys.modulesr*  )r   r   extsepr   r   rZ   r   r  r  r'   r   r[   r   r   r  rJ   r   r  r   reloadru   r   r   )rO   r  rI   rz   s       r4   test_failing_reloadzImportTests.test_failing_reload!  s   "))#d*&#0 	$AGGN#	$ 	299%	V$CMM&#++.SUUA'JKSUUA'JK   fcG4 -+,- /1A1A3G++//&)C  &LM SUUB(KLSUUA'JK  6NC	$ 	$"- -  6Ns1   G2B
G3 <G'BG3 G$'G0,G3 31H$c                    t         dz   }t        |dd      5 }|j                  d       d d d        t        j                  j                  dt        j                         	 t        t               }| j                  |j                  j                  d             t        j                  |       t        j                  t         = t        |       t        j                           t        t               }t        j                  j#                  |j                        \  }}| j%                  |d       t        j                  d= t'        t                t         t        j                  v rt        j                  t         = y y # 1 sw Y   UxY w# t        j                  d= t'        t                t         t        j                  v rt        j                  t         = w w xY w)NrD   r   r   r   ztest = None
r   rE   )r   r   r   rZ   r   r  r   r  r'   r$  r`   endswithremover[   r   r   r   splitextr   rJ   )rO   r  rI   rz   baser  s         r4   test_file_to_sourcezImportTests.test_file_to_sourceG  sC    %&#0 	%AGGO$	% 	299%	(V$COOCLL11%89IIfF#F#'')V$C((6ID#S&) $KK' %#	% 	%  $KK' %s   E=!CF
 =F
AGc                 ^   t         j                  j                  t              }t	        j
                         }	 |j                  |       | j                  t              5 }t        |       d d d        y # t        $ r# | j                  dj                  |             Y Uw xY w# 1 sw Y   y xY w)Nzpath is not encodable to {})r   r   abspathr   rZ   getfilesystemencodingencodeUnicodeEncodeErrorrN   r   r   r   r'   )rO   r   r   r  s       r4   test_import_by_filenamez#ImportTests.test_import_by_filename_  s    wwv&,,.	JKK! {+ 	qt	 	 " 	JMM7>>xHI	J	 	s   A4 B#4)B B #B,c                     t        j                  dt        t        j                  d            }t        j
                  |       y )Nr   z            import sys
            class C:
               def __del__(self):
                  import importlib
            sys.argv.insert(0, C())
            )r   make_scriptr   r   r   assert_python_ok)rO   testfns     r4   !test_import_in_del_does_not_crashz-ImportTests.test_import_in_del_does_not_crashi  s7    **2vx H 8  	&&v.r6   c                    t         j                  j                  dt        j                         	 t
        dz   }t        j                  j                  |      }t        |dd      5 }	 d d d        	 t        j                  |d       t#        t
               t        j$                  |       t         j                  d= t'        t
               y # 1 sw Y   exY w# t        $ r | j                  d       Y mt        $ rY}|j                  t        t        dd       t        t        d	d       fvr | j                  d
j!                  |             Y d }~d }~ww xY w# t         j                  d= t'        t
               w xY w)Nr   rD   r   r   r   )    rD  z-cannot set modification time to large integer	EOVERFLOWEINVALz2cannot set modification time to large integer ({}))rZ   r   r  r   r  r   r   utilcache_from_sourcer   utimeOverflowErrorrN   OSErrorerrnogetattrr   r'   statrJ   )rO   r  compiledrI   es        r4   test_timestamp_overflowz#ImportTests.test_timestamp_overflowt  s(    	299%	!e^F ~~77?HfcG4 ^!;< vGGH !  ! OMN ^7775+t#D#*5(D#A#C CRYYZ[\]]	^  sZ   6E &C(E 1C $E CE E2E 4E<AEE EE "E:c                 b    	 t        ddg       y # t        $ r | j                  d       Y y w xY w)Nhttpr   )fromlistzfromlist must allow bogus names)r'   r   r   r   s    r4   test_bogus_fromlistzImportTests.test_bogus_fromlist  s/    	9v1 	9II78	9s    ..c                 z    ddg}t        j                  | }|j                         \  }}| j                  d|       y )N-cz&del __builtins__.__import__; import oss   ImportError)r   spawn_pythoncommunicater   )rO   argspopenstdoutstderrs        r4   test_delete_builtins_importz'ImportTests.test_delete_builtins_import  s=    >?**D1**,nf-r6   c                 f    | j                  t        d      5  ddlm} d d d        y # 1 sw Y   y xY w)Nz^No module named 'bogus'r   )foo)r   r   bogusr`  )rO   r`  s     r4   /test_from_import_message_for_nonexistent_modulez;ImportTests.test_from_import_message_for_nonexistent_module  s+    ##K1KL 	"!	" 	" 	"   '0c                 f    | j                  t        d      5  ddlm} d d d        y # 1 sw Y   y xY w)Nz^cannot import name 'bogus'r   )ra  )r   r   r   ra  )rO   ra  s     r4   ,test_from_import_message_for_existing_modulez8ImportTests.test_from_import_message_for_existing_module  s+    ##K1NO 	! 	! 	! 	!rc  c                 "    G d d      }d}| j                  t        |        |       t        j                  |<   | j	                  t
              5 }ddlm} d d d        | j                  t        j                        d       y # 1 sw Y   /xY w)Nc                       e Zd Zd Zy)IImportTests.test_from_import_AttributeError.<locals>.AlwaysAttributeErrorc                     t         r=   )AttributeError)rO   _s     r4   __getattr__zUImportTests.test_from_import_AttributeError.<locals>.AlwaysAttributeError.__getattr__  s    $$r6   N)r   r   r   rl  rT   r6   r4   AlwaysAttributeErrorrh    s    %r6   rm  test_from_import_AttributeErrorr   does_not_existzScannot import name 'does_not_exist' from '<unknown module name>' (unknown location))
addCleanupr   rZ   r[   r   r   rn  rp  r   r&   r   )rO   rm  module_namer   rp  s        r4   rn  z+ImportTests.test_from_import_AttributeError  s}    	% 	% 8,#7#9K {+ 	GrF	G 	R\\*a	c	G 	Gs   BBc                 $   t        t        dd       5  | j                  t              5  ddlm} d d d        | j                  t
              5  t        j                   d d d        d d d        y # 1 sw Y   @xY w# 1 sw Y   xY w# 1 sw Y   y xY w)Nr   r   ro  )r   r   r   r   rp  rj  )rO   rp  s     r4   test_issue31492zImportTests.test_issue31492  s~    
 r:t, 	""";/ .-. "">2 "!!"		" 	". ." "		" 	"s9   BA.BA:B.A7	3B:B	?BBc                    d t         j                  j                  dt        j                  j	                  t        j                  j                  t              d             	 d fd}t        d      D ]  }t        j                         t        d      D cg c]  }t        j                  |       }}	 t        j                  |j                        5  t        j                  d       d d d        t         j                   j#                  dd        t         j                   j#                  d	d        ŉ 	 t         j                  d= y c c}w # 1 sw Y   gxY w# t         j                   j#                  dd        t         j                   j#                  d	d        w xY w# t         j                  d= w xY w)
Nc                 n    |dk(  r0| j                   j                  dk(  rt        j                  d       y y y )Ncallhas_deadlockg?)f_codeco_nametimesleep)frameeventargs      r4   delay_has_deadlockz8ImportTests.test_concurrency.<locals>.delay_has_deadlock  s-    5<<#7#7>#I

3 $Jr6   r   datac                      t        j                         j                          	 dd l} t        j                  d        y # t        $ r}|Y d }~&d }~ww xY wr   )rZ   settracewaitpackageBaseException)r  rP  r  r~  excs     r4   runz)ImportTests.test_concurrency.<locals>.run  sF    /0

" T" % Cs   A 	AAAr*  r   )targetr  zpackage.submodule)rZ   r   r  r   joindirnamer`   r  	threadingEventThreadr   start_threadssetr{  r|  r[   r\   )rO   r  r  r&  threadsr  r~  r  s        @@@r4   test_concurrencyzImportTests.test_concurrency  s=   	  	277<<(A6JK	C# 2Y 
!)AFqJA9++37JJ?)77K &

1& KKOOIt4KKOO$7>?I
  K& & KKOOIt4KKOO$7> sV   '8F, E<F, ? E'E5E'=AF,  F, F, E$	 E''AF))F, ,F?win32Windows-specificc                 n   ddl m}  |t        j                        }t        j
                  j                  d      j                  }t        j                  j                  t        j                  j                  |      dj                  d|v rdnd            }t        j                         5 }t        j                  j                  |d      }t        j                  |       t        j                  j                  |t        j                  j!                  t        j"                              }t%        j&                  t        j"                  |       t%        j&                  ||       t)        j(                  t        j                  j                  t)        j*                  t        j,                        d            D ]  }t%        j&                  ||        t%        j&                  ||       d }	t        j.                  D 
ci c]$  }
|
j1                         t        j.                  |
   & }	}
|d	z   t2        z   |	d
<   t5        j6                  |dd	j                  ddj                  t        j                  j                  |            ddg      gt4        j8                  |	t        j                  j                  |             t%        j&                  ||       t5        j6                  |ddgt4        j8                  |	t        j                  j                  |             d d d        y c c}
w # 1 sw Y   y xY w)Nr   )GetModuleFileName_sqlite3zsqlite3{}.dll_dr   DLLszvcruntime*.dll;
PYTHONPATHz-Scz	import oszp = os.add_dll_directory({!r})zimport _sqlite3zp.close)r]  envcwd)_winapir  rZ   	dllhandler   rG  	find_specr9   r   r   r  r  r   r	   temp_dirmkdirbasename
executableshutilcopyglobr   prefixenvironupperr
   
subprocess
check_callSTDOUT)rO   r  dllnamepydnamedepnametmptmp2pyexerI   r  ks              r4   test_dll_dependency_importz&ImportTests.test_dll_dependency_import  sJ   -#CMM2..**:6=='',,GGOOG$""47?4CE ! "	@S77<<V,DHHTNGGLLbgg&6&6s~~&FGEKK.KK%YYrww||DKK

,CEUVW $As#$ KK&C57ZZ@1779bjjm+@C@ $s
Z 7C !!uchh4;;02%( # "((GGOOE*
, KK&!!5%1B"C+5+<+<(+(*(>@?"	@ "	@ A"	@ "	@s    ,EL+ )L&)C4L+&L++L4c                     | j                  t              5 }t        j                  dd       d d d        | j	                  dt        j                               y # 1 sw Y   /xY w)Nr&  s   6'Cuz"Frozen object named 'x' is invalid)r   r   _impget_frozen_objectr   r&   r   )rO   r   s     r4   test_issue105979zImportTests.test_issue105979  sS    {+ 	:r""3(89	::",,'	)	: 	:s   AA$N)longlist)*r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r(  r,  r1  skip_if_dont_write_bytecoder7  r=  rB  rQ  rU  r^  rb  re  rn  rt  r   requires_working_threadingr  r+   
skipUnlessrZ   r	  r  r  rT   r6   r4   r   r   @  s7   &<FKh  "-+7*7'R&P!(	33"$L !( !(.	/ !! !!29 . ."!c  	" 	" 1002  3 D X02DE*@ F*@X)r6   r   c                   f   e Zd Z ej                  ej                  dk(  d       ej                  exs e	d      d               Z
 ej                  ej                  dk(  d      ej                  d               Z ej                  ej                  dk(  d      ej                  d               Zd Zy)	FilePermissionTestsposix%test meaningful only on posix systemsz$Emscripten's/WASI's umask is a stub.c                    d}t        |      5  t               5 \  }}t        j                  j	                  |      }t        |      }t        j                  j                  |      s| j                  d       t        j                  |      }d d d        d d d        | j                  t        t        j                  j                              t        d| z               y # 1 sw Y   WxY w# 1 sw Y   [xY w)N   4__import__ did not result in creation of a .pyc filei  )r   r   r   rG  rH  r'   r   r   existsr   rN  r   octS_IMODEst_mode)rO   maskrH   r   cached_pathr.   	stat_infos          r4   test_creation_modez&FilePermissionTests.test_creation_mode  s      	-0 	-LT4#..::4@K%F77>>+.		 ( ),I	- 	- 	T\\)*;*;<=UdU]+	-	- 	- 	- 	-s#   C.A3C"C."C+	'C..C7c                    d}t        d      5  t               5 \  }}t        j                  j	                  |      }t        j                  ||       t        |       t
        j                  j                  |      s| j                  d       t        j                  |      }d d d        d d d        | j                  t        t        j                  j                              t        |             y # 1 sw Y   SxY w# 1 sw Y   WxY w)N  r  r  r   r   r   rG  rH  r   chmodr'   r   r  r   rN  r   r  r  r  )rO   moderH   r   r  r  s         r4   test_cached_mode_issue_2051z/FilePermissionTests.test_cached_mode_issue_20510  s    
  	- 1 	-\dD#..::4@KHHT4 t77>>+.		 ( ),I	- 	- 	T\\)*;*;<=s4yI	- 	- 	- 	-s#   D B	C4"D 4C=	9D  D	c                 "   d}t        d      5  t               5 \  }}t        j                  j	                  |      }t        j                  ||       t        |       t
        j                  j                  |      s| j                  d       t        j                  |      }d d d        d d d        |dz  }| j                  t        t        j                  j                              t        |             y # 1 sw Y   XxY w# 1 sw Y   \xY w)N   r  r     r  )rO   r  rH   r   r  r  r1   s          r4   test_cached_readonlyz(FilePermissionTests.test_cached_readonlyA  s      	- 1 	-\dD#..::4@KHHT4 t77>>+.		 ( ),I	- 	- %<T\\)*;*;<=s8}M	- 	- 	- 	-s#   DB	C9"D9D	>DDc                    t               5 \  }}t        |dd      5 }|j                  d       d d d        t        j                  |      }t        j
                  ||j                  |j                  dz
  f       t        j                  |d       t        |      }| j                  |j                  d       t        j                  |d       t        |dd      5 }|j                  d	       d d d        t        |       t        j                          t        |      }| j                  |j                  d
       t        |       t        |       t        j                          |dz   }t        j                   t        j"                  j%                  |      |       t        |      }| j                  |j                  d
       d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)Nr   r   r   zx = 'original'
i r  originalr  zx = 'rewritten'
	rewrittenr  )r   r   r   r   rN  rI  st_atimest_mtimer  r'   r   r&  r   r   r   r   renamerG  rH  )rO   rH   r   rI   smbytecode_onlys          r4   test_pyc_always_writablez,FilePermissionTests.test_pyc_always_writableR  s     	/,4dC'2 ,a*+, AHHTAJJ

9(<=>HHT5!4 AQSS*-HHT5!dC'2 -a+,-4L'')4 AQSS+.4L4L'') 3JMIIinn66t<mL4 AQSS+.3	/ 	/, ,- -	/ 	/s;   G'GB-G'G.CG'G	G'G$	 G''G0N)r   r   r   r+   r  r   rH   rg   r   r   r  r	   skip_unless_working_chmodr  r  r  rT   r6   r4   r  r    s     XG+@BX__ .-	B- XG+@B((J )BJ XG+@B((N )BN/r6   r  c                      e Zd ZdZdZej                  j                  e      Z	ej                  j                  e	e      ej                  z   dz   Zej                  j                  e      Zd Zd Zd Zd Zd Zd	 Zd
 Zy)PycRewritingTestsunlikely_module_namez
import sys
code_filename = sys._getframe().f_code.co_filename
module_filename = __file__
constant = 1
def func():
    pass
func_filename = func.__code__.co_filename
r.  c                    t         j                  d d  | _        t         j                  j	                  | j
                  d       | _        t        j                  | j                         t        | j                  dd      5 }|j                  | j                         d d d        t         j                  j                  d| j                         t        j                           y # 1 sw Y   HxY w)Nr   r   r   r   )rZ   r   sys_pathr[   r\   rr  orig_moduler   r  dir_namer   	file_namer   module_sourcer  r   r   )rO   rI   s     r4   r   zPycRewritingTests.setUp  s    ;;??4+;+;TB
$..#8 	(AGGD&&'	(4==)##%	( 	(s   ?C""C+c                 N   | j                   t        j                  d d  | j                  (| j                  t        j                  | j
                  <   nt        | j
                         t        | j                         t        | j                         t        | j                         y r=   )r  rZ   r   r  r[   rr  r   r   r  compiled_namer   r  r   s    r4   r   zPycRewritingTests.tearDown  sm    mm',0,<,<CKK(()4##$t~~t!!"t}}r6   c                 ~    t               }t        | j                  ||       t        j                  | j                     S r=   )r   r'   rr  rZ   r[   )rO   rq   s     r4   import_modulezPycRewritingTests.import_module  s0    Y4##R,{{4++,,r6   c                 B   | j                         }| j                  |j                  | j                         | j                  |j                  | j                         | j                  |j
                  | j                         t        j                  | j                  = | j                         }| j                  |j                  | j                         | j                  |j                  | j                         | j                  |j
                  | j                         y r=   )	r  r   module_filenamer  code_filenamefunc_filenamerZ   r[   rr  rO   rz   s     r4   test_basicszPycRewritingTests.test_basics  s      ",,dnn=**DNN;**DNN;KK(()  ",,dnn=**DNN;**DNN;r6   c                 J   t        j                  | j                  d       | j                         }| j	                  |j
                  | j                         | j	                  |j                  | j                         | j	                  |j                  | j                         y Nzanother_module.py)dfile)r  r  r  r  r   r  r  r  r  s     r4   test_incorrect_code_namez*PycRewritingTests.test_incorrect_code_name  ss    4>>1DE  ",,dnn=**DNN;**DNN;r6   c                    d}t        j                  | j                  |       t        j                  | j                         t        | j                        }t        j                          | j                         }| j                  |j                  |       | j                  |j                  |       | j                  |j                  |       y r  )r  r  r  r   r4  r   r   r   r  r   r  r  r  )rO   r  pyc_filerz   s       r4   test_module_without_sourcez,PycRewritingTests.test_module_without_source  s    $4>>8
		$..!"4>>2##%  ",,h7**F3**F3r6   c                    t        j                  | j                         t        | j                  d      5 }|j                  d      }t        j                  |      }d d d        t        j                        }t        j                  j                  }|j                  d      }|||<   |j                  t        |            }t        | j                  d      5 }|j!                         t        j"                  ||       d d d        | j                         }| j%                  |j&                  j(                  |j(                         y # 1 sw Y   xY w# 1 sw Y   VxY w)Nrb   r  )	co_constswb)r  r  r  r   r  r   marshalloadlistr  r   r  __code__indexreplacer   r   dumpr   constantco_filename)rO   rI   headercode	constantsforeign_codeposrz   s           r4   test_foreign_codez#PycRewritingTests.test_foreign_code  s   4>>*$$$d+ 	#qVVBZF<<?D	# (	 ..77ooa %	#||eI&6|7$$$d+ 	"qGGFOLLq!	"   "11<3K3KL	# 	#	" 	"s   'E(EEE!N)r   r   r   rr  r  r   r   r9  r   r  r  r/  r  r   rG  rH  r  r   r   r  r  r  r  r  rT   r6   r4   r  r  q  s~    
 )KM wwv&HX{3bii?$FINN44Y?M&-
	<<	4Mr6   r  c                   r    e Zd ZdZeZd Zd Zd Z e	j                  ej                  dk(  d      d        Zy)	
PathsTests)r!  u   testäöüßu   testéèu
   test°³²c                 r    t        j                  | j                         t        j                  d d  | _        y r=   )r   r  r   rZ   syspathr   s    r4   r   zPathsTests.setUp  s!    
xx{r6   c                 h    t        | j                         | j                  t        j                  d d  y r=   )r   r   r  rZ   r   s    r4   r   zPathsTests.tearDown  s    tyyllr6   c                 x   t        t        j                  j                  | j                  d      dd      5 }|j	                  d       d d d        t
        j                  j                  | j                  dz          t        d      }| j                  |j                  d       t        d       y # 1 sw Y   hxY w)Nztest_trailing_slash.pyr   r   r   z testdata = 'test_trailing_slash'/test_trailing_slash)r   r   r   r  r   rZ   r  r'   r   testdatar   )rO   rI   rz   s      r4   r  zPathsTests.test_trailing_slash  s    "'',,tyy*BC) 	8,-GG67	8 			#&./'<=$%	8 	8s   B00B9r  r  c                    t        t        j                  j                  | j                  d      d      5 }|j	                  d       d d d        t        j                          t        j                  j                  | j                        }dd l}|j                         }|d   }d|d|d}||dd  z  }	 t        j                  |       t"        j                  j%                  d|       	 t'        d
      }| j-                  j.                  d
       | j1                  |j2                  j5                  |      |j2                         t7        d
       y # 1 sw Y   xY w# t        $ rU}|j                  t        j                  t        j                  t        j                  fv r| j!                  d	|        d }~ww xY w# t(        $ r!}| j+                  d|d|       Y d }~d }~ww xY w)Nztest_unc_path.pyr   ztestdata = 'test_unc_path'r   z\\\$r   z#cannot access administrative share test_unc_pathz&could not import 'test_unc_path' from z: )r   r   r   r  r   r   r   r9  socketgethostnamelistdirrK  rL  EPERMEACCESENOENTrN   rZ   r  r'   r   r   r   r  r$  r`   r
  r   )	rO   rI   r   r  hndriveuncrP  rz   s	            r4   test_UNC_pathzPathsTests.test_UNC_path  sy   "'',,tyy*<=sC 	2qGG01	2##%wwtyy)!Q'tABx	JJsO 	3	"_-C 	7//4cllC3	2 	2  	ww5;;ellCCNO		  	"IIa! " "	"s<   E7E" -G E"	G +AF;;G 	G-G((G-N)r   r   r   SAMPLESr   r   r   r   r  r+   r  rZ   r	  r&  rT   r6   r4   r  r    sK    )GD##
& X02DE  F r6   r  c                   F    e Zd Zd ZeZd Zd Zd Zd Zd Z	d Z
d Zd	 Zy
)RelativeImportTestsc                     t        d       y )Nztest.relimport)r   r   s    r4   r   zRelativeImportTests.tearDown  s     r6   c                 F    ddl m} | j                  t        |d             y )Nr   )	relimportr)  )r   r,  r$  r   )rO   r,  s     r4   test_relimport_starz'RelativeImportTests.test_relimport_star  s     	+@ABr6   c                 @   fd}t        dd       |        t        dd       |        t        dd      | j                  t        |       t        dd      | j                  t        |       t        t                     | j                  t        |       y )Nc                      t        d        y )Nzfrom . import relimport)r   )rq   s   r4   check_relativez:RelativeImportTests.test_issue3221.<locals>.check_relative  s    *B/r6   r!  ztest.notarealmodule)__package__r   znotarealpkg.notarealmoduler`  )r1  )dictr   r   objectr   )rO   r0  rq   s     @r4   test_issue3221z"RelativeImportTests.test_issue3221  s    	0 f/DE f/KL e.CD-~> e.JK-~> fh')^4r6   c                 4    t        j                  dddd       y )Nz-WignorerW  zfoo = 1; from . import foo)r   assert_python_failurer   s    r4   )test_parentless_import_shadowed_by_globalz=RelativeImportTests.test_parentless_import_shadowed_by_global(  s    ++D(D(	*r6   c                     | j                  t              5  ddlm} | j	                  d       d d d        y # 1 sw Y   y xY w)Nr  )sepz>explicit relative import triggered an implicit absolute import)r   r   r   r:  r   )rO   r:  s     r4   #test_absolute_import_without_futurez7RelativeImportTests.test_absolute_import_without_future-  s;     {+ 	2II 1 2	2 	2 	2s	   7A c                    t         j                  j                  t         j                  j                  t              dd      }t        dd      5  t        |      5  | j                  t              5  dd l	}d d d        | j                  dt        j                         | j                  dt        j                         d d d        d d d        y # 1 sw Y   ZxY w# 1 sw Y   xY w# 1 sw Y   y xY w)Nr  package2
submodule1
submodule2r   )r   r   r  r  r`   r   r   r   r   r>  r   rZ   r[   )rO   r   r>  s      r4   test_import_from_non_packagez0RelativeImportTests.test_import_from_non_package6  s    ww||BGGOOH5vzJ\<0 	8-2E 	8"";/ "!"\3;;7\3;;7		8 	8 	8" "	8 	8 	8 	8s=   C'C1C6AC>C'CCC$	 C''C0c                 :   t        ddd      5  t        t        j                  j	                  t        j                  j                  t              d            5  dd l}|j                  j                   d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nr=  zpackage2.submodule1zpackage2.submodule2r  r   )
r   r   r   r   r  r  r`   package2.submodule1r>  r?  )rO   r=  s     r4   !test_import_from_unloaded_packagez5RelativeImportTests.test_import_from_unloaded_package>  sp    Z!68MN 	+277<<(A6JK	+&**	+ 	+ 	+ 	+ 	+ 	+s$   ABB4BB	
BBc                    t         j                  j                  t         j                  j                  t              d      }t        dd      5  t        |      5  ddlm} | j                  |j                  d       dd lm} | j                  |j                  d       d d d        d d d        t        dd      5  t        |      5  dd lm} | j                  |j                  d       ddlm} | j                  |j                  d       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   *xY w# 1 sw Y   y xY w)Nr  package3zpackage3.submoduler   	submodulerebound)r   r   r  r  r`   r   r   rE  rG  r   attrpackage3.submodulerO   r   rG  s      r4   test_rebindingz"RelativeImportTests.test_rebindingD  s     ww||BGGOOH5v>Z!56 	8d8K 	8*Y^^Y72Y^^Y7		8 	8
 Z!56 	8d8K 	82Y^^Y7*Y^^Y7		8 	8 	8	8 	8 	8 	8
	8 	8 	8 	8J   D)ADD);EAD5ED&	"D))D25D>	:EE
c                    t         j                  j                  t         j                  j                  t              d      }t        dd      5  t        |      5  dd lm} | j                  |j                  d       ddlm} | j                  |j                  d       d d d        d d d        t        dd      5  t        |      5  ddlm} | j                  |j                  d       dd lm} | j                  |j                  d       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   *xY w# 1 sw Y   y xY w)Nr  package4zpackage4.submoduler   rG  rF  r9   )r   r   r  r  r`   r   r   package4.submodulerG  r   rI  rO  rK  s      r4   test_rebinding2z#RelativeImportTests.test_rebinding2S  s    ww||BGGOOH5v>Z!56 	:d8K 	:2Y^^[9*Y^^[9		: 	:
 Z!56 	:d8K 	:*Y^^X62Y^^[9		: 	: 	:	: 	: 	: 	:
	: 	: 	: 	:rM  N)r   r   r   r   r   r-  r4  r8  r;  r@  rC  rL  rQ  rT   r6   r4   r)  r)     s5    !EC
5:*
28+8:r6   r)  c                       e Zd Zd Zy)OverridingImportBuiltinTestsc                 @   dd l }d }| j                   |       |       t        t        dd       5  | j                   |       d       d d d        t	        t               dd       5  | j                   |       |       d d d        y # 1 sw Y   @xY w# 1 sw Y   y xY w)Nr   c                      dd l } | S r   r   rV  s    r4   r`  z?OverridingImportBuiltinTests.test_override_builtin.<locals>.foof  s
    Ir6   r'   c                       yN   rT   r&  s    r4   <lambda>zDOverridingImportBuiltinTests.test_override_builtin.<locals>.<lambda>k      r6   rY  c                       yrX  rT   rZ  s    r4   r[  zDOverridingImportBuiltinTests.test_override_builtin.<locals>.<lambda>q  r\  r6   )r   r   r   builtinsr   r   )rO   r   r`  s      r4   test_override_builtinz2OverridingImportBuiltinTests.test_override_builtinb  s    	 	#x|< 	'SUA&	' wy,= 	(SUB'	( 	(	' 	'	( 	(s   B'BBBN)r   r   r   r_  rT   r6   r4   rS  rS  a  s    (r6   rS  c                   >   e Zd Zd Zd Zd Zed        Z ej                  e
j                  dk(  d      eej                  ej                   ej                  ed      d                                    Zed	        Zed
        Zd Zed        Zed        Zd Zd Zy)PycacheTestsc                 b    t        t               t        d       t        | j                         y )NrG   )r   r   r   r   r  r   s    r4   _cleanzPycacheTests._cleanx  s    v}t{{r6   c                 8   t         dz   | _        | j                          t        | j                  dd      5 }t	        d|       d d d        t
        j                  j                  dt        j                         t        j                          y # 1 sw Y   LxY w)NrD   r   r   r   z/# This is a test file written by test_import.pyr   r   )r   r  rc  r   r   rZ   r   r  r   r  r   r   )rO   fps     r4   r   zPycacheTests.setUp}  sn    un$++sW5 	NC"M	N299%##%	N 	Ns   BBc                     t         j                  d   t        j                  k(  sJ d       t         j                  d= | j	                          y )Nr   zUnexpected sys.path[0])rZ   r   r   r  rc  r   s    r4   r   zPycacheTests.tearDown  s6    xx{bii'A)AA'HHQKr6   c                    | j                  t        j                  j                  d             t	        t
               | j                  t        j                  j                  d             t        j                  j                  | j                        }| j                  t        j                  j                  |      dj                  |t
                     y )NrG   z*bytecode file {!r} for {!r} does not exist)assertFalser   r   r  r'   r   r$  r   rG  rH  r  r   rO   pyc_paths     r4   test_import_pyc_pathz!PycacheTests.test_import_pyc_path  s    676}56>>33DKK@x0  &x 8	:r6   r  r  zumask is a stubc                    t        d      5  t        t               d d d        | j                  t        j
                  j                  d             t        j                  j                  | j                        }| j                  t        j
                  j                  |      dj                  |t                     y # 1 sw Y   xY w)N   rG   z"bytecode file {!r} for {!r} exists)r   r'   r   r$  r   r   r  r   rG  rH  r  rh  r   ri  s     r4   test_unwritable_directoryz&PycacheTests.test_unwritable_directory  s      	v	}56>>33DKK@1!!'&!9	;		 	s   B??Cc                    t        t               t        j                  j	                  | j
                        }| j                  t        j                  j                  |             t        j                  | j
                         t        t               t        j                          | j                  t        t         t               y r=   )r'   r   r   rG  rH  r  r$  r   r   r  r4  r   r   r   r   )rO   r  s     r4   test_missing_sourcez PycacheTests.test_missing_source  sr     	6>>33DKK@x01
		$++v##%+z6:r6   c           	          t        t               t        | j                        }t	        j
                  | j                         t        t               t        j                          t        t              }	 | j                  |j                  t        j                  j                  t	        j                         t        j                  j                  |                   t	        j
                  |       y # t	        j
                  |       w xY wr=   )r'   r   r   r  r   r4  r   r   r   r   r`   r   r  getcwdrelpathrO   r  r  s      r4   test_missing_source_legacyz'PycacheTests.test_missing_source_legacy  s     	6"4;;/
		$++v##%v	 QZZWW\\"))+rwwx7PQS IIhBIIhs   7A)C6 6Dc                    t        t              }t        j                  j	                  t        dz         }| j                  |j                  t        j                  j                  t        j                         |             y )NrD   )r'   r   r   rG  rH  r   
__cached__r   r   r  rr  )rO   r  r  s      r4   test___cached__zPycacheTests.test___cached__  sM    v>>33FUNCrww||BIIK'JKr6   c           	         t        t               t        | j                        }t	        j
                  | j                         t        t               t        j                          t        t              }| j                  |j                  t        j                  j                  t	        j                         t        j                  j                  |                   y r=   )r'   r   r   r  r   r4  r   r   r   r   rw  r   r  rr  rs  rt  s      r4   test___cached___legacy_pycz'PycacheTests.test___cached___legacy_pyc  s     	6"4;;/
		$++v##%vbiik277??83LM	Or6   c                    d }t        j                  d       | j                  |       t        t         j                  j                  dd      d      5  	 d d d        t        t         j                  j                  dd      d      5  	 d d d        t        j                          t        d      }t        j                  j                  t         j                  j                  dd            }| j                  |j                  t         j                  j                  t        j                         |             t        j                  j                  t         j                  j                  dd            }| j                  t        j                  d   j                  t         j                  j                  t        j                         |             y # 1 sw Y   xY w# 1 sw Y   ZxY w)Nc                  F    t        d       t        d       t        d       y Npep3147pep3147.foor   r   rT   r6   r4   cleanupz5PycacheTests.test_package___cached__.<locals>.cleanup      9=!9r6   r~  __init__.pyr   foo.pyr  )r   r  rq  r   r   r  r   r   r'   rG  rH  r   rw  rr  rZ   r[   rO   r  r  init_pycfoo_pycs        r4   test_package___cached__z$PycacheTests.test_package___cached__  sB   	 	 "'',,y-8$? 		"'',,y(3T: 		##%}%>>33GGLLM24rww||BIIK'JK..22277<<	83TU]3>>biik7;	=	 		 	s   GG"G"G,c                 H   d }t        j                  d       | j                  |       t        t         j                  j                  dd      d      5  	 d d d        t        t         j                  j                  dd      d      5  	 d d d        t        j                          t        d      }t        d       t        d       t        j                          t        d      }t        j                  j                  t         j                  j                  dd            }| j                  |j                  t         j                  j                  t        j                         |             t        j                  j                  t         j                  j                  dd            }| j                  t        j                   d   j                  t         j                  j                  t        j                         |             y # 1 sw Y   xY w# 1 sw Y   xY w)Nc                  F    t        d       t        d       t        d       y r}  r  rT   r6   r4   r  z>PycacheTests.test_package___cached___from_pyc.<locals>.cleanup  r  r6   r~  r  r   r  r  )r   r  rq  r   r   r  r   r   r'   r   rG  rH  r   rw  rr  rZ   r[   r  s        r4    test_package___cached___from_pycz-PycacheTests.test_package___cached___from_pyc  sh   	 	 "'',,y-8$? 		"'',,y(3T: 		##%}%}y##%}%>>33GGLLM24rww||BIIK'JK..22277<<	83TU]3>>biik7;	=	 		 	s   H
H
HH!c                 
   t        t               t        t               t        | j                  dd      5 }t        d|       d d d        t        t              }| j                  |j                  d       y # 1 sw Y   5xY w)Nr   r   r   zx = 5r   rY  )r'   r   r   r   r  r   r   r&  )rO   re  r  s      r4   test_recompute_pyc_same_secondz+PycacheTests.test_recompute_pyc_same_second  sb     	6v$++sW5 	$'#	$va 	$ 	$s   A99BN)r   r   r   rc  r   r   r  rk  r+   r  r   rH   r	   r  skip_if_dac_overriderg   r   rn  rp  ru  rx  rz  r  r  r  rT   r6   r4   ra  ra  u  s    
&
 !: !: XG+@B ((##X__]$56	; 7 $ ) !B	; !	; !	; !  ! $L !O !O != !=,=6!r6   ra  c                       e Zd ZdZedz   Zd Zd Z ej                   e	e
d       xs  e
j                         dk\  d      ej                  d               Zy	)
TestSymbolicallyLinkedPackagesamplez-taggedc                    t        j                  | j                         t        j                  | j                         t        j
                  d d  | _        t        j                  | j                         | j                  t         j                  | j                         t        j
                  j                  | j                  d      }t        j                  |       t        j
                  j                  |      sJ t        j                  | j                  | j                  d       | j                  t         j                  | j                         t        j                           | j#                  t        j
                  j%                  | j                        d       t        j
                  j'                  t        j
                  j                  | j                  d            sJ y )Nr  T)target_is_directory)r	   r   taggedpackage_namerZ   r   orig_sys_pathr   r  rq  r  create_empty_filer  symlinkr   r   r   r   isdirisfile)rO   	init_files     r4   r   z#TestSymbolicallyLinkedPackage.setUp  s.   %**+ XXa[ 		(($++6GGLLm<	##I.ww~~i((( 	

4;; 1 1tL	(($*;*;<##%t'8'894@ww~~bggll4+<+<mLMMMr6   c                 >    | j                   t        j                  d d  y r=   )r  rZ   r   r   s    r4   r   z&TestSymbolicallyLinkedPackage.tearDown2  s    ((r6   getwindowsversion)   r   zWindows Vista or later requiredc                 R   dgt         j                  d d  t        j                  j                  | j                        sJ t        j                  j                  t        j                  j                  | j                  d            sJ t        j                  | j                         y )N.r  )rZ   r   r   r  r  r  r   r  r   s    r4   test_symlinked_dir_importablez;TestSymbolicallyLinkedPackage.test_symlinked_dir_importable6  sp     eww~~d//000ww~~bggll4+<+<mLMMM 	 1 12r6   N)r   r   r   r  r  r   r   r+   r  r   rZ   r  r	   skip_unless_symlinkr  rT   r6   r4   r  r    sv    LI%FN.) XC,-- 	- 3  "f,)+ ""3 #	+
3r6   r  c                   $    e Zd Zd Zd Zd Zd Zy)ImportlibBootstrapTestsc                 L    t         j                  d   }| j                  |       y )N_frozen_importlib)rZ   r[   r$  r  s     r4   test_frozen_importlibz-ImportlibBootstrapTests.test_frozen_importlibI  s    kk-.r6   c                 4   ddl m} t        j                  d   }| j	                  ||       | j                  |j                  d       | j                  |j                  d       | j                  |j                  j                  d      |j                         y )Nr   )
_bootstrapr  zimportlib._bootstrapr   z_bootstrap.py)r   r  rZ   r[   r#  r   r   r1  r$  r`   r3  )rO   r  rz   s      r4   "test_frozen_importlib_is_bootstrapz:ImportlibBootstrapTests.test_frozen_importlib_is_bootstrapM  sl    (kk-.c:&'=>+6--o>Mr6   c                 4   ddl m} t        j                  d   }| j	                  ||       | j                  |j                  d       | j                  |j                  d       | j                  |j                  j                  d      |j                         y )Nr   )_bootstrap_external_frozen_importlib_externalzimportlib._bootstrap_externalr   z_bootstrap_external.py)r   r  rZ   r[   r#  r   r   r1  r$  r`   r3  )rO   r  rz   s      r4   4test_frozen_importlib_external_is_bootstrap_externalzLImportlibBootstrapTests.test_frozen_importlib_external_is_bootstrap_externalU  sn    1kk67c./'FG+6--.FGVr6   c                     ddl m} t        j                  d   }| j	                  |j
                  |j
                         y )Nr   )	machineryr  )r   r  rZ   r[   r#  
ModuleSpec)rO   r  rz   s      r4   test_there_can_be_only_onez2ImportlibBootstrapTests.test_there_can_be_only_one]  s.     	(kk-.i**CNN;r6   N)r   r   r   r  r  r  r  rT   r6   r4   r  r  E  s    NW<r6   r  c                   "    e Zd ZdZd Zd Zd Zy)GetSourcefileTestszTest importlib._bootstrap_external._get_sourcefile() as used by the C API.

    Because of the peculiarities of the need of this function, the tests are
    knowingly whitebox tests.

    c                     t        j                  d      5 }d|_        t        dz   }t        dz   }| j	                  t        |      |       d d d        y # 1 sw Y   y xY w)N*importlib._bootstrap_external._path_isfileTrE   rD   r   patchreturn_valuer   r   r   )rO   _path_isfiler   expects       r4   test_get_sourcefilez&GetSourcefileTests.test_get_sourcefilep  sW     ZZDE 	<(,L%F?De^F_T2F;		< 	< 	<s   5AAc                     t        j                  d      5 }d|_        t        dz   }| j	                  t        |      |       d d d        y # 1 sw Y   y xY w)Nr  FrE   r  )rO   r  r   s      r4   test_get_sourcefile_no_sourcez0GetSourcefileTests.test_get_sourcefile_no_sourcey  sN     ZZDE 	:(-L%F?D_T2D9	: 	: 	:s   ,AAc                 L    t         dz   }| j                  t        |      |       y )Nz.bad_ext)r   r   r   )rO   r   s     r4   test_get_sourcefile_bad_extz.GetSourcefileTests.test_get_sourcefile_bad_ext  s#     
".5r6   N)r   r   r   r   r  r  r  rT   r6   r4   r  r  f  s    <:6r6   r  c                       e Zd 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d Zd Zed        Z ej(                  ed      d        Zy)ImportTracebackTestsc                     t        j                  t               t        j                  d d  | _        t        j                  j                  dt               y r   )r   r  r   rZ   r   old_pathr  r   s    r4   r   zImportTracebackTests.setUp  s/    
6"r6   c                 \    | j                   t        j                  d d  t        t               y r=   )r  rZ   r   r   r   r   s    r4   r   zImportTracebackTests.tearDown  s    mmvr6   c                    t         j                  j                  t        ||z         }t	        |dd      5 }|j                  |       d d d        | j                  t        |       t        j                          |S # 1 sw Y   5xY w)Nr   r   r   )
r   r   r  r   r   r   rq  r   r   r   )rO   rz   contentsr  fnamerI   s         r4   create_modulez"ImportTracebackTests.create_module  sh    VS3Y/%w/ 	1GGH	$##%		 	s   A<<Bc                 :   g }|rL|j                   j                  }|j                  }|r||d   k7  r|j                  |       |j                  }|rL| j                  t        |      t        |      |       t        ||      D ]  \  }}| j                  ||        y )Nr  )	tb_framery  r	  r  tb_nextr   lenzipr   )rO   tbfilesdeduped_filesr  fnpats          r4   assert_tracebackz%ImportTracebackTests.assert_traceback  s    ;;%%D!!B B-*;$;$$R(B  	]+SZG=%0 	#GBMM#r"	#r6   c                     	 dd l }| j                  d       | j	                  t
        g       y # t        $ r}|j                  }Y d }~2d }~ww xY w)Nr   #ImportError should have been raised)nonexistent_xyzzyr   r   __traceback__r  r`   )rO   r  rP  r  s       r4   test_nonexistent_modulez,ImportTracebackTests.test_nonexistent_module  sF    	=$ II;<b8*-	  	!B	!s   / 	AA		Ac                     | j                  dd       	 dd l}| j                  d       | j                  t        dg       y # t        $ r}|j                  }Y d }~3d }~ww xY w)Nr`  zimport nonexistent_xyzzyr   r  r  )r  r`  r   r   r  r  r`   rO   r`  rP  r  s       r4   test_nonexistent_module_nestedz3ImportTracebackTests.test_nonexistent_module_nested  sZ    5"<=	= II;<b8X"67	  	!B	!   A 	A!AA!c                     | j                  dd       	 dd l}| j                  d       | j                  t        dg       y # t        $ r}|j                  }Y d }~3d }~ww xY w)Nr`  1/0r   )ZeroDivisionError should have been raisedr  r  r`  r   r  r  r  r`   r  s       r4   test_exec_failurez&ImportTracebackTests.test_exec_failure  sZ    5%(	C IIABb8X"67	 ! 	!B	!r  c                     | j                  dd       | j                  dd       	 dd l}| j                  d       | j                  t        ddg       y # t        $ r}|j                  }Y d }~4d }~ww xY w)	Nr`  z
import barbarr  r   r  r  bar.pyr  r  s       r4   test_exec_failure_nestedz-ImportTracebackTests.test_exec_failure_nested  sl    5,/5%(	C IIABb8Xx"@A	 ! 	!B	!s   A 	A4A//A4c                     | j                  dd       	 dd l}| j                  d       | j                  t        g       y # t        $ r}|j                  }Y d }~2d }~ww xY w)Nr`  zinvalid syntax is invalidr   z#SyntaxError should have been raised)r  r`  r   SyntaxErrorr  r  r`   r  s       r4   test_syntax_errorz&ImportTracebackTests.test_syntax_error  sW    5"=>	= II;<b8*-	  	!B	!s   A 	A 
AA c                 $   d}| j                  t        |       t        j                  j	                  t
        |      }t        j                  |       t        j                  j	                  |d      }t        |dd      5 }|j                  |       d d d        t        j                  j	                  |d      }t        |dd      5 }|j                  |       d d d        t        j                          ||fS # 1 sw Y   ixY w# 1 sw Y   -xY w)N_parent_foor  r   r   r   r  )rq  r   r   r   r  r   r  r   r   r   r   )rO   parentchildpkg_namepkg_path	init_pathrI   bar_paths           r4   _setup_broken_packagez*ImportTracebackTests._setup_broken_package  s     )77<<1
GGLL=9	)S73 	qGGFO	77<<(3(C'2 	aGGEN	##%(""	 		 	s    C:D:DDc                     | j                  dd      \  }}	 dd l}| j                  d       | j                  t        |g       y # t        $ r}|j                  }Y d }~3d }~ww xY w)Nr   r  r   r  r  _parent_foo.barr   r  r  r  r`   rO   r  r  r  rP  r  s         r4   test_broken_submodulez*ImportTracebackTests.test_broken_submodule  sa    "88UC	8	C" IIABb8X"67	 ! 	!B	!   A 	A$AA$c                     | j                  dd      \  }}	 ddlm} | j                  d       | j                  t        |g       y # t        $ r}|j
                  }Y d }~3d }~ww xY w)Nr   r  r   r  r  r  r  r  r   r  r  r  r`   rO   r  r  r  rP  r  s         r4   test_broken_fromz%ImportTracebackTests.test_broken_from  s`    "88UC	8	=' II;<b8X"67	 ! 	!B	!   A 	A&A!!A&c                     | j                  dd      \  }}	 dd l}| j                  d       | j                  t        |g       y # t        $ r}|j                  }Y d }~3d }~ww xY w)Nr  r   r   r  r  r  s         r4   test_broken_parentz'ImportTracebackTests.test_broken_parent  sa    "88C	8	C" IIABb8Y"78	 ! 	!B	!r  c                     | j                  dd      \  }}	 ddlm} | j                  d       | j                  t        |g       y # t        $ r}|j
                  }Y d }~3d }~ww xY w)Nr  r   r   r  r  r  r  s         r4   test_broken_parent_fromz,ImportTracebackTests.test_broken_parent_from  sa    "88C	8	C' IIABb8Y"78	 ! 	!B	!r  c                    | j                  dd       t        j                  d   }dt        |j                        v r|j                  j
                  }nd }	 d }||j                  _        	 dd l}| j                  d       | j                  t        dt        g       ||j                  `y ||j                  _        y # t        $ r}|j                  }Y d }~Xd }~ww xY w# ||j                  `w ||j                  _        w xY w)	Nr`  r   r  load_modulec                      ddz   y )Nr  r   rT   )rZ  s    r4   exec_modulez9ImportTracebackTests.test_import_bug.<locals>.exec_module  s	    !r6   r   r  z<frozen importlib)r  rZ   r[   varsSourceLoaderr  r`  r   r  r  r  r`   )rO   r   old_exec_moduler  r`  rP  r  s          r4   test_import_bugz$ImportTracebackTests.test_import_bug  s     	5"%KK <=	D!7!788'44@@O"O	E1<I"".G 		EF!!"x1Dh&OP&**65D	&&2 % %__% &**65D	&&2s6   C! ,B? 0.C! ?	CCC! CC! !"Dzneed TESTFN_UNENCODABLEc                     t        j                  dt        d      }| j                  t        |       |d d }t        j
                  dd|z  d       y )Nr   passrW  zmod = __import__(%a)F)
__isolated)r   r?  r   rq  r   r@  )rO   pynamerH   s      r4   test_unencodable_filenamez.ImportTracebackTests.test_unencodable_filename-  sM     **2/A6J'cr{&&t-Cd-J27	9r6   N)rD   )r   r   r   r   r   r  r  r  r  r  r  r  r  r  r  r   r  r   r
  r+   r  r   r  rT   r6   r4   r  r    s    #

#.88	B.#8899 E E4 X+-FG9 H9r6   r  c                   R    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y)CircularImportTestszQSee the docstrings of the modules being imported for the purpose of the
    test.c                     t        t        j                  j                               D ]%  }|j	                  d      st        j                  |= ' y)zSMake sure no modules pre-exist in sys.modules which are being used to
        test.z&test.test_import.data.circular_importsN)r  rZ   r[   keysr
  )rO   keys     r4   r   zCircularImportTests.tearDown=  s>     ((*+ 	%C~~FGKK$	%r6   c                 N    	 dd l }y # t        $ r | j                  d       Y y w xY w)Nr   z/circular import through relative imports failed),test.test_import.data.circular_imports.basicr   r   rO   r!  s     r4   test_directzCircularImportTests.test_directD  s)    	I? 	IIIGH	I    $$c                 N    	 dd l }y # t        $ r | j                  d       Y y w xY w)Nr   z@relative import in module contributing to circular import failed)/test.test_import.data.circular_imports.indirectr   r   r  s     r4   test_indirectz!CircularImportTests.test_indirectJ  s*    	'B 	'II & '	'r  c                 N    	 dd l }y # t        $ r | j                  d       Y y w xY w)Nr   z-circular import involving a subpackage failed)1test.test_import.data.circular_imports.subpackager   r   r  s     r4   test_subpackagez#CircularImportTests.test_subpackageQ  s)    	GD 	GIIEF	Gr  c                     	 dd l mc mc mc m} ddlm} | j                  |j                  j                         y # t
        $ r | j                  d       Y Iw xY w)Nr   z9circular import with rebinding of module attribute failed)rG  )
0test.test_import.data.circular_imports.rebindingr  r  circular_imports	rebindingr   r   -test.test_import.data.circular_imports.subpkgrG  r#  )rO   r$  rG  s      r4   rL  z"CircularImportTests.test_rebindingW  sJ    	SPP 	Gdii0  	SIIQR	Ss   > AAc                 N    	 dd l }y # t        $ r | j                  d       Y y w xY w)Nr   z9circular import with binding a submodule to a name failed).test.test_import.data.circular_imports.bindingr   r   r  s     r4   test_bindingz CircularImportTests.test_binding_  s)    	SA 	SIIQR	Sr  c                     dd l }dd l}y r   )*test.test_import.data.circular_imports.use-test.test_import.data.circular_imports.sourcer  s     r4   test_crossreference1z(CircularImportTests.test_crossreference1e  s    9<r6   c                    | j                  t              5 }dd l}d d d        t        j                        }| j                  d|       | j                  d|       | j                  d|       | j                  d|       y # 1 sw Y   gxY w)Nr   z-test.test_import.data.circular_imports.sourcespamzpartially initialized modulezcircular import)r   rj  r+  r&   r   r   )rO   r   r!  errmsgs       r4   test_crossreference2z(CircularImportTests.test_crossreference2i  sw    ~. 	A"@	AR\\"EvNff%4f='0	A 	As   BB
c                     | j                  t              5 }dd l}d d d        | j                  dt	        j
                               y # 1 sw Y   /xY w)Nr   zcannot import name 'b' from partially initialized module 'test.test_import.data.circular_imports.from_cycle1' (most likely due to a circular import))r   r   2test.test_import.data.circular_imports.from_cycle1r   r&   r   rO   r   r!  s      r4   test_circular_from_importz-CircularImportTests.test_circular_from_importr  sM    {+ 	FrE	F5 		
	F 	F   A		Ac                     | j                  t              5 }dd l}d d d        | j                  dt	        j
                               y # 1 sw Y   /xY w)Nr   zcannot access submodule 'parent' of module 'test.test_import.data.circular_imports.subpkg2' (most likely due to a circular import))r   rj  5test.test_import.data.circular_imports.subpkg2.parentr   r&   r   r3  s      r4    test_absolute_circular_submodulez4CircularImportTests.test_absolute_circular_submodule|  sM    ~. 	I"H	I5 		
	I 	Ir5  c                    | j                  t        d       | j                  t        d       dd lmc mc m} | j                  t              5  ddlm} d d d        | j                  t        |      t               | j                  t              t               | j                  t              5  d|_        d d d        y # 1 sw Y   mxY w# 1 sw Y   y xY w)Nz test.test_import.data.unwritablez"test.test_import.data.unwritable.xr   rZ  *   )rq  r    test.test_import.data.unwritabler  r  
unwritableassertWarnsImportWarningr&  assertNotEqualr(   r    r   r   rj  )rO   r<  r&  s      r4   test_unwritable_modulez*CircularImportTests.test_unwritable_module  s     BC DE==m, 	;:	; 	D,j9a*-~. 	JL	 		; 	;
	 	s   C0CC
CN)r   r   r   r   r   r  r  r   rL  r(  r,  r0  r4  r8  r@  rT   r6   r4   r  r  8  sA    %I'G1S=1

r6   r  c                   .   e Zd Z edddd      Z edd      Zej                         D  ci c]	  \  }}||  c}}} Zded<    ej                   e
ed      d	      d
        Zd dZd!dddddZd!ddddZd!dddZddddZdddZd Zed        Zed        Z ej0                  edu d      d        Z ej0                  edu d      d        Z ej0                  edu d      d        Zd Zed        Zd Ze ed               Z!yc c}}} w )"SubinterpImportTestsFT)
allow_fork
allow_execallow_threadsallow_daemon_threadsr   )use_main_obmallocgilr  rH  r   zrequires os.pipe()c                    t        j                         \  }}| j                  t         j                  |       | j                  t         j                  |       t	        t         d      rt        j
                  |d       ||fS )Nset_blockingF)r   r   rq  r   r   rJ  )rO   r   r   s      r4   r   zSubinterpImportTests.pipe  sV    wwy1!$!$2~&OOAu%1vr6   Nc                     d}|d| d}|r%t        j                  d| d|d|d|d| d	      S t        j                  d
| d| d| d	      S )Nr   zZ
                import _imp
                _imp._override_multi_interp_extensions_check()
                z
                from importlib.util import spec_from_loader, module_from_spec
                from importlib.machinery import ExtensionFileLoader
                import os, sys
                z.
                loader = ExtensionFileLoader(z, z*)
                spec = spec_from_loader(a4  , loader)
                try:
                    module = module_from_spec(spec)
                    loader.exec_module(module)
                except ImportError as exc:
                    text = 'ImportError: ' + str(exc)
                else:
                    text = 'okay'
                os.write(z(, text.encode('utf-8'))
                z0
                import os, sys
                z1
                try:
                    import z
                except ImportError as exc:
                    text = 'ImportError: ' + str(exc)
                else:
                    text = 'okay'
                os.write()r   r   )rO   rH   fdr  check_overrideoverride_texts         r4   import_scriptz"SubinterpImportTests.import_script  s    %!>>L=M NM ?? (   ..2XR| D))- 1  $  " ?? (   6 "
  
$ 
 
r6   )check_singlephase_settingcheck_singlephase_overrideisolatedc                4   t        |       t        di | j                  |r| j                  n| j                  d|i}| j                         \  }}| j                  ||||      }	t        |	fi |}
| j                  |
d       t        j                  |d      S )a{  
        Try importing the named module in a subinterpreter.

        The subinterpreter will be in the current process.
        The module will have already been imported in the main interpreter.
        Thus, for extension/builtin modules, the module definition will
        have been loaded already and cached globally.

        "check_singlephase_setting" determines whether or not
        the interpreter will be configured to check for modules
        that are not compatible with use in multiple interpreters.

        This should always return "okay" for all modules if the
        setting is False (with no override).
        check_multi_interp_extensionsr   d   rT   )r'   r2  
RUN_KWARGSISOLATEDNOT_ISOLATEDr   rP  r   r   r   r   )rO   rH   r  rQ  rR  rS  kwargsr   r   r   r   s              r4   run_herezSubinterpImportTests.run_here  s    ( 	4 
oo
 (t}}d.?.?
 +D
 yy{1##D!X$>@ +6<V<a wwq#r6   strictrS  c                R    | j                  ||||      }| j                  |d       y )NrQ  rS     okayr[  r   )rO   rH   r  r]  rS  outs         r4   check_compatible_herez*SubinterpImportTests.check_compatible_here  s3     mmD(6<%-   	g&r6   rS  c                x    | j                  ||d|      }| j                  |j                  d      d| d       y )NTr_  r   ImportError: module , does not support loading in subinterpreters)r[  r   r   )rO   rH   r  rS  rb  s        r4   check_incompatible_herez,SubinterpImportTests.check_incompatible_here  sJ     mmD(6:%-   	JJw"4&(TU	
r6   c                L   t        di | j                  |r| j                  n| j                  d|i}t	        j
                  dt        j                  d|d|d|d| j                  |d      d| d	            \  }}}| j                  |d
       | j                  |d       y )NrU  rW  zH
            import _testcapi, sys
            assert (
                z0 in sys.builtin_module_names or
                z( not in sys.modules
            ), repr(zL)
            ret = _testcapi.run_in_subinterp_with_config(
                sys.stdout.fileno(),
                **=,
            )
            assert ret == 0, ret
            r6   r`  rT   )
r2  rW  rX  rY  r   r@  r   r   rP  r   )rO   rH   r]  rS  rZ  rk  rb  r3   s           r4   check_compatible_freshz+SubinterpImportTests.check_compatible_fresh  s    
  
oo
 (t}}d.?.?
 +1

 $44T8?? P   H ##D*?@C D( L < 3 	c"g&r6   c                l   t        di | j                  |r| j                  n| j                  ddi}t	        j
                  dt        j                  d|d|d| j                  |d      d| d		            \  }}}| j                  |d
       | j                  |j                  d      d| d       y )NrU  TrW  z6
            import _testcapi, sys
            assert z not in sys.modules, zK
            ret = _testcapi.run_in_subinterp_with_config(
                rj  rk  rl  r6   r   rf  rg  rT   )r2  rW  rX  rY  r   r@  r   r   rP  r   r   )rO   rH   rS  rZ  rk  rb  r3   s          r4   check_incompatible_freshz-SubinterpImportTests.check_incompatible_fresh(  s      
oo
 (t}}d.?.?
 +/

 $44T8?? P80 9##D*?@C D( L < 3 	c"JJw"4&(TU	
r6   c                    d}t        |       | j                  | d      5  | j                  |d       d d d        | j                  | d      5  | j                  |d       d d d        y # 1 sw Y   :xY w# 1 sw Y   y xY w)Nr  : not strictFr]  : strict, not freshT)r;   subTestrc  rO   r.   s     r4   test_builtin_compatz(SubinterpImportTests.test_builtin_compat@  s     \\VHL12 	=&&ve&<	=\\VH$789 	<&&vd&;	< 	<	= 	=	< 	<s   A/A;/A8;Bc                    d}t        |d       t        |      j                  j                  dk7  rt	        j
                  | d      | j                  | d      5  | j                  |d       d d d        | j                  | d	      5  | j                  |d       d d d        y # 1 sw Y   :xY w# 1 sw Y   y xY w)
Nr  Tr7   r$   z is unexpectedly not frozenrq  Frr  rs  )r@   r'   r)   r9   r+   r,   rt  rc  ru  s     r4   test_frozen_compatz'SubinterpImportTests.test_frozen_compatJ  s    $vD)f&&--9##vh.I$JKK\\VHL12 	=&&ve&<	=\\VH$789 	<&&vd&;	< 	<	= 	=	< 	<s   B+B7+B47C c                 ~   d}t        |       | j                  | d      5  | j                  |d       d d d        | j                  | d      5  | j                  |       d d d        | j                  | d      5  | j	                  |       d d d        y # 1 sw Y   fxY w# 1 sw Y   DxY w# 1 sw Y   y xY w)NrY   rq  Frr  rs  : strict, fresh)r>   rt  rc  rh  ro  ru  s     r4   !test_single_init_extension_compatz6SubinterpImportTests.test_single_init_extension_compatU  s    #&!\\VHL12 	=&&ve&<	=\\VH$789 	1((0	1\\VHO45 	2))&1	2 	2		= 	=	1 	1	2 	2s#   BB' B3B$'B03B<z$test requires _testmultiphase modulec                    d}t        |       | j                  | d      5  | j                  |d       d d d        | j                  | d      5  | j                  |d       d d d        | j                  | d      5  | j                  |d       d d d        y # 1 sw Y   jxY w# 1 sw Y   FxY w# 1 sw Y   y xY w)N_testmultiphaserq  Frr  rs  Trz  )r>   rt  rc  rm  ru  s     r4    test_multi_init_extension_compatz5SubinterpImportTests.test_multi_init_extension_compat`  s    "&!\\VHL12 	=&&ve&<	=\\VH$789 	<&&vd&;	<\\VHO45 	=''t'<	= 	=		= 	=	< 	<	= 	=#   BB+B7B(+B47C c                    d}t         j                  }t        ||      }t        j                  j                  ||      }t        j                  j                  |      }|j                  |       |t        j                  |<   t        |       | j                  | d      5  | j                  ||d       d d d        | j                  | d      5  | j                  ||d       d d d        | j                  | d      5  | j                  ||d       d d d        y # 1 sw Y   lxY w# 1 sw Y   GxY w# 1 sw Y   y xY w)	N_test_non_isolatedz
: isolatedTrd  z: not isolatedFrq  rr  r}  r`   r   r   rG  spec_from_loadermodule_from_specr  rZ   r[   r>   rt  rh  rc  rO   modnamer  r*   specr.   s         r4   -test_multi_init_extension_non_isolated_compatzBSubinterpImportTests.test_multi_init_extension_non_isolated_compatk  s5   &"++$Wh7~~..w?0066"%G&!\\WIZ01 	K(((T(J	K\\WI^45 	L(((U(K	L\\WI\23 	H&&w&G	H 	H		K 	K	L 	L	H 	Hs$   !D!D-D9!D*-D69Ec                    d}t         j                  }t        ||      }t        j                  j                  ||      }t        j                  j                  |      }|j                  |       |t        j                  |<   t        |       | j                  | d      5  | j                  ||d       d d d        | j                  | d      5  | j                  ||dd       d d d        | j                  | d      5  | j                  ||dd       d d d        y # 1 sw Y   nxY w# 1 sw Y   HxY w# 1 sw Y   y xY w)	N_test_shared_gil_onlyz: isolated, strictTrd  z: not isolated, strictFr\  z: not isolated, not strictr  r  s         r4   4test_multi_init_extension_per_interpreter_gil_compatzISubinterpImportTests.test_multi_init_extension_per_interpreter_gil_compat}  sJ   )"++$Wh7~~..w?0066"%G&!\\WI%789 	K(((T(J	K\\WI%;<= 	D&&w.2U ' D	D \\WI%?@A 	E&&w.3e ' E	E 	E	K 	K	D 	D	E 	Es$   !D#D/D;#D,/D8;Ec                    d}t        |       | j                  | d      5  | j                  |d       d d d        | j                  | d      5  | j                  |d       d d d        | j                  | d      5  | j                  |d       d d d        y # 1 sw Y   jxY w# 1 sw Y   FxY w# 1 sw Y   y xY w)Nr  rq  Frr  rs  Trz  rB   rt  rc  rm  ru  s     r4   test_python_compatz'SubinterpImportTests.test_python_compat  s    F#\\VHL12 	=&&ve&<	=\\VH$789 	<&&vd&;	<\\VHO45 	=''t'<	= 	=		= 	=	< 	<	= 	=r  c                 n    dt                fd} fd} j                  d      5   |dd       d d d         j                  d      5   |dd       d d d         j                  d	      5   |dd
       d d d         j                  d      5   |dd       d d d         j                  d      5   |dd       d d d         j                  d      5   |dd
       d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   txY w# 1 sw Y   ]xY w# 1 sw Y   y xY w)NrY   c                 R    j                  | |      }j                  |d       y N)rQ  rR  r`  ra  settingoverriderb  r.   rO   s      r4   check_compatiblez_SubinterpImportTests.test_singlephase_check_with_setting_and_override.<locals>.check_compatible  s1    --*1+3   C
 S'*r6   c                 R    j                  | |      }j                  |d       y r  )r[  r?  r  s      r4   check_incompatiblezaSubinterpImportTests.test_singlephase_check_with_setting_and_override.<locals>.check_incompatible  s1    --*1+3   C
 W-r6   z(config: check enabled; override: enabledTr  z+config: check enabled; override: use configr   z)config: check enabled; override: disabledr  z)config: check disabled; override: enabledFz,config: check disabled; override: use configz*config: check disabled; override: disabled)r>   rt  )rO   r  r  r.   s   `  @r4   0test_singlephase_check_with_setting_and_overridezESubinterpImportTests.test_singlephase_check_with_setting_and_override  s+   #&!	+	. \\DE 	(tQ'	(\\GH 	(tQ'	(\\EF 	'T2&	' \\EF 	)ua(	)\\HI 	'UA&	'\\FG 	(UB'	( 	(	( 	(	( 	(	' 	'	) 	)	' 	'	( 	(sG   
C/
C;3
D
D9
D
D+/C8;DDDD(+D4c                    d}t        |       | j                  | d      5  | j                  |dd       d d d        | j                  | d      5  | j                  |dd       d d d        y # 1 sw Y   ;xY w# 1 sw Y   y xY w)Nr  rs  Tr\  rz  r  ru  s     r4   test_isolated_configz)SubinterpImportTests.test_isolated_config  s    F#\\VH$789 	K&&vdT&J	K\\VHO45 	L''td'K	L 	L	K 	K	L 	Ls   A1A=1A:=Bc                 ~   t        j                  d      }t        j                         }| j	                  t        j
                        5  t        j                  ||       d d d        | j	                  t        j
                        5  t        j                  ||       d d d        y # 1 sw Y   HxY w# 1 sw Y   y xY w)NzU
            import _testsinglephase
            print(_testsinglephase)
            )r   r   rk   creater   RunFailedErrorr   )rO   r   r   s      r4   test_disallowed_reimportz-SubinterpImportTests.test_disallowed_reimport  s      "  !'')};;< 	7$$Xv6	7};;< 	7$$Xv6	7 	7	7 	7	7 	7s   	B'B3'B03B<)NNr=   )"r   r   r   r2  rW  rX  itemsrY  r+   r  r   r   r   rP  r[  rc  rh  rm  ro  rv  r   rx  ri   r{  rg   r}  r~  r  r  r  r  r  rl   r  ).0r  vs   000r4   rB  rB    s   "	J H *2)9::AA1uH:LLXV,.BC D#J"+0,0"H
'%*',
'
u 
 6;U '2 :? 
0< < < 2 2 X___,.TU= V= X___,.TUH VH" X___,.TUE VE&=  (  (DL 
7  
7O	 ;s   DrB  c                        e Zd Ze fd       Zej                   ej                  d      j                         z   Ze fd       Z
 xZS )TestSinglePhaseSnapshotc                    t         |   |      }|j                  dd      |_        |j	                         |_        t        |j
                        |_        |j                         |_        t        |d      r|j                         |_        |S )Nr  r   initialized_count)superr{   sumsummedlook_up_selflookeduprp   lookedup_idstate_initializedr   r  
init_count)ry   rz   rO   	__class__s      r4   r{   z#TestSinglePhaseSnapshot.from_module  su    w"3'ggam((*dmm,!$!6!6!83+,!335DOr6   a  
        snapshot['module'].update(dict(
            int_const=mod.int_const,
            str_const=mod.str_const,
            _module_initialized=mod._module_initialized,
        ))
        snapshot.update(dict(
            summed=mod.sum(1, 2),
            lookedup_id=id(mod.look_up_self()),
            state_initialized=mod.state_initialized(),
            init_count=mod.initialized_count(),
            has_spam=hasattr(mod, 'spam'),
            spam=getattr(mod, 'spam', None),
        ))
        c                 F    t         |   |      }|j                  s|`|`|S r=   )r  r   has_spamr.  )ry   r   rO   r  s      r4   r   zTestSinglePhaseSnapshot.parse  s'    w}T"}}	Mr6   )r   r   r   r   r{   rn   r   r   r   rstripr   __classcell__)r  s   @r4   r  r    sW      !,,x @ 0 VXK   r6   r  c                      e Zd ZdZed        Zed        Zd Zed        Zd Z	d Z
d Zd	 Zd
 Zd ddd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ed        Z ed      ed               Zed        Zy)!SinglephaseInitTestsrY   c                     t         j                  j                  | j                        }ddlm} |j                  | _        t        |j                        | _
        | j                  |u sJ | j                          y )Nr   )r   )r   rG  r  NAMEimportlib.machineryr   r9   FILEr(   r*   LOADERclean_up)ry   r  r   s      r4   
setUpClasszSinglephaseInitTests.setUpClass   sV    ~~''1;;;$++&
zz0000 	r6   c                     t                y r=   rd   )ry   s    r4   tearDownClassz"SinglephaseInitTests.tearDownClass  s     "r6   c                 $    | j                          y r=   )r  r   s    r4   r   zSinglephaseInitTests.tearDown  s    r6   c                 f   | j                   }| j                  }|t        j                  v rqt	        t        j                  |   d      rCt        j                  |   j
                  |k(  sJ t        j                  |   j                          t        j                  |= t        j                  ||       y )Nr]   )	r  r  rZ   r[   r   r`   r]   r^   r_   )ry   rH   r  s      r4   r  zSinglephaseInitTests.clean_up  s    xx883;;s{{4(*:;{{4(11X===D!002D!))$9r6   c                 6      fd} j                  |       y )Nc                  F    t        j                   j                         y r=   )r^   r_   r  )rH   rO   s   r4   r  z9SinglephaseInitTests.add_module_cleanup.<locals>.clean_up#  s    --dDII>r6   )rq  )rO   rH   r  s   `` r4   add_module_cleanupz'SinglephaseInitTests.add_module_cleanup"  s    	? 	!r6   c                     ddl m} | j                  ||      }t        j                  j                  |||      } ||      S )z+
        Load an extension module.
        r   )_load)r*   )importlib._bootstrapr  r  r   rG  spec_from_file_location)rO   rH   r   r  r*   r  s         r4   _load_dynamicz"SinglephaseInitTests._load_dynamic(  sD    
 	/T4( ~~55dD=C 6 ET{r6   c                 0   	 | j                   }||vsJ | j                  || j                        }| j	                  ||j                                |||<   t        j                  ||t        j                  |            S # t        $ r i x}| _         Y w xY wNrH   r.   snapshot)
already_loadedrj  r  r  r   valuesrv   rw   r  r{   )rO   rH   r  rz   s       r4   r  zSinglephaseInitTests.load6  s    	6!00N >)))  tyy1n3356"t$$,88=
 	
  	6355NT0	6s   B   BBc                     t         j                  |   |u sJ |j                  |j                  k(  sJ | j                  || j                        }t        j                  ||t        j                  |            S r  )	rZ   r[   rx   r  r  rv   rw   r  r{   )rO   rH   rz   reloadeds       r4   re_loadzSinglephaseInitTests.re_loadE  sl    {{4 C'''||s||+++%%dDII6$$,88B
 	
r6   c                      t        j                  d      t        j                  t        j                  d              fd} j                  |       S )NFrd  zI
            import sys
            import _testinternalcapi
            c            
          t        j                   t        j                  dj                  dj
                  d             t        j                          y )Nz
                name = z
                if name in sys.modules:
                    sys.modules.pop(name)._clear_globals()
                _testinternalcapi.clear_extension(name, rL  )rk   r   r   r   r  r  destroy)r   rO   s   r4   r  z9SinglephaseInitTests.add_subinterpreter.<locals>.clean_upW  sY    $$Xx D		} %9 :> F	@ 0  !!(+r6   )rk   r  r   r   r   rq  )rO   r  r   s   ` @r4   add_subinterpreterz'SinglephaseInitTests.add_subinterpreterQ  sK     ''7  8?? < , 		, 	!r6   NFr~   r   c                   | j                   }|r|dnd}d| d| j                  d}	 | j                  }t        j                  |||d||      }	t        j                  |d |	      S # t        $ rc t	        j
                         x\  }}x}| _        | j                  t        j                  |       | j                  t        j                  |       Y w xY w)	Nzimport _testinternalcapir   z
                z^
                mod._clear_globals()
                _testinternalcapi.clear_extension(name, rL  T)r   r}   r~   r   r  )r  r  _piperj  r   r   rq  r   r  r   rv   rw   )
rO   r   r~   r   rH   import_r   r   r   r  s
             r4   import_in_subinterpz(SinglephaseInitTests.import_in_subinterpb  s     yy4<4D0"G	 99= FK	)::D +99!# : 
 $$
 	
  	)')wwy0DAq04$*OOBHHa(OOBHHa(	)s   A( (A)CCc                    d}|j                   }|sd}|j                  j                   }| j                  |j                  j                  |j                         | j                  |j
                  | j                         | j                  |j                  j                  | j                         |s)| j                  t        |j                  t                     | j                  |j                  d       | j                  |j                  d       | j                  |j                  t                | j#                  |j                  d       |j                  }| j                  |j$                  d       |j&                  <| j                  |j&                  t                | j#                  |j&                  d       |rw| j                  |j(                  |j*                         | j                  |j,                  |j*                         | j/                  t0              5  |j2                   d d d        y | j5                  |j6                  |       | j5                  |j8                  |       y # 1 sw Y   y xY w)NFTi  zsomething differentr   r  )r.   r  r   r)   rH   r`   r  r9   r$  
issubclasserrorr-   	int_const	str_constassertIsInstance_module_initializedfloatassertGreaterr  r  r  rp   rt   r   rj  r.  r#  r  rs   )rO   loadedrS  rz   snaps        r4   check_commonz!SinglephaseInitTests.check_common  s   mmH//((C**FKK8tyy1,,dii8OOJsyy)<=-(=>c55u=322A6a(!!-!!$"8"8%@t55q9 T--tww7T^^TWW5"">2 		  MM$---MM$++s+	 s   !I00I9c                     | j                  |j                  j                  |j                         | j	                  |j
                  j                  |j                         y r=   )r   r.   r   rH   r#  r  r  rO   r  s     r4   check_directz!SinglephaseInitTests.check_direct  s<    //=foo..>r6   c                    ||j                   usJ |j                  |j                  k7  sJ | j                  |j                   j                  |j                         | j	                  |j
                  j                  |j                          y r=   )r.   r   rH   r?  r#  r  r  )rO   r  origs      r4   check_indirectz#SinglephaseInitTests.check_indirect  sd    6==(((}}+++FMM22FKK@foo..>r6   c                    |j                   }| j                  |j                  d        | j                  |j                  t
               | j                  |j                  d       | j                  |j                  |       y r   )r  assertIsNotr  r  r  intr  r   )rO   r  expected_init_countr  s       r4   check_basicz SinglephaseInitTests.check_basic  s`     //6doos34??A.*=>r6   c                      y r=   rT   r  s     r4   check_with_reinitz&SinglephaseInitTests.check_with_reinit  s     	r6   c                     |j                   }| j                  |j                  d       | j                  |j                  j                  |j
                         y)zU
        The module had not been loaded before (at least since fully reset).
        r  N)r  r   r  r.   r  r  )rO   r  r  s      r4   check_freshz SinglephaseInitTests.check_fresh  sH     
 	!, 	88//	1r6   c                 b   |j                   }| j                  |j                  |j                   j                         | j                  |j                  |j                   j                         | j                  |j                  |j                   j                  dz          | j                  |j
                  j                  |j                         | j                  |j                  |j                   j                         | j                  |j                  |j                   j                         y)zp
        The module had been loaded before and then reset
        (but the module global state wasn't).
        r  Nr  r?  rp   r   r  r.   r  r  )rO   r  r6  prevr  s        r4   check_semi_freshz%SinglephaseInitTests.check_semi_fresh  s    
 
 	DGGT]]%5%56DGGT]]%5%56$--*B*BQ*FG 	88//	1D22 MM;;	=D22 MM;;	=r6   c                    |j                   }| j                  |j                  |j                   j                         | j                  |j                  |j                   j                         | j                  |j
                  j                  |j                         | j                  |j                  |j                   j                         y)zD
        The module had been loaded before and never reset.
        Nr  )rO   r  r6  r  s       r4   check_copiedz!SinglephaseInitTests.check_copied  s     
 	DGGT]]%5%56$--*B*BC 	88//	1//88	:r6   c                 F   | j                  | j                        }|j                  } |j                         } |j                           |j                         } |j
                         }| j                  |d       | j                  |d       | j                  |d       y )Nr   r  )r  r  r.   r  r]   r  r  r   )rO   r  rY   init_before
init_afterr  s         r4   test_cleared_globalsz)SinglephaseInitTests.test_cleared_globals 	  s    499%!==8&88:''')7%779
7%779
;*Q'R(r6   c                    d | _         | j                  }d}| j                  |      5  | j                  |      }| j	                  |       | j                  |       | j                  ||       d d d        j                  }| j                   d}| j                  |       |dz  }| j                  |      5  | j                  |      }| j	                  |       | j                  ||       | j                  ||       | j                  |j                         |j                         | j                  |j                         |       d d d        |j                  }| j                   d}| j                  |       |dz  }| j                  |      5  | j                  |      }| j	                  |       | j                  |       | j                  ||       | j                  |j                         |       | j                  |j                         |       d d d        | j                   d}| j                  |       | j                  |      5  | j                  |      }| j	                  |       | j                  |j                  j                  d        | j                  |       | j!                  |       | j                  |j                         |       | j                  |j                         |       d d d        | j                   d}| j                  |       | j                  |      5  | j                  |      }| j#                  |j                  j$                         | j	                  |       | j'                  |j                  j                  d        | j                  |       | j!                  |       | j                  |j                         |       | j                  |j                         |       d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   ;xY w# 1 sw Y   y xY w)Nr  _basic_wrapper_basic_copy_with_reinit_with_state)maxDiffr  rt  r  r  r  r  r.   r  r  r#  r  r   r  r  r  r  rq  _clear_module_stater  )rO   rH   r  r  basicbasic_lookedups         r4   test_variantsz"SinglephaseInitTests.test_variants	  s    yy\\$ 	:YYt_Ff%f%V%89	:  ))N+%q \\$ 		MYYt_Ff%.V%89 MM%,,.>U4468KL		M   ))K(%q \\$ 		MYYt_Ff%f%V%89 MM%,,.?U4468KL		M ))L)%\\$ 
	MYYt_Ff%MM&//;;TBf%""6* MM%,,.?U4468KL
	M ))K(%\\$ 	MYYt_FOOFMM==>f%V__>>Ef%""6* MM%,,.?U4468KL	M 	M	: 	:		M 		M&		M 		M
	M 
	M 	M 	Ms@   AP7BPBP(B+P55CQPP%(P25P?Qc                    d | _         | j                  | j                   d| j                   dfD ]  }| j                  |       | j                  |      5  | j	                  |      }| j                  ||j                        }| j                  |       | j                  |       | j                  t        |j                  j                        |j                  j                         | j                  |j                  j                  j                  |j                  j                         | j                  |j                  j                  j                  |j                         | j                  |j                  j                   |j                  j                  j                          | j#                  |j                  |j                         | j#                  |j                  j                  |j                  j                         | j#                  |j                  j$                  |j                  j$                         | j                  |j                  j&                  |j                  j&                         | j                  |j                  j(                  |j                  j(                         | j#                  |j                  j*                  |j                         d d d         y # 1 sw Y   xY w)Nr   r  )r  r  r  rt  r  r  r.   r  r   rp   rx   r  rr   rq   r)   rH   r   r#  r  r  r  rs   )rO   rH   r  r  s       r4   test_basic_reloadedz(SinglephaseInitTests.test_basic_reloadeda	  sB     IIyyk(yyk%
 #	ID
 ##D)d# I4<<fmm<!!&)!!(+   FMM$:$:!;!'!6!68  !3!3!<!<!'!7!79   !9!9!>!>N  !9!9!)!2!2!5!5!>!>@ hoov}}=hoo668N8NO h//88$oo668  !2!2!D!D!'!B!BD  !2!2!=!=!'!;!;= h//66H;I I#	II Is   JK66L 	c                    d | _         | j                  | j                        }| j                   ddf| j                   ddffD ]  \  }}| j                  |       | j	                  ||      5  | j                  |      }|r%| j                  |j                  j                         | j                  ||j                        }|r%| j                  |j                  j                         | j                  |       | j                  |       | j                  t        |j                  j                        |j                  j                         | j                  |j                  j                  j                  |j                  j                         | j                  |j                  j                   j"                  |j"                         | j                  |j                  j$                  |j                  j                  j$                         | j'                  |j                  |j                         | j)                  |j                  j                  |j                  j                         | j+                  |j                  j,                  |j                         |j                  j.                  '| j+                  |j                  j.                  d        n:| j1                  |j                  j.                  |j                  j.                         | j+                  |j                  j2                  |j                         d d d         y # 1 sw Y   xY w)Nr  Fr  T)rH   	has_state)r  r  r  r  rt  rq  r.   r  r  r  r   rp   rx   r  rr   rq   r)   rH   r   r  r?  r#  r  r  r  rs   )rO   r  rH   r  r  r  s         r4   test_with_reinit_reloadedz.SinglephaseInitTests.test_with_reinit_reloaded	  s    		$))$ 		{,'/		{+&- 
 %	IOD) ##D)49=  I4OOFMM$E$EF<<fmm<OOHOO$G$GH!!&)!!(+   FMM$:$:!;!'!6!68  !3!3!<!<!'!7!79   !9!9!>!>N  !9!9!)!2!2!5!5!>!>@   &--@##HOO$<$<$*MM$:$:<h//88(//J??44<MM("3"3"E"EtL&&x'8'8'J'J'-'H'HJ h//66HA I  I%	I
 I  Is   0KMM 	c                    | j                  | j                        }|j                  }d|_        | j	                  |       | j                  |       | j                         }| j                         }| j                         }| j	                  |       | j                  ||       | j                  |      }| j	                  |       | j                  ||       | j                  |      }| j	                  |       | j                  ||       y )Nz&spam, spam, spam, spam, eggs, and spam)	r  r  r.   r.  r  r  r  r  r  )rO   main_loadedrY   	interpid1	interpid2r  s         r4   .test_basic_multiple_interpreters_main_no_resetzCSinglephaseInitTests.test_basic_multiple_interpreters_main_no_reset	  s     ii		*&-- H+&%++-	++-	 ))+&!&+. )))4&!&+. )))4&!&+.r6   zArerun not possible; module state is never cleared (see gh-102251))rR   c                    t        t        d      rt        j                  d      | j	                         }| j	                         }| j                  | j                        }|j                  j                          t        j                  | j                  | j                         | j                  d      }| j                  |       | j                  |       | j                  |      }| j                  |       | j                  |||       | j                  |      }| j                  |       | j!                  ||       y )N
getobjectszcrashes on Py_TRACE_REFS buildsz
            # Attrs set after loading are not in m_copy.
            mod.spam = 'spam, spam, mash, spam, eggs, and spam'
        )r~   )r   rZ   r+   r,   r  r  r  r.   r]   r^   r_   r  r  r  r  r  r  )rO   r  r  loaded_mainr6  loaded_interp1loaded_interp2s          r4   1test_basic_multiple_interpreters_deleted_no_resetzFSinglephaseInitTests.test_basic_multiple_interpreters_deleted_no_reset
  s   
 3% ##$EFF ++-	++-	 ii		*))+))$))TYY? '' 4'  	$ 11)<.)nk4@ 11)<.)..9r6   c                    | j                         }| j                         }| j                  dd      }| j                  |       | j                  |       | j                  |d      }| j                  |       | j                  |       | j                  |d      }| j                  |       | j                  |       y )Nz
            # Attrs set after loading are not in m_copy.
            mod.spam = 'spam, spam, mash, spam, eggs, and spam'
            Tr  )r   )r  r  r  r  )rO   r  r  r  s       r4   +test_basic_multiple_interpreters_reset_eachz@SinglephaseInitTests.test_basic_multiple_interpreters_reset_eachN
  s     ++-	++-	 ))  * 
 	&!  ))))F&!  ))))F&! r6   r=   ) r   r   r   r  r   r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r
  r  rl   r  rV   r  r  rT   r6   r4   r  r    s    D  # # 	: 	:"

""
'+(-"
L!,F?
??
1=,:,)RMh(IT,Ih :/ :/F XY@:  Z@:R 0! 0!r6   r  __main__)`r^  rL  r  r   importlib.utilr   importlib._bootstrap_externalr   r  r   r   r   r   r  r   r  r   r  rN  r  rZ   r   r  r{  rv   r+   r   r^   r  r"  r	   r
   r   r   r   r   r   r   r   test.support.import_helperr   r   r   r   r   r   r   test.support.os_helperr   r   r   r   r   r   test.test_importlib.utilr   r    rY   r   r}  _xxsubinterpretersrk   r   rg   dont_write_bytecoder  r5   r;   r>   r@   rB   rJ   rV   ra   ri   rl   rw   rn   TestCaser   r  r  r  r)  rS  ra  r  r  r  r  r  rB  r  r  r   mainrT   r6   r4   <module>r%     s        9   	      
         "= = =     4 4 & ) , .
 .hoo46 
6 %* A ', 7 $( ? ). 4& *:  
J=`(U** `(FT)(## T)n V/(++ V/ V/rVM)) VMr3 "" 3 l^:(++ ^:B(8#4#4 ((_!8$$ _!D+3H$5$5 +3\ <h// < <@ 6** 6 6Bm98,, m9`Y(++ Yx~78,, ~7B
#n #L C
!8,, C
! C
!Z zHMMO R    O  Ms6   :J ?J J" JJJJ"J-,J-