本文整理匯總了Python中nose.selector.Selector.wantFunction方法的典型用法代碼示例。如果您正苦於以下問題:Python Selector.wantFunction方法的具體用法?Python Selector.wantFunction怎麽用?Python Selector.wantFunction使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類nose.selector.Selector
的用法示例。
在下文中一共展示了Selector.wantFunction方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_want_function
# 需要導入模塊: from nose.selector import Selector [as 別名]
# 或者: from nose.selector.Selector import wantFunction [as 別名]
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"
示例2: NoseSelectPlugin
# 需要導入模塊: from nose.selector import Selector [as 別名]
# 或者: from nose.selector.Selector import wantFunction [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)