示例#1
0
    def test_ignore_files_default(self):
        """A default configuration should always skip some 'hidden' files."""
        s = Selector(Config())

        assert not s.wantFile('_test_underscore.py')
        assert not s.wantFile('.test_hidden.py')
        assert not s.wantFile('setup.py')
示例#2
0
 def test_ignore_files_default(self):
     """A default configuration should always skip some 'hidden' files."""
     s = Selector(Config())
     
     assert not s.wantFile('_test_underscore.py')
     assert not s.wantFile('.test_hidden.py')
     assert not s.wantFile('setup.py')
示例#3
0
class NoseSelectPlugin(Plugin):
    """Selects test to run based on tests names matching a pattern."""

    def options(self, parser, env):
        """Register command line options"""
        parser.add_option("-t", "--select-tests",
                          dest="selection_criteria", action="append",
                          default=list(),
                          metavar="SELECT",
                          help="Only run tests with a name matching a case-insensitive glob pattern (See fnmatch)")

    def _as_pattern(self, criterion):
        # transforms selection criteria in glob patterns
        return '*%s*' % criterion.lower().strip('*')

    def add_criterion(self, criterion):
        #used mostly for testing
        if not hasattr(self, 'selection_criteria'):
            self.selection_criteria = []
        self.selection_criteria.append(self._as_pattern(criterion))

    def configure(self, options, config):
        self.selection_criteria = [self._as_pattern(criterion) 
                                   for criterion in options.selection_criteria
                                   if criterion and criterion.strip()]

        if self.selection_criteria:
            self.enabled = True

        # use a base selector to ensure we are additive to the basic selection
        self.base_selector = Selector(config)
        self.base_selector.configure(config)
        # we use a mock for plugins to avoid our plugin to be called 
        # in a loop from the Selector (and avoid an infinite loop)
        self.base_selector.plugins = MockPlugins()

    def _is_selected(self, test_obj):
        """Return True if a test object should be selected based on criteria pattern."""
        if not test_obj:
            return
        if isinstance(test_obj, basestring):
            name = test_obj
        else:
            name = objname(test_obj)
        #log.debug('object name: %r' % name)
        if name:
            name = name.lower()
            matched = lambda pat: fnmatch(name, pat)
            selected = any(matched(pat) for pat in self.selection_criteria)
            #log.debug('selected:%r name: %r' % (selected, name,))
            return selected
        else:
            return False

    def wantMethod(self, method):
        return self.base_selector.wantMethod(method) and self._is_selected(method)

    def wantFunction(self, function):
        return self.base_selector.wantFunction(function) and self._is_selected(function)
示例#4
0
 def test_ignore_files_override(self):
     """Override the configuration to skip only specified files."""
     c = Config()
     c.ignoreFiles = [re.compile(r'^test_favourite_colour\.py$')]
     s = Selector(c)
     
     assert s.wantFile('_test_underscore.py')
     assert s.wantFile('.test_hidden.py')
     assert not s.wantFile('setup.py') # Actually excluded because of testMatch
     assert not s.wantFile('test_favourite_colour.py')
示例#5
0
    def test_want_class(self):
        class Foo:
            pass

        class Bar(unittest.TestCase):
            pass

        class TestMe:
            pass

        class TestType(type):
            def __new__(cls, name, bases, dct):
                return type.__new__(cls, name, bases, dct)

        class TestClass(object):
            __metaclass__ = TestType

        s = Selector(Config())
        assert not s.wantClass(Foo)
        assert s.wantClass(Bar)
        assert s.wantClass(TestMe)
        assert s.wantClass(TestClass)

        TestMe.__test__ = False
        assert not s.wantClass(TestMe), "Failed to respect __test__ = False"
        Bar.__test__ = False
        assert not s.wantClass(Bar), "Failed to respect __test__ = False"
示例#6
0
    def configure(self, options, config):
        self.selection_criteria = [
            self._as_pattern(criterion)
            for criterion in options.selection_criteria
            if criterion and criterion.strip()
        ]

        if self.selection_criteria:
            self.enabled = True

        # use a base selector to ensure we are additive to the basic selection
        self.base_selector = Selector(config)
        self.base_selector.configure(config)
        # we use a mock for plugins to avoid our plugin to be called
        # in a loop from the Selector (and avoid an infinite loop)
        self.base_selector.plugins = MockPlugins()
示例#7
0
    def test_want_function(self):
        def foo():
            pass
        def test_foo():
            pass
        def test_bar():
            pass
        
        s = Selector(Config())
        assert s.wantFunction(test_bar)
        assert s.wantFunction(test_foo)
        assert not s.wantFunction(foo)

        test_foo.__test__ = False
        assert not s.wantFunction(test_foo), \
               "Failed to respect __test__ = False"
示例#8
0
    def test_want_function(self):
        def foo():
            pass
        def test_foo():
            pass
        def test_bar():
            pass
        
        s = Selector(Config())
        assert s.wantFunction(test_bar)
        assert s.wantFunction(test_foo)
        assert not s.wantFunction(foo)

        test_foo.__test__ = False
        assert not s.wantFunction(test_foo), \
               "Failed to respect __test__ = False"
示例#9
0
    def test_exclude(self):
        s = Selector(Config())
        c = Config()
        c.exclude = [re.compile(r'me')]
        s2 = Selector(c)

        assert s.matches('test_foo')
        assert s2.matches('test_foo')
        assert s.matches('test_me')
        assert not s2.matches('test_me')
示例#10
0
    def test_want_class(self):
        class Foo:
            pass

        class Bar(unittest.TestCase):
            pass

        class TestMe:
            pass

        class TestType(type):
            def __new__(cls, name, bases, dct):
                return type.__new__(cls, name, bases, dct)

        class TestClass(object, metaclass=TestType):
            pass

        s = Selector(Config())
        assert not s.wantClass(Foo)
        assert s.wantClass(Bar)
        assert s.wantClass(TestMe)
        assert s.wantClass(TestClass)

        TestMe.__test__ = False
        assert not s.wantClass(TestMe), "Failed to respect __test__ = False"
        Bar.__test__ = False
        assert not s.wantClass(Bar), "Failed to respect __test__ = False"
示例#11
0
class SynchroNosePlugin(Plugin):
    name = 'synchro'

    def __init__(self, *args, **kwargs):
        # We need a standard Nose selector in order to filter out methods that
        # don't match TestSuite.test_*
        self.selector = Selector(config=None)
        super(SynchroNosePlugin, self).__init__(*args, **kwargs)

    def configure(self, options, conf):
        super(SynchroNosePlugin, self).configure(options, conf)
        self.enabled = True

    def wantModule(self, module):
        for module_name in excluded_modules:
            if module_name.endswith('*'):
                if module.__name__.startswith(module_name.rstrip('*')):
                    # E.g., test_motor_cursor matches "test_motor_*".
                    excluded_modules_matched.add(module_name)
                    return False

            elif module.__name__ == module_name:
                return False

        return True

    def wantFunction(self, fn):
        # PyMongo's test generators run at import time; tell Nose not to run
        # them as unittests.
        if fn.__name__ in ('test_cases', 'create_test',
                           'create_selection_tests'):
            return False

    def wantMethod(self, method):
        # Run standard Nose checks on name, like "does it start with test_"?
        if not self.selector.matches(method.__name__):
            return False

        for excluded_name in excluded_tests:
            if PY3:
                classname = method.__self__.__class__.__name__
            else:
                classname = method.im_class.__name__

            # Should we exclude this method's whole TestCase?
            suite_name, method_name = excluded_name.split('.')
            suite_matches = (suite_name == classname or suite_name == '*')

            # Should we exclude this particular method?
            method_matches = (method.__name__ == method_name
                              or method_name == '*')

            if suite_matches and method_matches:
                excluded_tests_matched.add(excluded_name)
                return False

        return True
示例#12
0
 def configure(self, options, conf):
     super(Plugin, self).configure(options, conf)
     if options.only_focus and options.just_ignore:
         raise optparse.OptionError("Please specify only one --with-focus or --without-ignored", "--with-focus")
     self.enabled = options.only_focus or options.just_ignore or options.only_include_filename
     self.lineage.selector = Selector(conf)
     self.only_focus = options.only_focus
     self.just_ignore = options.just_ignore
     self.only_include_filename = options.only_include_filename
     self.logger = logging.getLogger('{0}.{1}'.format(__name__, type(self).__name__))
示例#13
0
 def test_want_method(self):
     class Baz:
         def test_me(self):
             pass
         def test_too(self):
             pass
         def other(self):
             pass
         def test_not_test(self):
             pass
         test_not_test.__test__ = False
         
     s = Selector(Config())
     
     assert s.wantMethod(Baz.test_me)
     assert s.wantMethod(Baz.test_too)
     assert not s.wantMethod(Baz.other)
     assert not s.wantMethod(Baz.test_not_test), \
            "Failed to respect __test__ = False"
示例#14
0
    def configure(self, options, config):
        self.selection_criteria = [self._as_pattern(criterion) 
                                   for criterion in options.selection_criteria
                                   if criterion and criterion.strip()]

        if self.selection_criteria:
            self.enabled = True

        # use a base selector to ensure we are additive to the basic selection
        self.base_selector = Selector(config)
        self.base_selector.configure(config)
        # we use a mock for plugins to avoid our plugin to be called 
        # in a loop from the Selector (and avoid an infinite loop)
        self.base_selector.plugins = MockPlugins()
示例#15
0
    def test_want_directory(self):
        s = Selector(Config())
        assert s.wantDirectory('test')
        assert not s.wantDirectory('test/whatever')
        assert s.wantDirectory('whatever/test')
        assert not s.wantDirectory('/some/path/to/unit_tests/support')

        # default src directory
        assert s.wantDirectory('lib')
        assert s.wantDirectory('src')

        # FIXME move to functional tests

        # this looks on disk for support/foo, which is a package
        here = os.path.abspath(os.path.dirname(__file__))
        support = os.path.join(here, 'support')
        tp = os.path.normpath(os.path.join(support, 'foo'))
        assert s.wantDirectory(tp)
        # this looks for support, which is not a package
        assert not s.wantDirectory(support)
示例#16
0
 def test_exclude(self):
     s = Selector(Config())
     c = Config()
     c.exclude = [re.compile(r'me')]
     s2 = Selector(c)
     
     assert s.matches('test_foo')
     assert s2.matches('test_foo')
     assert s.matches('test_me')
     assert not s2.matches('test_me')
示例#17
0
class SynchroNosePlugin(Plugin):
    name = 'synchro'

    def __init__(self, *args, **kwargs):
        # We need a standard Nose selector in order to filter out methods that
        # don't match TestSuite.test_*
        self.selector = Selector(config=None)
        super(SynchroNosePlugin, self).__init__(*args, **kwargs)

    def configure(self, options, conf):
        super(SynchroNosePlugin, self).configure(options, conf)
        self.enabled = True

    def wantModule(self, module):
        for module_name in excluded_modules:
            if module_name.endswith('*'):
                if module.__name__.startswith(module_name.rstrip('*')):
                    # E.g., test_motor_cursor matches "test_motor_*".
                    return False

            elif module.__name__ == module_name:
                return False

        return True

    def wantMethod(self, method):
        # Run standard Nose checks on name, like "does it start with test_"?
        if not self.selector.matches(method.__name__):
            return False

        for excluded_name in excluded_tests:
            if PY3:
                classname = method.__self__.__class__.__name__
            else:
                classname = method.im_class.__name__

            # Should we exclude this method's whole TestCase?
            suite_name, method_name = excluded_name.split('.')
            suite_matches = (suite_name == classname or suite_name == '*')

            # Should we exclude this particular method?
            method_matches = (
                method.__name__ == method_name or method_name == '*')

            if suite_matches and method_matches:
                return False

        return True
示例#18
0
 def test_ignore_files_override(self):
     """Override the configuration to skip only specified files."""
     c = Config()
     c.ignoreFiles = [re.compile(r'^test_favourite_colour\.py$')]
     s = Selector(c)
     
     assert s.wantFile('_test_underscore.py')
     assert s.wantFile('.test_hidden.py')
     assert not s.wantFile('setup.py') # Actually excluded because of testMatch
     assert not s.wantFile('test_favourite_colour.py')
示例#19
0
    def test_want_directory(self):
        s = Selector(Config())
        assert s.wantDirectory("test")
        assert not s.wantDirectory("test/whatever")
        assert s.wantDirectory("whatever/test")
        assert not s.wantDirectory("/some/path/to/unit_tests/support")

        # default src directory
        assert s.wantDirectory("lib")
        assert s.wantDirectory("src")

        # FIXME move to functional tests

        # this looks on disk for support/foo, which is a package
        here = os.path.abspath(os.path.dirname(__file__))
        support = os.path.join(here, "support")
        tp = os.path.normpath(os.path.join(support, "foo"))
        assert s.wantDirectory(tp)
        # this looks for support, which is not a package
        assert not s.wantDirectory(support)
示例#20
0
    def test_want_directory(self):
        s = Selector(Config())
        assert s.wantDirectory('test')
        assert not s.wantDirectory('test/whatever')
        assert s.wantDirectory('whatever/test')
        assert not s.wantDirectory('/some/path/to/unit_tests/support')

        # default src directory
        assert s.wantDirectory('lib')
        assert s.wantDirectory('src')

        # FIXME move to functional tests
        
        # this looks on disk for support/foo, which is a package
        here = os.path.abspath(os.path.dirname(__file__))
        support = os.path.join(here, 'support')
        tp = os.path.normpath(os.path.join(support, 'foo'))
        assert s.wantDirectory(tp)
        # this looks for support, which is not a package
        assert not s.wantDirectory(support)        
示例#21
0
class SynchroNosePlugin(Plugin):
    name = 'synchro'

    def __init__(self, *args, **kwargs):
        # We need a standard Nose selector in order to filter out methods that
        # don't match TestSuite.test_*
        self.selector = Selector(config=None)
        super(SynchroNosePlugin, self).__init__(*args, **kwargs)

    def configure(self, options, conf):
        super(SynchroNosePlugin, self).configure(options, conf)
        self.enabled = True

    def wantModule(self, module):
        for module_name in excluded_modules:
            if module.__name__.startswith(module_name):
                return False

        return True

    def wantMethod(self, method):
        # Run standard Nose checks on name, like "does it start with test_"?
        if not self.selector.matches(method.__name__):
            return False

        for excluded_name in excluded_tests:
            if PY3:
                classname = method.__self__.__class__.__name__
            else:
                classname = method.im_class.__name__

            # Should we exclude this method's whole TestCase?
            suite_name, method_name = excluded_name.split('.')
            suite_matches = (suite_name == classname or suite_name == '*')

            # Should we exclude this particular method?
            method_matches = (method.__name__ == method_name
                              or method_name == '*')

            if suite_matches and method_matches:
                return False

        return True
示例#22
0
    def test_want_module(self):
        m = mod('whatever')
        m2 = mod('this.that')
        m3 = mod('this.that.another')
        m4 = mod('this.that.another.one')
        m5 = mod('test.something')
        m6 = mod('a.test')
        m7 = mod('my_tests')
        m8 = mod('__main__')

        s = Selector(Config())
        assert not s.wantModule(m)
        assert not s.wantModule(m2)
        assert not s.wantModule(m3)
        assert not s.wantModule(m4)
        assert not s.wantModule(m5)
        assert s.wantModule(m6)
        assert s.wantModule(m7)
        assert s.wantModule(m8)

        m6.__test__ = False
        assert not s.wantModule(m6), "Failed to respect __test__ = False"
示例#23
0
class SynchroNosePlugin(Plugin):
    name = 'synchro'

    def __init__(self, *args, **kwargs):
        # We need a standard Nose selector in order to filter out methods that
        # don't match TestSuite.test_*
        self.selector = Selector(config=None)
        super(SynchroNosePlugin, self).__init__(*args, **kwargs)

    def configure(self, options, conf):
        super(SynchroNosePlugin, self).configure(options, conf)
        self.enabled = True

    def wantModule(self, module):
        for module_name in excluded_modules:
            if module.__name__.startswith(module_name):
                return False

        return True

    def wantMethod(self, method):
        # Run standard Nose checks on name, like "does it start with test_"?
        if not self.selector.matches(method.__name__):
            return False

        for excluded_name in excluded_tests:
            suite_name, method_name = excluded_name.split('.')
            suite_matches = (
                method.im_class.__name__ == suite_name or suite_name == '*')

            method_matches = (
                method.__name__ == method_name or method_name == '*')

            if suite_matches and method_matches:
                return False

        return True
示例#24
0
    def test_want_module(self):
        m = mod('whatever')
        m2 = mod('this.that')
        m3 = mod('this.that.another')
        m4 = mod('this.that.another.one')
        m5 = mod('test.something')
        m6 = mod('a.test')
        m7 = mod('my_tests')
        m8 = mod('__main__')
        
        s = Selector(Config())
        assert not s.wantModule(m)
        assert not s.wantModule(m2)
        assert not s.wantModule(m3)
        assert not s.wantModule(m4)
        assert not s.wantModule(m5)
        assert s.wantModule(m6)
        assert s.wantModule(m7)
        assert s.wantModule(m8)

        m6.__test__ = False
        assert not s.wantModule(m6), "Failed to respect __test__ = False"
示例#25
0
    def test_want_module(self):
        m = mod("whatever")
        m2 = mod("this.that")
        m3 = mod("this.that.another")
        m4 = mod("this.that.another.one")
        m5 = mod("test.something")
        m6 = mod("a.test")
        m7 = mod("my_tests")
        m8 = mod("__main__")

        s = Selector(Config())
        assert not s.wantModule(m)
        assert not s.wantModule(m2)
        assert not s.wantModule(m3)
        assert not s.wantModule(m4)
        assert not s.wantModule(m5)
        assert s.wantModule(m6)
        assert s.wantModule(m7)
        assert s.wantModule(m8)

        m6.__test__ = False
        assert not s.wantModule(m6), "Failed to respect __test__ = False"
示例#26
0
 def test_want_method(self):
     class Baz:
         def test_me(self):
             pass
         def test_too(self):
             pass
         def other(self):
             pass
         def test_not_test(self):
             pass
         test_not_test.__test__ = False
         
     s = Selector(Config())
     
     assert s.wantMethod(Baz.test_me)
     assert s.wantMethod(Baz.test_too)
     assert not s.wantMethod(Baz.other)
     assert not s.wantMethod(Baz.test_not_test), \
            "Failed to respect __test__ = False"
示例#27
0
 def __init__(self, *args, **kwargs):
     # We need a standard Nose selector in order to filter out methods that
     # don't match TestSuite.test_*
     self.selector = Selector(config=None)
     super(SynchroNosePlugin, self).__init__(*args, **kwargs)
示例#28
0
    def test_want_file(self):

        #logging.getLogger('nose.selector').setLevel(logging.DEBUG)
        #logging.basicConfig()

        c = Config()
        c.where = [absdir(os.path.join(os.path.dirname(__file__), 'support'))]
        base = c.where[0]
        s = Selector(c)

        assert not s.wantFile('setup.py')
        assert not s.wantFile('/some/path/to/setup.py')
        assert not s.wantFile('ez_setup.py')
        assert not s.wantFile('.test.py')
        assert not s.wantFile('_test.py')
        assert not s.wantFile('setup_something.py')

        assert s.wantFile('test.py')
        assert s.wantFile('foo/test_foo.py')
        assert s.wantFile('bar/baz/test.py')
        assert not s.wantFile('foo.py')
        assert not s.wantFile('test_data.txt')
        assert not s.wantFile('data.text')
        assert not s.wantFile('bar/baz/__init__.py')
示例#29
0
    def test_include(self):
        s = Selector(Config())
        c = Config()
        c.include = [re.compile(r'me')]
        s2 = Selector(c)

        assert s.matches('test')
        assert s2.matches('test')
        assert not s.matches('meatball')
        assert s2.matches('meatball')
        assert not s.matches('toyota')
        assert not s2.matches('toyota')
        
        c.include.append(re.compile('toy'))
        assert s.matches('test')
        assert s2.matches('test')
        assert not s.matches('meatball')
        assert s2.matches('meatball')
        assert not s.matches('toyota')
        assert s2.matches('toyota')
示例#30
0
 def __init__(self, config, test_blacklist, file_blacklist):
     Selector.__init__(self, config)
     self.test_blacklist = test_blacklist
     self.file_blacklist = file_blacklist
     self.mod = None
示例#31
0
    def test_include(self):
        s = Selector(Config())
        c = Config()
        c.include = [re.compile(r"me")]
        s2 = Selector(c)

        assert s.matches("test")
        assert s2.matches("test")
        assert not s.matches("meatball")
        assert s2.matches("meatball")
        assert not s.matches("toyota")
        assert not s2.matches("toyota")

        c.include.append(re.compile("toy"))
        assert s.matches("test")
        assert s2.matches("test")
        assert not s.matches("meatball")
        assert s2.matches("meatball")
        assert not s.matches("toyota")
        assert s2.matches("toyota")
示例#32
0
    def test_want_file(self):

        #logging.getLogger('nose.selector').setLevel(logging.DEBUG)
        #logging.basicConfig()
        
        c = Config()
        c.where = [absdir(os.path.join(os.path.dirname(__file__), 'support'))]
        base = c.where[0]
        s = Selector(c)

        assert not s.wantFile('setup.py')
        assert not s.wantFile('/some/path/to/setup.py')
        assert not s.wantFile('ez_setup.py')
        assert not s.wantFile('.test.py')
        assert not s.wantFile('_test.py')
        assert not s.wantFile('setup_something.py')
        
        assert s.wantFile('test.py')
        assert s.wantFile('foo/test_foo.py')
        assert s.wantFile('bar/baz/test.py')
        assert not s.wantFile('foo.py')
        assert not s.wantFile('test_data.txt')
        assert not s.wantFile('data.text')
        assert not s.wantFile('bar/baz/__init__.py')
示例#33
0
 def __init__(self, config, test_blacklist, file_blacklist):
     Selector.__init__(self, config)
     self.test_blacklist = test_blacklist
     self.file_blacklist = file_blacklist
     self.mod = None
示例#34
0
class NoseSelectPlugin(Plugin):
    """Selects test to run based on tests names matching a pattern."""
    def options(self, parser, env):
        """Register command line options"""
        parser.add_option(
            "-t",
            "--select-tests",
            dest="selection_criteria",
            action="append",
            default=list(),
            metavar="SELECT",
            help=
            "Only run tests with a name matching a case-insensitive glob pattern (See fnmatch)"
        )

    def _as_pattern(self, criterion):
        # transforms selection criteria in glob patterns
        return '*%s*' % criterion.lower().strip('*')

    def add_criterion(self, criterion):
        #used mostly for testing
        if not hasattr(self, 'selection_criteria'):
            self.selection_criteria = []
        self.selection_criteria.append(self._as_pattern(criterion))

    def configure(self, options, config):
        self.selection_criteria = [
            self._as_pattern(criterion)
            for criterion in options.selection_criteria
            if criterion and criterion.strip()
        ]

        if self.selection_criteria:
            self.enabled = True

        # use a base selector to ensure we are additive to the basic selection
        self.base_selector = Selector(config)
        self.base_selector.configure(config)
        # we use a mock for plugins to avoid our plugin to be called
        # in a loop from the Selector (and avoid an infinite loop)
        self.base_selector.plugins = MockPlugins()

    def _is_selected(self, test_obj):
        """Return True if a test object should be selected based on criteria pattern."""
        if not test_obj:
            return
        if isinstance(test_obj, six.string_types):
            name = test_obj
        else:
            name = objname(test_obj)
        #log.debug('object name: %r' % name)
        if name:
            name = name.lower()
            selected = any(
                fnmatch(name, pat) for pat in self.selection_criteria)
            #log.debug('selected:%r name: %r' % (selected, name,))
            return selected
        else:
            return False

    def wantMethod(self, method):
        return self.base_selector.wantMethod(method) and self._is_selected(
            method)

    def wantFunction(self, function):
        return self.base_selector.wantFunction(function) and self._is_selected(
            function)
示例#35
0
    def test_include(self):
        s = Selector(Config())
        c = Config()
        c.include = [re.compile(r'me')]
        s2 = Selector(c)

        assert s.matches('test')
        assert s2.matches('test')
        assert not s.matches('meatball')
        assert s2.matches('meatball')
        assert not s.matches('toyota')
        assert not s2.matches('toyota')

        c.include.append(re.compile('toy'))
        assert s.matches('test')
        assert s2.matches('test')
        assert not s.matches('meatball')
        assert s2.matches('meatball')
        assert not s.matches('toyota')
        assert s2.matches('toyota')
示例#36
0
class SynchroNosePlugin(Plugin):
    name = 'synchro'

    def __init__(self, *args, **kwargs):
        # We need a standard Nose selector in order to filter out methods that
        # don't match TestSuite.test_*
        self.selector = Selector(config=None)
        super(SynchroNosePlugin, self).__init__(*args, **kwargs)

    def configure(self, options, conf):
        super(SynchroNosePlugin, self).configure(options, conf)
        self.enabled = True

    def wantModule(self, module):
        # Depending on PYTHONPATH, Motor's direct tests may be imported - don't
        # run them now.
        if module.__name__.startswith('test.test_motor_'):
            return False

        for module_name in excluded_modules:
            if module_name.endswith('*'):
                if module.__name__.startswith(module_name.rstrip('*')):
                    # E.g., test_motor_cursor matches "test_motor_*".
                    excluded_modules_matched.add(module_name)
                    return False

            elif module.__name__ == module_name:
                excluded_modules_matched.add(module_name)
                return False

        return True

    def wantFunction(self, fn):
        # PyMongo's test generators run at import time; tell Nose not to run
        # them as unittests.
        if fn.__name__ in ('test_cases',
                           'create_test',
                           'create_selection_tests'):
            return False

    def wantMethod(self, method):
        # Run standard Nose checks on name, like "does it start with test_"?
        if not self.selector.matches(method.__name__):
            return False

        for excluded_name in excluded_tests:
            if PY3:
                classname = method.__self__.__class__.__name__
            else:
                classname = method.im_class.__name__

            # Should we exclude this method's whole TestCase?
            suite_name, method_name = excluded_name.split('.')
            suite_matches = (suite_name == classname or suite_name == '*')

            # Should we exclude this particular method?
            method_matches = (
                method.__name__ == method_name or method_name == '*')

            if suite_matches and method_matches:
                excluded_tests_matched.add(excluded_name)
                return False

        return True
示例#37
0
 def __init__(self, *args, **kwargs):
     # We need a standard Nose selector in order to filter out methods that
     # don't match TestSuite.test_*
     self.selector = Selector(config=None)
     super(SynchroNosePlugin, self).__init__(*args, **kwargs)
示例#38
0
class SynchroNosePlugin(Plugin):
    name = "synchro"

    def __init__(self, *args, **kwargs):
        # We need a standard Nose selector in order to filter out methods that
        # don't match TestSuite.test_*
        self.selector = Selector(config=None)
        super().__init__(*args, **kwargs)

    def configure(self, options, conf):
        super().configure(options, conf)
        self.enabled = True

    def wantModule(self, module):
        # Depending on PYTHONPATH, Motor's direct tests may be imported - don't
        # run them now.
        if module.__name__.startswith("test.test_motor_"):
            return False

        for module_name in excluded_modules:
            if module_name.endswith("*"):
                if module.__name__.startswith(module_name.rstrip("*")):
                    # E.g., test_motor_cursor matches "test_motor_*".
                    excluded_modules_matched.add(module_name)
                    return False

            elif module.__name__ == module_name:
                excluded_modules_matched.add(module_name)
                return False

        return True

    def wantFunction(self, fn):
        # PyMongo's test generators run at import time; tell Nose not to run
        # them as unittests.
        if fn.__name__ in (
            "test_cases",
            "create_spec_test",
            "create_test",
            "create_tests",
            "create_connection_string_test",
            "create_document_test",
            "create_operation_test",
            "create_selection_tests",
            "generate_test_classes",
        ):
            return False

    def wantClass(self, cls):
        # PyMongo's test generator classes run at import time; tell Nose not
        # to run them as unittests.
        if cls.__name__ in ("TestCreator",):
            return False

    def wantMethod(self, method):
        # Run standard Nose checks on name, like "does it start with test_"?
        if not self.selector.matches(method.__name__):
            return False

        if method.__name__ in ("run_test_ops", "maybe_skip_test"):
            return False

        for excluded_name in excluded_tests:
            classname = method.__self__.__class__.__name__

            # Should we exclude this method's whole TestCase?
            suite_name, method_name = excluded_name.split(".")
            suite_matches = suite_name in [classname, "*"]

            # Should we exclude this particular method?
            method_matches = method.__name__ == method_name or method_name == "*"

            if suite_matches and method_matches:
                excluded_tests_matched.add(excluded_name)
                return False

        return True