U
    Ze                     @   s   d Z zddlmZ W n ek
r0   d ZZY nNX ddlmZmZmZm	Z	m
Z
 ddlmZ ddlmZ dd ZG d	d
 d
eZdS )a  
nosetests setuptools command
----------------------------

The easiest way to run tests with nose is to use the `nosetests` setuptools
command::

  python setup.py nosetests

This command has one *major* benefit over the standard `test` command: *all
nose plugins are supported*.

To configure the `nosetests` command, add a [nosetests] section to your
setup.cfg. The [nosetests] section can contain any command line arguments that
nosetests supports. The differences between issuing an option on the command
line and adding it to setup.cfg are:

* In setup.cfg, the -- prefix must be excluded
* In setup.cfg, command line flags that take no arguments must be given an
  argument flag (1, T or TRUE for active, 0, F or FALSE for inactive)

Here's an example [nosetests] setup.cfg section::

  [nosetests]
  verbosity=1
  detailed-errors=1
  with-coverage=1
  cover-package=nose
  debug=nose.loader
  pdb=1
  pdb-failures=1

If you commonly run nosetests with a large number of options, using
the nosetests setuptools command and configuring with setup.cfg can
make running your tests much less tedious. (Note that the same options
and format supported in setup.cfg are supported in all other config
files, and the nosetests script will also load config files.)

Another reason to run tests with the command is that the command will
install packages listed in your `tests_require`, as well as doing a
complete build of your package before running tests. For packages with
dependencies or that build C extensions, using the setuptools command
can be more convenient than building by hand and running the nosetests
script.

Bootstrapping
-------------

If you are distributing your project and want users to be able to run tests
without having to install nose themselves, add nose to the setup_requires
section of your setup()::

  setup(
      # ...
      setup_requires=['nose>=1.0']
      )

This will direct setuptools to download and activate nose during the setup
process, making the ``nosetests`` command available.

    )CommandN)Configoption_blacklistuser_config_filesflag_bool)TestProgram)DefaultPluginManagerc                 C   s   g }| j D ]r}|jd dd tkr&q
|jd dd }|jdkrJ|d }d}|jrf|jd dd }||||jpvdf q
|S )zAconvert a optparse option list into a distutils option tuple listr      N
store_truestore_false=    )option_list
_long_optsr   action_short_optsappendhelp)parserZopt_listoptZ	long_nameZ
short_name r   l/mounts/lovelace/software/anaconda3/envs/qiime2-amplicon-2024.2/lib/python3.8/site-packages/nose/commands.pyget_user_optionsI   s    

r   c                   @   sP   e Zd ZdZee e dZe Z	e
e	Zdd Zdd Zdd Zd	d
 ZdS )	nosetestszRun unit tests using nosetests)filespluginsc                 C   sR   i | _ | jjD ]8}|jd dd }|dd}|| j |< t| |d qd| _dS )zWcreate the member variables, but change hyphens to
            underscores
            r   r
   N-_)option_to_cmds_nosetests__parserr   r   replacesetattrattr)selfr   cmd_nameoption_namer   r   r   initialize_options`   s    
znosetests.initialize_optionsc                 C   s   dS )znothing to do hereNr   )r&   r   r   r   finalize_optionsm   s    znosetests.finalize_optionsc              	   C   s0  t | jddrh| d}d|_|  | d}|j}| d}||_|  | d}d|_|  n"| d | d}d|_|  | jjr| j	| jj | jj
r| j	| jj
 | d}dd	|jg}t| j D ]>\}}	|tkrqt | |}
|
d
k	r|| |dd|
 qt|| jd d
S )zhensure tests are capable of being run, then
            run nose.main with a reconstructed argument listZuse_2to3Fbuild_pyr   egg_info	build_extr   r   z--whereNr    r   )argvconfig)getattrdistributionget_finalized_commandZinplacerun	build_libZegg_baserun_commandZinstall_requiresZfetch_build_eggsZtests_requirelistr!   itemsr   extendcfgToArgr#   r   _nosetests__config)r&   r+   Zbpy_cmdZ
build_pathr,   r-   Zei_cmdr.   r(   r'   valuer   r   r   r3   q   sF    








znosetests.runc                 C   s`   g }d| }| j |}|jdkrNt|s:td||f t|r\|| n|||g |S )Nz--r   zInvalid value '%s' for '%s')r"   
get_optionr   r   
ValueErrorr   r   r8   )r&   optnamer;   r.   Zlong_optnamer   r   r   r   r9      s    
 znosetests.cfgToArgN)__name__
__module____qualname__descriptionr   r   r	   r:   Z	getParserr"   r   user_optionsr)   r*   r3   r9   r   r   r   r   r   Y   s   /r   )__doc__
setuptoolsr   ImportErrorr   Znose.configr   r   r   r   r   Z	nose.corer   Znose.pluginsr	   r   r   r   r   r   <module>   s   =