From bd4bc4bdfcd1a70c041e710fa6f4e27548fed81b Mon Sep 17 00:00:00 2001 From: Kurt Grandis Date: Sat, 6 Mar 2010 03:56:30 -0500 Subject: [PATCH] initial stab at a nose plugin --- nose_exclude.py | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ setup.py | 12 ++++++++++ 2 files changed, 73 insertions(+) create mode 100644 nose_exclude.py create mode 100644 setup.py diff --git a/nose_exclude.py b/nose_exclude.py new file mode 100644 index 0000000..3cd0534 --- /dev/null +++ b/nose_exclude.py @@ -0,0 +1,61 @@ +import os +import logging +from nose.plugins import Plugin + +log = logging.getLogger('nose.plugins.nose-exclude') + +class NoseExclude(Plugin): + + def options(self, parser, env=os.environ): + """Define the command line options for the plugin.""" + super(NoseExclude, self).options(parser, env) + + parser.add_option( + "--exclude-dirs", action="append", + dest="exclude_dirs", + help="Directories to exclude from test discovery. \ + Paths can be relative to current working directory \ + or an absolute path. [NOSE_EXCLUDE_DIRS]") + + def configure(self, options, conf): + """Configure plugin based on command line options""" + super(NoseExclude, self).configure(options, conf) + + #TODO add logging + if not options.exclude_dirs: + self.enabled = False + return + + self.enabled = True + root = os.getcwd() + log.debug('cwd: %s' % root) + + cleaned_dirs = [] + for d in options.exclude_dirs: + if os.path.isabs(d): + cleaned_dirs.append(d) + elif os.path.isdir(d): + #see if it's relative + new_abs_d = os.path.join(root,d) + cleaned_dirs.append(new_abs_d) + else: + #bad path + #TODO + pass + + self.exclude_dirs = cleaned_dirs + + exclude_str = "excluding dirs: %s" % ",".join(self.exclude_dirs) + log.debug(exclude_str) + + def wantDirectory(self, dirname): + """Check if directory is eligible for test discovery""" + if dirname in self.exclude_dirs: + log.debug("excluded: %s" % dirname) + return False + else: + return True + + + + diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..89cffa1 --- /dev/null +++ b/setup.py @@ -0,0 +1,12 @@ +from setuptools import setup + +setup( + name = "nose-exclude", + version = "0.1.1", + py_modules = ['nose_exclude'], + + entry_points = { + 'nose.plugins': ['nose-exclude = nose_exclude:NoseExclude'] + }, + install_requires = ['nose'], +)