
    eZ                        d Z ddlZddlZddlZddlZddlZddlZddlmZ ddl	m
Z
 ddlmZ ddlmZmZmZmZmZ ddlmZ  G d d	e          Z G d
 de          Z G d d          Z G d de          Zd Zd Zd ZdS )z&Support code for distutils test cases.    N)deepcopy)	os_helper)log)DEBUGINFOWARNERRORFATAL)Distributionc                   :     e Zd Z fdZ fdZd Zd Zd Z xZS )LoggingSilencerc                     t                                                       t          j        t          j                  | _        t          j        j        | _        | j        t          j        _        g | _	        d S N)
supersetUpr   set_thresholdr
   	thresholdLog_log_old_loglogsself	__class__s    )  /home/conda/feedstock_root/build_artifacts/python-split_1708115622739/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/lib/python3.11/distutils/tests/support.pyr   zLoggingSilencer.setUp   sK    *3955 y			    c                     t          j        | j                   | j        t           j        _        t                                                       d S r   )r   r   r   r   r   r   r   tearDownr   s    r   r   zLoggingSilencer.tearDown   s=    $.)))}r   c                 4   |t           t          t          t          t          fvrt          dt          |          z            t          |t                    s$t          dt          |          j
        z            | j                            |||f           d S )Nz%s wrong log levelzmsg should be str, not '%.200s')r   r   r   r	   r
   
ValueErrorstr
isinstance	TypeErrortype__name__r   append)r   levelmsgargss       r   r   zLoggingSilencer._log!   s    dE59991CJJ>???#s## 	4=#Cyy13 4 4 4	%d+,,,,,r   c                 *    fd| j         D             S )Nc                 *    g | ]\  }}}|v 
||z  S  r,   ).0r'   r(   r)   levelss       r   
<listcomp>z,LoggingSilencer.get_logs.<locals>.<listcomp>*   s4     1 1 1/uc4 % d
 /r   r   )r   r.   s    `r   get_logszLoggingSilencer.get_logs)   s0    1 1 1 191 1 1 	1r   c                     g | _         d S r   r0   r   s    r   
clear_logszLoggingSilencer.clear_logs-   s    			r   )	r%   
__module____qualname__r   r   r   r1   r4   __classcell__r   s   @r   r   r      s~                
- - -1 1 1      r   r   c                   B     e Zd ZdZ fdZ fdZd Zd	dZd
dZ xZ	S )TempdirManagerz}Mix-in class that handles temporary directories for test cases.

    This is intended to be used with unittest.TestCase.
    c                     t                                                       t          j                    | _        g | _        d S r   )r   r   osgetcwdold_cwdtempdirsr   s    r   r   zTempdirManager.setUp7   s,    y{{r   c                     t          j        | j                   t                                                       | j        r6| j                                        }t          j        |           | j        4d S d S r   )	r<   chdirr>   r   r   r?   popr   rmtree)r   tmpdirr   s     r   r   zTempdirManager.tearDown<   s{     	m 	%]&&((FV$$$ m 	% 	% 	% 	% 	%r   c                 `    t          j                    }| j                            |           |S )zjCreate a temporary directory that will be cleaned up.

        Returns the path of the directory.
        )tempfilemkdtempr?   r&   )r   ds     r   rG   zTempdirManager.mkdtempE   s-    
 Qr   xxxc                 
   t          |t          t          f          rt          j        j        | }t          |d          }	 |                    |           |                                 dS # |                                 w xY w)zWWrites a file in the given path.


        path can be a string or a sequence.
        wN)	r"   listtupler<   pathjoinopenwriteclose)r   rN   contentfs       r   
write_filezTempdirManager.write_fileN   so     dT5M** 	'7<&DsOO	GGGGGIIIIIAGGIIIIs   A, ,Bfooc                     |                                  }t          j                            ||          }t          j        |           t          |          }||fS )a  Will generate a test environment.

        This function creates:
         - a Distribution instance using keywords
         - a temporary directory with a package structure

        It returns the package directory and the distribution
        instance.
        )attrs)rG   r<   rN   rO   mkdirr   )r   pkg_namekwtmp_dirpkg_dirdists         r   create_distzTempdirManager.create_dist\   sP     ,,..',,w11
"%%%}r   )rI   )rV   )
r%   r5   r6   __doc__r   r   rG   rU   r_   r7   r8   s   @r   r:   r:   1   s         
    
% % % % %            r   r:   c                       e Zd ZdZd Zd ZdS )DummyCommandzAClass to store options for retrieval via set_undefined_options().c                 \    |                                 D ]\  }}t          | ||           d S r   )itemssetattr)r   kwargsr[   vals       r   __init__zDummyCommand.__init__q   s<    ||~~ 	# 	#GBD"c""""	# 	#r   c                     d S r   r,   r3   s    r   ensure_finalizedzDummyCommand.ensure_finalizedu   s    r   N)r%   r5   r6   r`   rh   rj   r,   r   r   rb   rb   n   s8        KK# # #    r   rb   c                   (     e Zd Z fdZ fdZ xZS )EnvironGuardc                     t          t          |                                            t          t          j                  | _        d S r   )r   rl   r   r   r<   environold_environr   s    r   r   zEnvironGuard.setUp{   s7    lD!!'')))#BJ//r   c                    | j                                         D ]7\  }}t          j                            |          |k    r|t          j        |<   8t          t          j                                                  D ]}|| j         vrt          j        |= t          t          |           	                                 d S r   )
ro   rd   r<   rn   getrM   keysr   rl   r   )r   keyvaluer   s      r   r   zEnvironGuard.tearDown   s    *0022 	( 	(JCz~~c""e++"'
3**++ 	$ 	$C$***JsOlD!!**,,,,,r   )r%   r5   r6   r   r   r7   r8   s   @r   rl   rl   y   sQ        0 0 0 0 0	- 	- 	- 	- 	- 	- 	- 	- 	-r   rl   c                 x    t                      }|t          j        d          t          j        ||            dS )ak  Helper for tests that need the xxmodule.c source file.

    Example use:

        def test_compile(self):
            copy_xxmodule_c(self.tmpdir)
            self.assertIn('xxmodule.c', os.listdir(self.tmpdir))

    If the source file can be found, it will be copied to *directory*.  If not,
    the test will be skipped.  Errors during copy are not caught.
    Nz>cannot find xxmodule.c (test must run in the python build dir))_get_xxmodule_pathunittestSkipTestshutilcopy)	directoryfilenames     r   copy_xxmodule_cr}      sG     "##H !8 9 9 	9
K)$$$$$r   c            
         t          j        d          } t          j                            t          j                            t                    d          t          j                            | dd          t          j                            | ddddd          g}|D ]%}t          j                            |          r|c S &d S )Nsrcdirz
xxmodule.cModulesz..)	sysconfigget_config_varr<   rN   rO   dirname__file__exists)r   
candidatesrN   s      r   rv   rv      s    %h//F 	RW__X..==
VY55 	VT4y,GG	J   7>>$ 	KKK	 r   c                    t           j        dk    r&t          j                            d          | _        dS t          j        d          rt          j        d          }|
dg| _        dS t          j	        dk    r	g | _        dS |
                    d          \  }}}d	 |                    t           j                  D             | _        dS dS )
a  Function needed to make build_ext tests pass.

    When Python was built with --enable-shared on Unix, -L. is not enough to
    find libpython<blah>.so, because regrtest runs in a tempdir, not in the
    source directory where the .so lives.

    When Python was built with in debug mode on Windows, build_ext commands
    need their debug attribute set, and it is not done automatically for
    some reason.

    This function handles both of these things.  Example use:

        cmd = build_ext(dist)
        support.fixup_build_ext(cmd)
        cmd.ensure_finalized()

    Unlike most other Unix platforms, Mac OS X embeds absolute paths
    to shared libraries into executables, so the fixup is not needed there.
    ntz_d.exePy_ENABLE_SHARED	RUNSHAREDN.darwin=c                     g | ]}||S r,   r,   )r-   rH   s     r   r/   z#fixup_build_ext.<locals>.<listcomp>   s    #L#L#L!!#LA#L#L#Lr   )r<   namesys
executableendswithdebugr   r   library_dirsplatform	partitionsplitpathsep)cmd	runsharedr   equalsrt   s        r   fixup_build_extr      s    ( 
w$N++H55					!"4	5	5 M ,[99	 #uC|x''#%   &/&9&9#&>&>#fe#L#Lu{{2:/F/F#L#L#L   M Mr   )r`   r<   r   ry   rF   rw   r   rz   r   test.supportr   	distutilsr   distutils.logr   r   r   r	   r
   distutils.corer   objectr   r:   rb   rl   r}   rv   r   r,   r   r   <module>r      s   , , 				 



              " " " " " "       9 9 9 9 9 9 9 9 9 9 9 9 9 9 ' ' ' ' ' '    f   B: : : : :V : : :z       - - - - -6 - - -$% % %&  ""M "M "M "M "Mr   