当前位置: 首页>>代码示例>>Python>>正文


Python selector.Selector类代码示例

本文整理汇总了Python中nose.selector.Selector的典型用法代码示例。如果您正苦于以下问题:Python Selector类的具体用法?Python Selector怎么用?Python Selector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Selector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_ignore_files_default

 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')
开发者ID:ANKIT-KS,项目名称:fjord,代码行数:7,代码来源:test_selector.py

示例2: NoseSelectPlugin

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)
开发者ID:aleGpereira,项目名称:nose-selecttests,代码行数:59,代码来源:__init__.py

示例3: test_ignore_files_override

 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')
开发者ID:ANKIT-KS,项目名称:fjord,代码行数:10,代码来源:test_selector.py

示例4: test_want_function

    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"
开发者ID:ANKIT-KS,项目名称:fjord,代码行数:16,代码来源:test_selector.py

示例5: test_want_class

    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"
开发者ID:GaloisInc,项目名称:echronos,代码行数:27,代码来源:test_selector.py

示例6: test_want_method

 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"
开发者ID:ANKIT-KS,项目名称:fjord,代码行数:19,代码来源:test_selector.py

示例7: configure

    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()
开发者ID:aleGpereira,项目名称:nose-selecttests,代码行数:14,代码来源:__init__.py

示例8: SynchroNosePlugin

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
开发者ID:jettify,项目名称:motor,代码行数:48,代码来源:synchrotest.py

示例9: test_exclude

 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')
开发者ID:ANKIT-KS,项目名称:fjord,代码行数:10,代码来源:test_selector.py

示例10: test_want_directory

    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)        
开发者ID:ANKIT-KS,项目名称:fjord,代码行数:20,代码来源:test_selector.py

示例11: test_want_directory

    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)
开发者ID:GaloisInc,项目名称:echronos,代码行数:20,代码来源:test_selector.py

示例12: SynchroNosePlugin

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
开发者ID:devlato,项目名称:motor,代码行数:37,代码来源:synchrotest.py

示例13: test_want_module

    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"
开发者ID:ANKIT-KS,项目名称:fjord,代码行数:22,代码来源:test_selector.py

示例14: test_want_module

    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"
开发者ID:GaloisInc,项目名称:echronos,代码行数:22,代码来源:test_selector.py

示例15: __init__

 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
开发者ID:netcharm,项目名称:ironclad,代码行数:5,代码来源:blacklists.py


注:本文中的nose.selector.Selector类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。