U
    aÊ¹j  ã                   @   s¨   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Zddlm	Z	 ddl
Z
ddlmZ e
j d¡G dd„ dƒƒZG dd	„ d	ƒZd
d„ Zdd„ Zdd„ Zdd„ ZdS )z&Support code for distutils test cases.é    N)ÚDistribution)Úalways_iterableZdistutils_managed_tempdirc                   @   s,   e Zd ZdZdd„ Zddd„Zddd	„Zd
S )ÚTempdirManagerzI
    Mix-in class that handles temporary directories for test cases.
    c                 C   s   t  ¡ }| j |¡ |S )zjCreate a temporary directory that will be cleaned up.

        Returns the path of the directory.
        )ÚtempfileÚmkdtempZtempdirsÚappend)ÚselfÚd© r
   úb/var/www/html/bwave/python/venv/lib/python3.8/site-packages/setuptools/_distutils/tests/support.pyr      s    zTempdirManager.mkdtempÚxxxc                 C   s   t jt|ƒŽ j|dd� dS )zVWrites a file in the given path.

        path can be a string or a sequence.
        zutf-8)ÚencodingN)ÚpathlibÚPathr   Ú
write_text)r   ÚpathÚcontentr
   r
   r   Ú
write_file   s    zTempdirManager.write_fileÚfooc                 K   s2   |   ¡ }tj ||¡}t |¡ t|d�}||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)r   Úosr   ÚjoinÚmkdirr   )r   Úpkg_nameÚkwZtmp_dirZpkg_dirÚdistr
   r
   r   Úcreate_dist&   s
    


zTempdirManager.create_distN)r   )r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r
   r
   r
   r   r      s   	
r   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚDummyCommandzAClass to store options for retrieval via set_undefined_options().c                 K   s   t | ƒ |¡ d S ©N)ÚvarsÚupdate)r   Úkwargsr
   r
   r   Ú__init__;   s    zDummyCommand.__init__c                 C   s   d S r"   r
   )r   r
   r
   r   Úensure_finalized>   s    zDummyCommand.ensure_finalizedN)r   r   r   r    r&   r'   r
   r
   r
   r   r!   8   s   r!   c                 C   s   t  tƒ tj | d¡¡ 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.
    ú
xxmodule.cN)ÚshutilÚcopyÚ_get_xxmodule_pathr   r   r   )Ú	directoryr
   r
   r   Úcopy_xxmodule_cB   s    r-   c                  C   s(   t jdkrdnd} tj tj t¡| ¡S )N)é   é	   r(   zxxmodule-3.8.c)ÚsysÚversion_infor   r   r   ÚdirnameÚ__file__)Zsource_namer
   r
   r   r+   Q   s    r+   c                 C   s~   t jdkrtj d¡| _n`t d¡rzt d¡}|dkr@dg| _n:tj	dkrRg | _n(| 
d¡\}}}d	d
„ | t j¡D ƒ| _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                 S   s   g | ]}|r|‘qS r
   r
   )Ú.0r	   r
   r
   r   Ú
<listcomp>x   s      z#fixup_build_ext.<locals>.<listcomp>)r   Únamer0   Ú
executableÚendswithÚdebugÚ	sysconfigÚget_config_varÚlibrary_dirsÚplatformÚ	partitionÚsplitÚpathsep)ÚcmdZ	runsharedr<   ÚequalsÚvaluer
   r
   r   Úfixup_build_extV   s    




rJ   c                 C   s    dd„ t  | g| j¡D ƒ| _| S )z®
    pytest will honor markers as found on the class, but when
    markers are on multiple subclasses, only one appears. Use
    this decorator to combine those markers.
    c                 S   s"   g | ]}t |d g ƒD ]}|‘qqS )Ú
pytestmark)Úgetattr)r:   ÚbaseÚmarkr
   r
   r   r;   �   s    þz#combine_markers.<locals>.<listcomp>)Ú	itertoolsÚchainÚ	__bases__rK   )Úclsr
   r
   r   Úcombine_markers{   s    þrS   )r    rO   r   r   r)   r0   r@   r   Údistutils.corer   ZpytestZmore_itertoolsr   rN   Zusefixturesr   r!   r-   r+   rJ   rS   r
   r
   r
   r   Ú<module>   s"   
'
%