當前位置: 首頁>>代碼示例>>Python>>正文


Python Selector.wantMethod方法代碼示例

本文整理匯總了Python中nose.selector.Selector.wantMethod方法的典型用法代碼示例。如果您正苦於以下問題:Python Selector.wantMethod方法的具體用法?Python Selector.wantMethod怎麽用?Python Selector.wantMethod使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在nose.selector.Selector的用法示例。


在下文中一共展示了Selector.wantMethod方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: NoseSelectPlugin

# 需要導入模塊: from nose.selector import Selector [as 別名]
# 或者: from nose.selector.Selector import wantMethod [as 別名]
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,代碼行數:61,代碼來源:__init__.py

示例2: test_want_method

# 需要導入模塊: from nose.selector import Selector [as 別名]
# 或者: from nose.selector.Selector import wantMethod [as 別名]
 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,代碼行數:21,代碼來源:test_selector.py


注:本文中的nose.selector.Selector.wantMethod方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。