a
   Bjc9                   @   s   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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mZmZmZmZ d dlmZ d dlmZ G dd	 d	eZG d
d dZG dd deZdS )    N)DistutilsErrorDistutilsOptionError)log)
TestLoader)	resource_listdirresource_existsnormalize_pathworking_set_namespace_packagesevaluate_markeradd_activation_listenerrequire
EntryPoint)Command)unique_everseenc                   @   s   e Zd Zdd ZdddZdS )ScanningLoaderc                 C   s   t |  t | _d S N)r   __init__set_visitedself r   ;/usr/lib/python3.9/site-packages/setuptools/command/test.pyr      s    
zScanningLoader.__init__Nc                 C   s   || j v rdS | j | g }|t| | t|drH||  t|drt|jdD ]`}|	dr|dkr|jd |dd  }n"t
|j|d	 r^|jd | }nq^|| | q^t|d
kr| |S |d S dS )a  Return a suite of all tests cases contained in the given module

        If the module is a package, load tests from all the modules in it.
        If the module has an ``additional_tests`` function, call it and add
        the return value to the tests.
        Nadditional_tests__path__ z.pyz__init__.py.z/__init__.py   r   )r   addappendr   loadTestsFromModulehasattrr   r   __name__endswithr   ZloadTestsFromNamelenZ
suiteClass)r   modulepatternZtestsfileZ	submoduler   r   r   r"      s$    



z"ScanningLoader.loadTestsFromModule)N)r$   
__module____qualname__r   r"   r   r   r   r   r      s   r   c                   @   s   e Zd Zdd ZdddZdS )NonDataPropertyc                 C   s
   || _ d S r   fget)r   r.   r   r   r   r   <   s    zNonDataProperty.__init__Nc                 C   s   |d u r| S |  |S r   r-   )r   objZobjtyper   r   r   __get__?   s    zNonDataProperty.__get__)N)r$   r*   r+   r   r0   r   r   r   r   r,   ;   s   r,   c                   @   s   e Zd ZdZdZg dZdd Zdd Zedd	 Z	d
d Z
dd Zejg fddZeejdd Zedd Zdd Zdd Zedd Zedd ZdS )testz.Command to run unit tests after in-place buildz0run unit tests after in-place build (deprecated)))ztest-module=mz$Run 'test_suite' in specified module)ztest-suite=sz9Run single test, case or suite (e.g. 'module.test_suite'))ztest-runner=rzTest runner to usec                 C   s   d | _ d | _d | _d | _d S r   )
test_suitetest_moduletest_loadertest_runnerr   r   r   r   initialize_optionsQ   s    ztest.initialize_optionsc                 C   s   | j r| jrd}t|| j d u rD| jd u r8| jj | _ n| jd | _ | jd u r^t| jdd | _| jd u rnd| _| jd u rt| jdd | _d S )Nz1You may specify a module or a suite, but not bothz.test_suiter7   z&setuptools.command.test:ScanningLoaderr8   )r5   r6   r   distributionr7   getattrr8   )r   msgr   r   r   finalize_optionsW   s    




ztest.finalize_optionsc                 C   s   t |  S r   )list
_test_argsr   r   r   r   	test_argsj   s    ztest.test_argsc                 c   s4   | j stjdkrdV  | jr"dV  | j r0| j V  d S )N)      Zdiscoverz	--verbose)r5   sysversion_infoverboser   r   r   r   r?   n   s    ztest._test_argsc                 C   s2   |    |  W d   n1 s$0    Y  dS )zI
        Backward compatibility for project_on_sys_path context.
        N)project_on_sys_path)r   funcr   r   r   with_project_on_sys_pathv   s    
ztest.with_project_on_sys_pathc           	   
   c   s  t | jdd}|rp| jddd | d | d}t|j}| jd|d | d | jddd | d n"| d | jdd	d | d | d}tjd d  }tj	
 }zt|j}tjd| t  td
d  td|j|jf  | |g d V  W d    n1 s 0    Y  W |tjd d < tj	  tj	| t  n.|tjd d < tj	  tj	| t  0 d S )Nuse_2to3FZbuild_pyr   )ZinplaceZegg_info)egg_baseZ	build_extr   c                 S   s   |   S r   )Zactivate)distr   r   r   <lambda>       z*test.project_on_sys_path.<locals>.<lambda>z%s==%s)r;   r:   Zreinitialize_commandZrun_commandZget_finalized_commandr   Z	build_librC   pathmodulescopyrJ   insertr	   r   r   r   Zegg_nameZegg_versionpaths_on_pythonpathclearupdate)	r   Zinclude_distsZ	with_2to3Zbpy_cmdZ
build_pathZei_cmdZold_pathZold_modulesZproject_pathr   r   r   rF   }   s@    








(


ztest.project_on_sys_pathc              
   c   s   t  }tjd|}tjdd}zdtjt| }td||g}tj|}|r\|tjd< dV  W ||u r|tjdd q|tjd< n$||u rtjdd n
|tjd< 0 dS )z
        Add the indicated paths to the head of the PYTHONPATH environment
        variable so that subprocesses will also see the packages at
        these paths.

        Do this in a context that restores the value on exit.
        Z
PYTHONPATHr   N)	objectosenvirongetpathsepjoinr   filterpop)pathsZnothingZorig_pythonpathZcurrent_pythonpathprefixZto_joinnew_pathr   r   r   rR      s     

ztest.paths_on_pythonpathc                 C   sD   |  | j}|  | jpg }|  dd | j D }t|||S )z
        Install the requirements indicated by self.distribution and
        return an iterable of the dists that were built.
        c                 s   s0   | ](\}}| d rt|dd r|V  qdS ):r   N)
startswithr   ).0kvr   r   r   	<genexpr>   s   z%test.install_dists.<locals>.<genexpr>)Zfetch_build_eggsZinstall_requiresZtests_requireZextras_requireitems	itertoolschain)rK   Zir_dZtr_dZer_dr   r   r   install_dists   s    
ztest.install_distsc              	   C   s   |  dtj | | j}d| j}| jr>|  d|  d S |  d|  tt	
d|}| |@ |   |   W d    n1 s0    Y  W d    n1 s0    Y  d S )NzWARNING: Testing via this command is deprecated and will be removed in a future version. Users looking for a generic test entry point independent of test runner are encouraged to use tox. zskipping "%s" (dry run)zrunning "%s"location)announcer   ZWARNri   r:   rZ   _argvdry_runmapoperator
attrgetterrR   rF   	run_tests)r   Zinstalled_distscmdr]   r   r   r   run   s    
ztest.runc                 C   s   t | jddrx| jdd }|tv rxg }|tjv r>|| |d7 }tjD ]}||rL|| qLt	t
tjj| tjd d | j| | j| | jdd}|j sd|j }| |tj t|d S )NrI   Fr   r   )Z
testLoaderZ
testRunnerexitzTest failed: %s)r;   r:   r5   splitr
   rC   rO   r!   ra   r>   ro   __delitem__unittestmainrm   _resolve_as_epr7   r8   resultZwasSuccessfulrl   r   ZERRORr   )r   r'   Zdel_modulesnamer1   r<   r   r   r   rr      s*    







ztest.run_testsc                 C   s   dg| j  S )Nrx   )r@   r   r   r   r   rm     s    z
test._argvc                 C   s$   | du rdS t d|  }|  S )zu
        Load the indicated attribute value, called, as a as if it were
        specified as an entry point.
        Nzx=)r   parseresolve)valparsedr   r   r   rz   	  s    ztest._resolve_as_epN)r$   r*   r+   __doc__descriptionZuser_optionsr9   r=   r,   r@   r?   rH   
contextlibcontextmanagerrF   staticmethodrR   ri   rt   rr   propertyrm   rz   r   r   r   r   r1   E   s,   
-

r1   )rV   rp   rC   r   rg   rx   Zdistutils.errorsr   r   Z	distutilsr   r   Zpkg_resourcesr   r   r   r	   r
   r   r   r   r   Z
setuptoolsr   Z setuptools.extern.more_itertoolsr   r   r,   r1   r   r   r   r   <module>   s   ,)
