Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/distutils/tests/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/distutils/tests/__pycache__/support.cpython-35.pyc



��Yf��@s#dZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
ddlmZm
Z
mZmZmZddlmZGdd�de�ZGd	d
�d
e�ZGdd�d�ZGd
d�de�Zdd�Zdd�Zdd�ZdS)z&Support code for distutils test cases.�N)�deepcopy)�log)�DEBUG�INFO�WARN�ERROR�FATAL)�DistributioncsXeZdZ�fdd�Z�fdd�Zdd�Zdd�Zd	d
�Z�S)�LoggingSilencercsMt�j�tjtj�|_tjj|_|jtj_g|_	dS)N)
�super�setUpr�
set_thresholdr�	threshold�Log�_log�_old_log�logs)�self)�	__class__��</opt/alt/python35/lib64/python3.5/distutils/tests/support.pyrs

zLoggingSilencer.setUpcs0tj|j�|jtj_t�j�dS)N)rr
rrrrr�tearDown)r)rrrrszLoggingSilencer.tearDowncCsv|tttttfkr1tdt|���t|t�sYtdt	|�j
��|jj|||f�dS)Nz%s wrong log levelzmsg should be str, not '%.200s')
rrrrr�
ValueError�str�
isinstance�	TypeError�type�__name__r�append)r�level�msg�argsrrrr szLoggingSilencer._logcs&dd�}�fdd�|jD�S)NcSs||S)Nr)r r!rrr�_format)sz)LoggingSilencer.get_logs.<locals>._formatcs/g|]%\}}}|�kr||�qSrr)�.0rr r!)�levelsrr�
<listcomp>+s	z,LoggingSilencer.get_logs.<locals>.<listcomp>)r)rr$r"r)r$r�get_logs(szLoggingSilencer.get_logscCs
g|_dS)N)r)rrrr�
clear_logs.szLoggingSilencer.clear_logs)r�
__module__�__qualname__rrrr&r'rr)rrr
s

r
csdeZdZdZ�fdd�Z�fdd�Zdd�Zdd	d
�Zddd
�Z�S)�TempdirManagerz}Mix-in class that handles temporary directories for test cases.

    This is intended to be used with unittest.TestCase.
    cs)t�j�tj�|_g|_dS)N)rr�os�getcwd�old_cwd�tempdirs)r)rrrr8s
zTempdirManager.setUpcsYtj|j�t�j�x5|jrT|jj�}tj|tj	dk�q WdS)N�nt�cygwin)r/r0)
r+�chdirr-rrr.�pop�shutilZrmtree�name)r�d)rrrr=s

zTempdirManager.tearDowncCs tj�}|jj|�|S)zjCreate a temporary directory that will be cleaned up.

        Returns the path of the directory.
        )�tempfile�mkdtempr.r)rr5rrrr7FszTempdirManager.mkdtempZxxxc
CsYt|ttf�r'tjj|�}t|d�}z|j|�Wd|j�XdS)zWWrites a file in the given path.


        path can be a string or a sequence.
        �wN)	r�list�tupler+�path�join�open�write�close)rr;Zcontent�frrr�
write_fileOszTempdirManager.write_fileZfoocKsG|j�}tjj||�}tj|�td|�}||fS)aWill 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.
        Zattrs)r7r+r;r<�mkdirr	)rZpkg_name�kwZtmp_dirZpkg_dirZdistrrr�create_dist]s


zTempdirManager.create_dist)	rr(r)�__doc__rrr7rArDrr)rrr*2s		r*c@s.eZdZdZdd�Zdd�ZdS)�DummyCommandzAClass to store options for retrieval via set_undefined_options().cKs1x*|j�D]\}}t|||�q
WdS)N)�items�setattr)r�kwargsrC�valrrr�__init__rszDummyCommand.__init__cCsdS)Nr)rrrr�ensure_finalizedvszDummyCommand.ensure_finalizedN)rr(r)rErKrLrrrrrFosrFcs4eZdZ�fdd�Z�fdd�Z�S)�EnvironGuardcs)tt|�j�ttj�|_dS)N)rrMrrr+�environ�old_environ)r)rrrr|szEnvironGuard.setUpcs�xB|jj�D]1\}}tjj|�|kr|tj|<qWx6ttjj��D]}||jkr[tj|=q[Wtt|�j	�dS)N)
rOrGr+rN�getr:�keysrrMr)r�key�value)rrrr�szEnvironGuard.tearDown)rr(r)rrrr)rrrMzsrMcCs8t�}|dkr$tjd��tj||�dS)akHelper 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�unittestZSkipTestr3�copy)Z	directory�filenamerrr�copy_xxmodule_c�s	rXc	Cs�tjd�}tjjtjjt�d�tjj|dd�tjj|ddddd�g}x$|D]}tjj|�rm|SqmWdS)N�srcdirz
xxmodule.c�Modulesz..)�	sysconfig�get_config_varr+r;r<�dirname�__file__�exists)rYZ
candidatesr;rrrrT�s$
rTcCs�tjdkr'tjjd�|_n�tjd�r�tjd�}|dkr`dg|_nUtj	dkr{g|_n:|j
d�\}}}d	d
�|jtj�D�|_dS)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.
    r/z_d.exe�Py_ENABLE_SHARED�	RUNSHAREDN�.�darwin�=cSsg|]}|r|�qSrr)r#r5rrrr%�s	z#fixup_build_ext.<locals>.<listcomp>)
r+r4�sys�
executable�endswith�debugr[r\Zlibrary_dirs�platform�	partition�split�pathsep)�cmdZ	runsharedr4ZequalsrSrrr�fixup_build_ext�srn)rEr+rer3r6rUr[rVrZ	distutilsrZ
distutils.logrrrrrZdistutils.corer	�objectr
r*rFrMrXrTrnrrrr�<module>s"(#=