本文整理汇总了Python中nose.util.isclass函数的典型用法代码示例。如果您正苦于以下问题:Python isclass函数的具体用法?Python isclass怎么用?Python isclass使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isclass函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addBlocked
def addBlocked(self, test, err, context):
"""Overrides normal addBlocked to add support for
errorClasses. If the exception is a registered class, the
error will be added to the list for that class, not errors.
"""
ec, ev, tb = err
for cls, (_, label, isfail) in self.errorClasses.items():
# if 'Skip' in cls.__name__ or 'Skip' in ec.__name__:
# from nose.tools import set_trace
# set_trace()
if isclass(ec) and issubclass(ec, cls):
if isfail:
test.passed = False
s = self.blocked.setdefault(label, [])
s.append((test, err, context))
self.printLabel(label, err)
return
if isclass(ec) and issubclass(ec, test.failureException):
label = "FAIL"
else:
label = "ERROR"
storage = self.blocked.setdefault(label, [])
storage.append((test, err, context))
test.passed = False
self.printLabel(label)
示例2: addError
def addError(self, test, err):
"""
Add error to the test result
:param test: Test for which to add error
:type test: str
:param error: Error message to add
:type error: str
"""
if isclass(err[0]) and issubclass(err[0], TCThresholdReached):
return
if isclass(err[0]) and issubclass(err[0], SkipTest):
self.addSkip(test, err[1])
return
if isclass(err[0]) and issubclass(err[0], TimeOut):
self.addTimedOut(test, err)
return
for cls, (storage, label, isfail) in self.errorClasses.items():
if isclass(err[0]) and issubclass(err[0], cls):
if isfail:
test.passed = False
storage.append((test, err))
if self.showAll:
self.logger.info(label + '\n')
elif self.dots:
self.logger.info(label[0])
return
test.passed = False
self._addError(test, err)
示例3: _recordAndPrintHeadline
def _recordAndPrintHeadline(self, test, error_class, artifact):
"""Record that an error-like thing occurred, and print a summary.
Store ``artifact`` with the record.
Return whether the test result is any sort of failure.
"""
# We duplicate the errorclass handling from super rather than calling
# it and monkeying around with showAll flags to keep it from printing
# anything.
is_error_class = False
for cls, (storage, label, is_failure) in self.errorClasses.items():
if isclass(error_class) and issubclass(error_class, cls):
if is_failure:
test.passed = False
storage.append((test, artifact))
is_error_class = True
if not is_error_class:
self.errors.append((test, artifact))
test.passed = False
is_any_failure = not is_error_class or is_failure
self._printHeadline(label if is_error_class else 'ERROR',
test,
is_failure=is_any_failure)
return is_any_failure
示例4: addError
def addError(self, test, err):
err_cls, a, b = err
if not isclass(err_cls):
return
classes = [e[0] for e in self.errorClasses]
if filter(lambda c: issubclass(err_cls, c), classes):
return True
示例5: makeTest
def makeTest(self, obj, parent=None):
"""Given a test object and its parent, return a test case
or test suite.
"""
ldr = loader.TestLoader()
if isinstance(obj, unittest.TestCase):
return obj
elif isclass(obj):
if parent and obj.__module__ != parent.__name__:
obj = transplant_class(obj, parent.__name__)
if issubclass(obj, unittest.TestCase):
# Randomize the order of the tests in the TestCase
return self.randomized_loadTestsFromTestCase(obj)
else:
return self.randomized_loadTestsFromTestClass(obj)
elif ismethod(obj):
if parent is None:
parent = obj.__class__
if issubclass(parent, unittest.TestCase):
return parent(obj.__name__)
else:
if isgenerator(obj):
return ldr.loadTestsFromGeneratorMethod(obj, parent)
else:
return MethodTestCase(obj)
elif isfunction(obj):
if parent and obj.__module__ != parent.__name__:
obj = transplant_func(obj, parent.__name__)
if isgenerator(obj):
return ldr.loadTestsFromGenerator(obj, parent)
else:
return [FunctionTestCase(obj)]
else:
return Failure(TypeError,
"Can't make a test from %s" % obj)
示例6: addError
def addError(self, test, err):
"""Overrides normal addError to add support for
errorClasses. If the exception is a registered class, the
error will be added to the list for that class, not errors.
"""
stream = getattr(self, 'stream', None)
ec, ev, tb = err
try:
exc_info = self._exc_info_to_string(err, test)
except TypeError:
# 2.3 compat
exc_info = self._exc_info_to_string(err)
for cls, (storage, label, isfail) in self.errorClasses.items():
if isclass(ec) and issubclass(ec, cls):
storage.append((test, exc_info))
# Might get patched into a streamless result
if stream is not None:
if self.showAll:
stream.writeln(label)
elif self.dots:
stream.write(label[:1])
return
self.errors.append((test, exc_info))
if stream is not None:
if self.showAll:
self.stream.writeln('ERROR')
elif self.dots:
stream.write('E')
示例7: addError
def addError(self, test, error): # pylint: disable-msg=W0221
"""Overrides normal addError to add support for
errorClasses. If the exception is a registered class, the
error will be added to the list for that class, not errors.
"""
fixTestCase(test)
#manually call startTest if it's not already called
if not getattr(test, '_subunit_started', False):
self.startTest(test)
ecls, evt, tbk = error # pylint: disable-msg=W0612
# pylint: disable-msg=W0612
for cls, (storage, label, isfail) in self.errorClasses.items():
if isclass(ecls) and issubclass(ecls, cls):
if not isfail:
reason = _exception_detail(evt)
if reason and self.useDetails:
details = {"reason":TextContent(reason)}
reason = None
else:
details = None
self._addNonFailOutcome(label.lower(), test,
reason=reason, details=details)
return
self._wassuccess = False
error, details = self._getArgs(test, error)
test.passed = False
TestProtocolClient.addError(self, test, error, details=details)
示例8: loadTestsFromModule
def loadTestsFromModule(self, module, path=None, discovered=False):
"""Load all tests from module and return a suite containing
them. If the module has been discovered and is not test-like,
the suite will be empty by default, though plugins may add
their own tests.
"""
log.debug("Load from module %s", module)
tests = []
test_classes = []
test_funcs = []
# For *discovered* modules, we only load tests when the module looks
# testlike. For modules we've been directed to load, we always
# look for tests. (discovered is set to True by loadTestsFromDir)
if not discovered or self.selector.wantModule(module):
for item in dir(module):
test = getattr(module, item, None)
# print "Check %s (%s) in %s" % (item, test, module.__name__)
if isclass(test):
if self.selector.wantClass(test):
test_classes.append(test)
elif isfunction(test) and self.selector.wantFunction(test):
test_funcs.append(test)
sort_list(test_classes, lambda x: x.__name__)
sort_list(test_funcs, func_lineno)
tests = map(lambda t: self.makeTest(t, parent=module),
test_classes + test_funcs)
# Now, descend into packages
# FIXME can or should this be lazy?
# is this syntax 2.2 compatible?
module_paths = getattr(module, '__path__', [])
if path:
path = os.path.realpath(path)
for module_path in module_paths:
log.debug("Load tests from module path %s?", module_path)
log.debug("path: %s os.path.realpath(%s): %s",
path, module_path, os.path.realpath(module_path))
# BEGIN MONKEYPATCH
#If a path was passed in, the case of path and
#module_path need to be normalized before comparing the two.
#This is to resolve a Windows-only issue with tests not being
#discovered correctly for namespace packages.
if path:
norm_module_path = os.path.normcase(module_path)
norm_path = os.path.normcase(path)
# END MONKEYPATCH
if (self.config.traverseNamespace or not path) or \
os.path.realpath(norm_module_path).startswith(norm_path):
# Egg files can be on sys.path, so make sure the path is a
# directory before trying to load from it.
if os.path.isdir(module_path):
tests.extend(self.loadTestsFromDir(module_path))
for test in self.config.plugins.loadTestsFromModule(module, path):
tests.append(test)
return self.suiteClass(ContextList(tests, context=module))
示例9: addError
def addError(self, test, err):
err_cls, a, b = err
if not isclass(err_cls):
return
classes = [e[0] for e in self.errorClasses]
if [c for c in classes if issubclass(err_cls, c)]:
return True
示例10: _makeTest
def _makeTest(self, obj, parent=None):
"""Given a test object and its parent, return a test case
or test suite.
"""
plug_tests = []
try:
addr = test_address(obj)
except KeyboardInterrupt:
raise
except:
addr = None
for test in self.config.plugins.makeTest(obj, parent):
plug_tests.append(test)
# TODO: is this try/except needed?
try:
if plug_tests:
return self.suiteClass(plug_tests)
except (KeyboardInterrupt, SystemExit):
raise
except:
exc = sys.exc_info()
return Failure(exc[0], exc[1], exc[2], address=addr)
if isfunction(obj) and parent and not isinstance(parent, types.ModuleType):
# This is a Python 3.x 'unbound method'. Wrap it with its
# associated class..
obj = unbound_method(parent, obj)
if isinstance(obj, unittest.TestCase):
return obj
elif isclass(obj):
if parent and obj.__module__ != parent.__name__:
obj = transplant_class(obj, parent.__name__)
if issubclass(obj, unittest.TestCase):
return self.loadTestsFromTestCase(obj)
else:
return self.loadTestsFromTestClass(obj)
elif ismethod(obj):
if parent is None:
parent = obj.__class__
if issubclass(parent, unittest.TestCase):
return parent(obj.__name__)
else:
if isgenerator(obj):
return self.loadTestsFromGeneratorMethod(obj, parent)
else:
return MethodTestCase(obj)
elif isfunction(obj):
isgen = isgenerator(obj)
if parent and obj.__module__ != parent.__name__:
obj = transplant_func(obj, parent.__name__)
if isgen:
return self.loadTestsFromGenerator(obj, parent)
else:
return FunctionTestCase(obj)
else:
return Failure(TypeError,
"Can't make a test from %s" % obj,
address=addr)
示例11: addError
def addError(self, test, err):
if isclass(err[0]) and issubclass(err[0], SkipTest):
self.addSkip(test, err[1])
return
if isclass(err[0]) and issubclass(err[0], TimeOut):
self.addTimedOut(test, err)
return
for cls, (storage, label, isfail) in self.errorClasses.items():
if isclass(err[0]) and issubclass(err[0], cls):
if isfail:
test.passed = False
storage.append((test, err))
if self.showAll:
self.logger.info(label + '\n')
elif self.dots:
self.logger.info(label[0])
return
test.passed = False
self._addError(test, err)
示例12: _exc_info_to_string
def _exc_info_to_string(self, err, test=None):
# 2.7 skip compat
from nose.plugins.skip import SkipTest
if isclass(err[0]) and issubclass(err[0], SkipTest):
return str(err[1])
# 2.3/2.4 -- 2.4 passes test, 2.3 does not
try:
return _TextTestResult._exc_info_to_string(self, err, test)
except TypeError:
# 2.3: does not take test arg
return _TextTestResult._exc_info_to_string(self, err)
示例13: startContext
def startContext(self, context):
context.param = self.param
context.start_time = datetime.datetime.now()
if isclass(context) and issubclass(context, PBSTestSuite):
self.result.logger.info(self.result.separator1)
self.result.logger.info('suite name: ' + context.__name__)
doc = context.__doc__
if doc is not None:
self.result.logger.info('suite docstring: \n' + doc + '\n')
self.result.logger.info(self.result.separator1)
context.start_time = datetime.datetime.now()
示例14: startContext
def startContext(self, context):
if self.options.syncplan:
if isclass(context):
names = ContextSuite.classSetup + ContextSuite.classTeardown
else:
names = ContextSuite.moduleSetup + ContextSuite.moduleTeardown
if hasattr(context, '__path__'):
names += ContextSuite.packageSetup + ContextSuite.packageTeardown
# If my context has any fixture attribute, I have fixtures
for m in names:
if hasattr(context, m):
setattr(context, m, None)
示例15: filter_no_plugins
def filter_no_plugins(module):
name = MODULE_PREFIX + ".%s" % module
try:
module = __import__(name, fromlist=[PLUGIN_CLASS_NAME])
module_attrs = dir(module)
if 'OutputPlugin' in module_attrs:
plugin = getattr(module, PLUGIN_CLASS_NAME)
if isclass(plugin):
return True
except ImportError, e:
str_reason = traceback.format_exc(e)
return False