本文整理汇总了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)