U
    Zeb                     @   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 d dlmZm	Z	 d dl
mZ d dlmZmZ e eZddgZdd	gZd
Zededd G dd deZG dd deZG dd deZG dd deZG dd deZdd Zdd Zdd Zdd Z dS )     N)OptionParser)absdirtolist)	NoPlugins)warnfilterwarningshelpverbosez	~/.nosercz
~/nose.cfg)win32clialwaysz(.*\.)?nose\.config)categorymodulec                   @   s   e Zd Zdd ZdS )NoSuchOptionErrorc                 C   s   t | | || _d S N)	Exception__init__name)selfr    r   j/mounts/lovelace/software/anaconda3/envs/qiime2-amplicon-2024.2/lib/python3.8/site-packages/nose/config.pyr       s    zNoSuchOptionError.__init__N)__name__
__module____qualname__r   r   r   r   r   r      s   r   c                   @   s   e Zd ZdS )ConfigErrorN)r   r   r   r   r   r   r   r   %   s   r   c                   @   sR   e Zd ZdZdddZdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd ZdS )ConfiguredDefaultsOptionParserz@
    Handler for options from commandline and config files.
    Nc                    s@   || _ || _ d kr| j j  | _|d kr6 fdd}|| _d S )Nc                    s    | S r   r   )msgkwerrorr   r   <lambda>4       z9ConfiguredDefaultsOptionParser.__init__.<locals>.<lambda>)_parser_config_sectionr   _error_file_error)r   parserZconfig_sectionr   
file_errorr   r   r   r   -   s    z'ConfiguredDefaultsOptionParser.__init__c                 C   s<   g }| j | kr8|| j D ]\}}||||f q|S r   )r#   sectionsitemsappend)r   cfgfilenameconfigr   valuer   r   r   _configTuples7   s
    z,ConfiguredDefaultsOptionParser._configTuplesc                 C   st   g }|D ]f}t  }z|| W n8 t jk
rZ } ztd|t|f W 5 d }~X Y nX || || q|S )N Error reading config file %r: %s)configparserRawConfigParserreadErrorr   strextendr/   )r   	filenamesr-   r,   r+   excr   r   r   _readFromFilenames>   s    
z1ConfiguredDefaultsOptionParser._readFromFilenamesc              
   C   s   t  }z
|j}W n tk
r*   d}Y nX z|| W n8 t jk
rr } ztd|t|f W 5 d }~X Y nX | ||S )Nz<???>r0   )	r1   r2   r   AttributeErrorreadfpr4   r   r5   r/   )r   fhr+   r,   r8   r   r   r   _readFromFileObjectJ   s    


z2ConfiguredDefaultsOptionParser._readFromFileObjectc                 C   sV   z
|j  W n8 tk
rB   |}t|tr0|g}n|}| |}Y nX |}| |}|S r   )readliner:   
isinstancer5   r9   r=   )r   config_filesZfilename_or_filenamesr7   r-   r<   r   r   r   _readConfigurationW   s    


z1ConfiguredDefaultsOptionParser._readConfigurationc                 C   s8   d| }| |}|d kr$t|n||||| d S )N--)
get_optionr   process)r   r   r.   valuesr&   opt_stroptionr   r   r   _processConfigValuef   s
    

z2ConfiguredDefaultsOptionParser._processConfigValuec           	      C   s   |D ]\}}}|t krqz| |||| W q tk
rh } z| jd||jf ||d W 5 d }~X Y q tjk
r } z6t|d| t	|d}| jd||f ||d W 5 d }~X Y qX qd S )Nz/Error reading config file %r: no such option %r)r   r,   rB      r0   )
option_blacklistrH   r   r%   r   optparseOptionValueErrorr5   replacerepr)	r   r&   r-   rE   r   r.   r,   r8   r   r   r   r   _applyConfigurationToValuesn   s*      z:ConfiguredDefaultsOptionParser._applyConfigurationToValuesc              
   C   s   | j  }z| |}W n0 tk
rH } z| t| W 5 d }~X Y nHX z| | j || W n0 tk
r } z| t| W 5 d }~X Y nX | j ||S r   )r"   get_default_valuesrA   r   r$   r5   rO   
parse_args)r   argsr@   rE   r-   r8   r   r   r   parseArgsAndConfigFiles   s    
  z6ConfiguredDefaultsOptionParser.parseArgsAndConfigFiles)NN)r   r   r   __doc__r   r/   r9   r=   rA   rH   rO   rS   r   r   r   r   r   )   s   

r   c                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 ZeZd
d Z	d!ddZ
dd Zdd Zdd Zd"ddZd#ddZdd Zdd Zdd Zdd  ZdS )$ConfigaD  nose configuration.

    Instances of Config are used throughout nose to configure
    behavior, including plugin lists. Here are the default values for
    all config keys::

      self.env = env = kw.pop('env', {})
      self.args = ()
      self.testMatch = re.compile(r'(?:^|[\b_\.%s-])[Tt]est' % os.sep)
      self.addPaths = not env.get('NOSE_NOPATH', False)
      self.configSection = 'nosetests'
      self.debug = env.get('NOSE_DEBUG')
      self.debugLog = env.get('NOSE_DEBUG_LOG')
      self.exclude = None
      self.getTestCaseNamesCompat = False
      self.includeExe = env.get('NOSE_INCLUDE_EXE',
                                sys.platform in exe_allowed_platforms)
      self.ignoreFiles = (re.compile(r'^\.'),
                          re.compile(r'^_'),
                          re.compile(r'^setup\.py$')
                          )
      self.include = None
      self.loggingConfig = None
      self.logStream = sys.stderr
      self.options = NoOptions()
      self.parser = None
      self.plugins = NoPlugins()
      self.srcDirs = ('lib', 'src')
      self.runOnInit = True
      self.stopOnError = env.get('NOSE_STOP', False)
      self.stream = sys.stderr
      self.testNames = ()
      self.verbosity = int(env.get('NOSE_VERBOSE', 1))
      self.where = ()
      self.py3where = ()
      self.workingDir = None
    c                 K   s`  | di  | _}d| _|ddtj | _t| j| _	|dd | _
d| _|d| _|d	| _d | _d| _|d
tjtk| _dddg| _tttj| j| _d | _d | _tj| _t | _d | _t | _ d| _!d| _"|dd| _#tj| _$g | _%t&|dd| _'d| _(d| _)t* | _+d| _,d| _-t.| _/d| _0| j12 | _3| 4| | j12 | _5d S )Nenvr   ZNOSE_TESTMATCHz(?:^|[\b_\.%s-])[Tt]estZNOSE_NOPATHFZ	nosetestsZ
NOSE_DEBUGZNOSE_DEBUG_LOGZNOSE_INCLUDE_EXEz^\.z^_z^setup\.py$)libsrcTZ	NOSE_STOPZNOSE_VERBOSErI   )6poprV   rR   getosseptestMatchPatrecompile	testMatchaddPathsconfigSectiondebugdebugLogexcludeZgetTestCaseNamesCompatsysplatformexe_allowed_platforms
includeExeignoreFilesDefaultStringslistmapignoreFilesincludeloggingConfigstderr	logStream	NoOptionsoptionsr&   r   pluginsZsrcDirsZ	runOnInitstopOnErrorstream	testNamesint	verbositywherepy3wheregetcwd
workingDirtraverseNamespacefirstPackageWinsr   parserClassworker__dict__copy_defaultupdate_orig)r   r   rV   r   r   r   r      sT    

zConfig.__init__c                 C   s8   | j  }|d= |d= |d= |d= |d= | jj|d< |S )Nrv   r   r   rV   rq   rt   )r   r   rt   	__class__r   stater   r   r   __getstate__   s    
zConfig.__getstate__c                 C   sV   | d}| | d| _| | _| j  |  }| j|i  | j| j|  d S )Nrt   T)	rY   r   r   rt   loadPluginsr   
addOptions	configurers   )r   r   Z	pluginclsZdummy_parserr   r   r   __setstate__   s    


zConfig.__setstate__c                    sL   | j   i  d< dd t  D }|  dd fdd|D  S )NrV   c                 S   s   g | ]}| d s|qS )_)
startswith.0kr   r   r   
<listcomp>   s    
z#Config.__repr__.<locals>.<listcomp>z
Config(%s)z, c                    s   g | ]}d | | f qS )z%s=%rr   r   dr   r   r      s   )r   r   rk   keyssortjoin)r   r   r   r   r   __repr__   s    
zConfig.__repr__c                    s6   d fdd	}t    j|d}||dd  |S )Nc                    s<   t  jdr0 j|r0d||f } t| t nt| d S )NexcludedOptionzDOption %r in config file %r ignored: excluded by runtime environment)hasattrrt   r   r   RuntimeWarningr   )r   r   r,   r   r   r   warn_sometimes  s    
z)Config._parseArgs.<locals>.warn_sometimes)r'   rI   )NN)r   	getParserrb   rS   )r   argv	cfg_filesr   r&   r   r   r   
_parseArgs  s    	  zConfig._parseArgsNc                 C   s0  | j }|dkrtj}t| dg }| ||\}}t|dg rN| ||j\}}|| _|r^|| _|jdk	rz| jt	|j |j
dk	rtjdkr|j
|_|js|dd|_|js|dg |_|js|dg |_|js|dg |_|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _|   |jsDdt_|jdk	r\| |j |jrrt |j| _|jrt!t"tj t	|j| _t#$d	|j nt#$d	| j% |jrt!t"tj t	|j| _t#$d
|j |jrt!t"tj t	|j| _t#$d|j |j&s,| j'(||  | j')  dS )zConfigure the nose running environment. Execute configure before
        collecting tests with nose.TestCollector to enable output capture and
        other features.
        Nfiles)   Z
NOSE_WHEREZNOSE_IGNORE_FILESZNOSE_INCLUDEZNOSE_EXCLUDETzIgnoring files matching %szIncluding tests matching %szExcluding tests matching %s)*rV   rf   r   getattrr   r   rs   rw   r6   r   r{   version_inforz   rZ   rm   rn   re   ra   ru   ry   ri   r~   rc   rd   ro   r   configureLoggingbyteCompiledont_write_bytecodeconfigureWherer`   r^   r_   rk   rl   loginforj   showPluginsrt   r   begin)r   r   docrV   r   rs   rR   r   r   r   r     sh    


zConfig.configurec                 C   s  | j r ddlm} || j  dS td}| jr>t| j}nt| j}|	| t
d}d|_d}| jrtj| j}|jD ] }t|tjkr|j|krd}qn*|jD ]"}t|tjkr|j| jkrd}q|s|| tj}| jdkrd}n&| jd	krtj}n| jd
krtj}|| | jrdd | jdD }	|	D ]:}
t
|
}|tj |jsF|
dsF|| qFdS )a  Configure logging for nose, or optionally other packages. Any logger
        name may be set with the debug option, and that logger will be set to
        debug level and be assigned the same handler as the nose loggers, unless
        it already has a handler.
        r   )
fileConfigNz$%(name)s: %(levelname)s: %(message)snoseFT      r   c                 S   s   g | ]}|r|qS r   r   )r   r   r   r   r   r     s    z+Config.configureLogging.<locals>.<listcomp>,)ro   logging.configr   logging	Formatterrd   FileHandlerStreamHandlerrq   setFormatter	getLogger	propagater[   pathabspathhandlerstypebaseFilenamerv   
addHandlerWARNINGry   DEBUGINFOsetLevelrc   splitr   )r   r   formathandlerloggerfoundZdebugLogAbsPathhZlvlZdebug_loggersZlogger_namelr   r   r   r   ]  sR    










zConfig.configureLoggingc                 C   s   ddl m} d| _t|}d}|D ]}| jst|}|dkrHtd| td| || _| jr"t	j
t	j
|dr"td|  || q"|std	t d
}| j| q"dS )zIConfigure the working directory or directories for the test run.
        r   )add_pathNFz4Working directory '%s' not found, or not a directoryzSet working dir to %sz__init__.pyz5Working directory %s is a package; adding to sys.pathzUse of multiple -w arguments is deprecated and support may be removed in a future release. You can get the same behavior by passing directories without the -w argument on the command line, or by using the --tests argument in a configuration file.T)Znose.importerr   r}   r   r   
ValueErrorr   r   ra   r[   r   existsr   r   DeprecationWarningrw   r*   )r   rz   r   Zwarnedr   abs_pathr   r   r   r     s6    zConfig.configureWherec                 C   s   | j | j dS )z-Reset all config values to defaults.
        N)r   r   r   r   r   r   r   default  s    zConfig.defaultc              
   C   sH  | j r| j S | j}| |}|jddddddd |jdd	dd
ddd |jdddd| jdd |jddddddd |jddddddd |jdddd d!d"d# |jd$d%dd&d'd(d# |jd)dd*d+d,d# |jd-d.d/dd0d1d2| j | jd3 |jd4dd5d6d7d8d9 |jd:d;dd<| jd=d |jd>d?d| jd@dAdB |jdCdDdEd| jd@dFdB |jdGdHddId1dJd# |jdKdLddMd1dNd# |jdOdPddQd1dRd# |jdSdTddU| j	dVd |jdWdXdYdZ| j
d[d |jd\dd]| jd^d |jd_dYd]d`da |jdbd| jdcddde |jdfdgdhdddidjde |jdkdYdldmdnde | j  | | || _ |S )oz,Get the command line option parser.
        z-Vz	--version
store_trueversionFzOutput nose version and exit)actiondestr   r   z-pz	--pluginsr   z[Output list of available plugins and exit. Combine with higher verbosity for greater detailz-vz	--verbosecountry   zBe more verbose. [NOSE_VERBOSE]z--verbositystoreZ	VERBOSITYrx   z.Set verbosity; --verbosity=2 is the same as -v)r   r   metavarr   r   z-qz--quietstore_constr   zBe less verbose)r   constr   r   z-cz--configr*   r   ZFILESzLoad configuration from config file(s). May be specified multiple times; in that case, all config files will be loaded and combined)r   r   r   r   z-wz--whererz   ZWHEREa  Look for tests in this directory. May be specified multiple times. The first directory passed will be used as the working directory, in place of the current working directory, which is the default. Others will be added to the list of tests to execute. [NOSE_WHERE]z
--py3wherer{   ZPY3WHEREa-  Look for tests in this directory under Python 3.x. Functions the same as 'where', but only applies if running under Python 3.x or above.  Note that, if present under 3.x, this option completely replaces any directories specified with 'where', so the 'where' option becomes ineffective. [NOSE_PY3WHERE]z-mz--matchz--testmatchr`   ZREGEXzFiles, directories, function names, and class names that match this regular expression are considered tests.  Default: %s [NOSE_TESTMATCH])r   r   r   r   r   z--testsrw   NZNAMESzRun these tests (comma-separated list). This argument is useful mainly from configuration files; on the command line, just pass the tests to run as additional arguments with no switch.)r   r   r   r   r   z-lz--debugrc   zActivate debug logging for one or more systems. Available debug loggers: nose, nose.importer, nose.inspector, nose.plugins, nose.result and nose.selector. Separate multiple names with a comma.z--debug-logrd   FILEz5Log debug messages to this file (default: sys.stderr))r   r   r   r   r   z--logging-configz--log-configro   zQLoad logging config from this file -- bypasses all other logging config settings.z-Iz--ignore-filesrm   a  Completely ignore any file that matches this regular expression. Takes precedence over any other settings or plugins. Specifying this option will replace the default setting. Specify this option multiple times to add more regular expressions [NOSE_IGNORE_FILES]z-ez	--excludere   z<Don't run tests that match regular expression [NOSE_EXCLUDE]z-iz	--includern   zThis regular expression will be applied to files, directories, function names, and class names for a chance to include additional tests that do not match TESTMATCH.  Specify this option multiple times to add more regular expressions [NOSE_INCLUDE]z-xz--stopru   z3Stop running tests after the first error or failurez-Pz--no-path-adjustmentstore_falsera   zCDon't make any changes to sys.path when loading tests [NOSE_NOPATH]z--exeri   zLook for tests in python modules that are executable. Normal behavior is to exclude executable modules, since they may not be import-safe [NOSE_INCLUDE_EXE]z--noexezoDO NOT look for tests in python modules that are executable. (The default on the windows platform is to do so.))r   r   r   z--traverse-namespacer~   z8Traverse through all path entries of a namespace package)r   r   r   r   z--first-package-winsz--first-pkg-winsz--1st-pkg-winsr   znose's importer will normally evict a package from sys.modules if it sees a package with the same name in a different location. Set this option to disable that behavior.z--no-byte-compileTr   ziPrevent nose from byte-compiling the source into .pyc files while nose is scanning for and running tests.)r&   rV   r   
add_optionry   r]   rc   rd   ro   ru   ra   ri   r~   rt   r   
pluginOpts)r   r   rV   r&   r   r   r   r     s   
                     	  
                   	                       

zConfig.getParserc                 C   s   |  | S )z*Return the generated help message
        )r   format_help)r   r   r   r   r   r   T  s    zConfig.helpc                 C   s   | j || j d S r   )rt   r   rV   )r   r&   r   r   r   r   Y  s    zConfig.pluginOptsc                 C   s   | j | j d S r   )r   r   r   r   r   r   r   reset\  s    zConfig.resetc                 C   s
   | j  S r   )r   r   r   r   r   r   todict_  s    zConfig.todictc                 C   s   | j | d S r   )r   r   )r   r   r   r   r   r   b  s    zConfig.update)NN)N)N)r   r   r   rT   r   r   r   r   __str__r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rU      s$   &+	
N;
 
rU   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )rr   z9Options container that returns None for all options.
    c                 C   s   i S r   r   r   r   r   r   r   i  s    zNoOptions.__getstate__c                 C   s   d S r   r   r   r   r   r   r   l  s    zNoOptions.__setstate__c                 C   s   dS )Nr   r   r   r   r   r   __getnewargs__o  s    zNoOptions.__getnewargs__c                 C   s   dS )NFr   r   r   r   r   __bool__r  s    zNoOptions.__bool__N)r   r   r   rT   r   r   r   r   r   r   r   r   rr   f  s
   rr   c                   C   s    t ttjjt ttjjtS )z2Return path to any existing user config files
    )rk   filterr[   r   r   rl   
expanduserr@   r   r   r   r   user_config_filesv  s    
r   c                  C   s    t  } tjdr| dg S | S )zlReturn path to any existing user config files, plus any setup.cfg
    in the current working directory.
    z	setup.cfg)r   r[   r   r   )userr   r   r   all_config_files}  s    
r   c                 C   s<   | dkrdS | dkrdS t | } t| dkr0dS |  dkS )z(Does the value look like an on/off flag?rI   Tr   Fr   )10FTTRUEFALSEONZOFF)r5   lenuppervalr   r   r   flag  s    r   c                 C   s   t |  dkS )N)r   r   r   r   )r5   r   r   r   r   r   _bool  s    r   )!r   rK   r[   r^   rf   r1   r   Z	nose.utilr   r   Znose.plugins.managerr   warningsr   r   r   r   r   rJ   r@   rh   r   r   r   r   objectr   rU   rr   r   r   r   r   r   r   r   r   <module>   s<   
	d   \