B t `b@sddlZddlZddlZddlZddlZddlZddlmZddlmZm Z ddl m Z ddl m Z mZeeZddgZdd gZd Zed ed d GdddeZGdddeZGdddeZGdddeZGdddeZddZddZddZddZ dS) N) OptionParser)absdirtolist) NoPlugins)warnfilterwarningshelpverbosez ~/.nosercz ~/nose.cfg)win32clialwaysz(.*\.)?nose\.config)categorymodulec@seZdZddZdS)NoSuchOptionErrorcCst||||_dS)N) Exception__init__name)selfrr//tmp/pip-unpacked-wheel-cjhnoqsi/nose/config.pyr s zNoSuchOptionError.__init__N)__name__ __module__ __qualname__rrrrrrsrc@s eZdZdS) ConfigErrorN)rrrrrrrr%src@sReZdZdZdddZddZddZd d Zd d Zd dZ ddZ ddZ dS)ConfiguredDefaultsOptionParserz@ Handler for options from commandline and config files. Ncs@||_||_dkr|jj|_|dkr6fdd}||_dS)Ncs|S)Nr)msgkw)errorrr4z9ConfiguredDefaultsOptionParser.__init__..)_parser_config_sectionr_error _file_error)rparserZconfig_sectionr file_errorr)rrr-s z'ConfiguredDefaultsOptionParser.__init__cCs@g}|j|krs "z1ConfiguredDefaultsOptionParser._readFromFilenamesc Cst}y |j}Wntk r*d}YnXy||Wn8tjk rr}ztd|t|fWdd}~XYnX|||S)Nzz Error reading config file %r: %s) r.r/rAttributeErrorreadfpr1rr2r-)rfhr)r*r5rrr_readFromFileObjectJs  "z2ConfiguredDefaultsOptionParser._readFromFileObjectcCsVy |jWn8tk rB|}t|tr0|g}n|}||}YnX|}||}|S)N)readliner7 isinstancer2r6r:)r config_filesZfilename_or_filenamesr4r+r9rrr_readConfigurationWs   z1ConfiguredDefaultsOptionParser._readConfigurationcCs8d|}||}|dkr$t|n|||||dS)Nz--) get_optionrprocess)rrr,valuesr$opt_stroptionrrr_processConfigValuefs   z2ConfiguredDefaultsOptionParser._processConfigValuec Csx|D]\}}}|tkrqy|||||Wqtk rj}z|jd||jf||dWdd}~XYqtjk r}z6t|d|t |d}|jd||f||dWdd}~XYqXqWdS)Nz/Error reading config file %r: no such option %r)rr*z--z Error reading config file %r: %s) option_blacklistrDrr#roptparseOptionValueErrorr2replacerepr) rr$r+rArr,r*r5rrrr_applyConfigurationToValuesns z:ConfiguredDefaultsOptionParser._applyConfigurationToValuesc Cs|j}y||}Wn0tk rH}z|t|Wdd}~XYnHXy||j||Wn0tk r}z|t|Wdd}~XYnX|j||S)N)r get_default_valuesr>rr"r2rK parse_args)rargsr=rAr+r5rrrparseArgsAndConfigFiless   z6ConfiguredDefaultsOptionParser.parseArgsAndConfigFiles)NN) rrr__doc__rr-r6r:r>rDrKrOrrrrr)s   rc@seZdZdZddZddZddZdd ZeZd d Z d!d dZ ddZ ddZ ddZ d"ddZd#ddZddZddZddZdd Zd S)$ConfigaDnose 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 cKs`|di|_}d|_|ddtj|_t|j|_ |dd |_ d|_ |d|_ |d |_ d|_d|_|d tjtk|_d d d g|_tttj|j|_d|_d|_tj|_t|_d|_t|_ d|_!d|_"|dd|_#tj|_$g|_%t&|dd|_'d|_(d|_)t*|_+d|_,d|_-t.|_/d|_0|j12|_3|4||j12|_5dS)NenvrZNOSE_TESTMATCHz(?:^|[\b_\.%s-])[Tt]estZ NOSE_NOPATHFZ nosetestsZ NOSE_DEBUGZNOSE_DEBUG_LOGZNOSE_INCLUDE_EXEz^\.z^_z ^setup\.py$)libsrcTZ NOSE_STOPZ NOSE_VERBOSErE)6poprRrNgetossep testMatchPatrecompile testMatchaddPaths configSectiondebugdebugLogexcludeZgetTestCaseNamesCompatsysplatformexe_allowed_platforms includeExeignoreFilesDefaultStringslistmap ignoreFilesinclude loggingConfigstderr logStream NoOptionsoptionsr$rpluginsZsrcDirsZ runOnInit stopOnErrorstream testNamesint verbositywherepy3wheregetcwd workingDirtraverseNamespacefirstPackageWinsr parserClassworker__dict__copy_defaultupdate_orig)rrrRrrrrsN     zConfig.__init__cCs8|j}|d=|d=|d=|d=|d=|jj|d<|S)NrrrrrRrmrp)r~rrp __class__)rstaterrr __getstate__s  zConfig.__getstate__cCsV|d}||d|_||_|j|}|j|i|j|j|dS)NrpT) rUrr}rp loadPluginsr| addOptions configurero)rrZ pluginclsZ dummy_parserrrr __setstate__s   zConfig.__setstate__csL|jid<ddtD}|ddfdd|DS)NrRcSsg|]}|ds|qS)_) startswith).0krrr sz#Config.__repr__..z Config(%s)z, csg|]}d||fqS)z%s=%rr)rr)drrrs)r~rrgkeyssortjoin)rrr)rr__repr__s  zConfig.__repr__cs6dfdd }tj|d}||dd|S)Ncs<tjdr0j|r0d||f}t|tnt|dS)NexcludedOptionzDOption %r in config file %r ignored: excluded by runtime environment)hasattrrprrRuntimeWarningr)rrr*)rrrwarn_sometimess     z)Config._parseArgs..warn_sometimes)r%rE)NN)r getParserr^rO)rargv cfg_filesrr$r)rr _parseArgss zConfig._parseArgsNcCs0|j}|dkrtj}t|dg}|||\}}t|dgrN|||j\}}||_|r^||_|jdk rz|jt |j|j dk rtj dkr|j |_ |j s| dd|_ |js| dg|_|js| dg|_|js| dg|_|j|_|j|_|j|_|j|_|j|_|j|_|j|_|j|_|j|_||jsDdt_|j dk r\||j |jrrt |j|_|jrt!t"tj t |j|_t#$d |jnt#$d |j%|jrt!t"tj t |j|_t#$d |j|jr t!t"tj t |j|_t#$d |j|j&s,|j'(|||j')dS) zConfigure the nose running environment. Execute configure before collecting tests with nose.TestCollector to enable output capture and other features. Nfiles)Z NOSE_WHEREZNOSE_IGNORE_FILESZ NOSE_INCLUDEZ NOSE_EXCLUDETzIgnoring files matching %szIncluding tests matching %szExcluding tests matching %s)*rRrbrgetattrrrrorsr3rrw version_inforvrVrirjrar]rqrurerzr_r`rkr{configureLogging byteCompiledont_write_bytecodeconfigureWherer\rZr[rgrhloginforf showPluginsrprbegin)rrdocrRrrorNrrrrsh       zConfig.configurec Cs|jr ddlm}||jdStd}|jr>t|j}n t|j}| |t d}d|_ d}|jrt j |j}xZ|jD] }t|tjkr|j|krd}qWn.x,|jD]"}t|tjkr|j|jkrd}qW|s||tj}|jdkrd}n&|jd krtj}n|jd kr"tj}|||jrd d |jd D} xB| D]:} t | } | tj| jsP| dsP| |qPWdS)aConfigure 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)sZnoseFTrcSsg|] }|r|qSrr)rrrrrrsz+Config.configureLogging..,)rklogging.configrlogging Formatterr` FileHandler StreamHandlerrm setFormatter getLogger propagaterWpathabspathhandlerstype baseFilenamerr addHandlerWARNINGruDEBUGINFOsetLevelr_splitr) rrformathandlerloggerfoundZdebugLogAbsPathhZlvlZ debug_loggersZ logger_namelrrrr]sN                   zConfig.configureLoggingcCsddlm}d|_t|}d}x|D]}|jst|}|dkrJtd|td|||_|jr$t j t j |dr$td|||q$|st d td }|j|q$WdS) zIConfigure the working directory or directories for the test run. r)add_pathNFz4Working directory '%s' not found, or not a directoryzSet 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.importerrryrr ValueErrorrrr]rWrexistsrrDeprecationWarningrsr()rrvrZwarnedrabs_pathrrrrs.   zConfig.configureWherecCs|j|jdS)z-Reset all config values to defaults. N)r~rr)rrrrdefaultszConfig.defaultc CsH|jr |jS|j}||}|jddddddd|jdd dd dd d|jd d dd|jdd|jddddddd|jddddddd|jdddd d!d"d#|jd$d%dd&d'd(d#|jd)dd*d+d,d#|jd-d.d/dd0d1d2|j|jd3|jd4dd5d6d7d8d9|jd:d;dd<|jd=d|jd>d?d|jd@dAdB|jdCdDdEd|jd@dFdB|jdGdHddId1dJd#|jdKdLddMd1dNd#|jdOdPddQd1dRd#|jdSdTddU|j dVd|jdWdXdYdZ|j d[d|jd\dd]|j d^d|jd_dYd]d`da|jdbd|j dcddde|jdfdgdhdddidjde|jdkdYdldmdnde|j ||||_|S)oz,Get the command line option parser. z-Vz --version store_trueversionFzOutput nose version and exit)actiondestrrz-pz --pluginsrz[Output list of available plugins and exit. Combine with higher verbosity for greater detailz-vz --verbosecountruzBe more verbose. [NOSE_VERBOSE]z --verbositystoreZ VERBOSITYrtz.Set verbosity; --verbosity=2 is the same as -v)rrmetavarrrz-qz--quiet store_constrzBe less verbose)rconstrrz-cz--configr(rZFILESzLoad configuration from config file(s). May be specified multiple times; in that case, all config files will be loaded and combined)rrrrz-wz--wherervZWHEREaLook 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 --py3whererwZPY3WHEREa-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\ZREGEXzFiles, directories, function names, and class names that match this regular expression are considered tests. Default: %s [NOSE_TESTMATCH])rrrrrz--testsrsNZNAMESzRun 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.)rrrrrz-lz--debugr_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-logr`FILEz5Log debug messages to this file (default: sys.stderr))rrrrrz--logging-configz --log-configrkzQLoad logging config from this file -- bypasses all other logging config settings.z-Iz--ignore-filesriaCompletely 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 --excluderazs8   d\