• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python util.isclass函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了isclass函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:jonozzz,项目名称:nose,代码行数:25,代码来源:result.py


示例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)
开发者ID:Bhagat-Rajput,项目名称:pbspro,代码行数:29,代码来源:ptl_test_runner.py


示例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
开发者ID:MasroorHamdani,项目名称:django-project-template,代码行数:27,代码来源:result.py


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


示例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)
开发者ID:brimo,项目名称:nose-randomize,代码行数:35,代码来源:plugin.py


示例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')
开发者ID:scbarber,项目名称:horriblepoems,代码行数:28,代码来源:result.py


示例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)
开发者ID:liucougar,项目名称:nose-subunit,代码行数:31,代码来源:sunit.py


示例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))
开发者ID:ChanChiChoi,项目名称:OpenMDAO-Framework,代码行数:60,代码来源:testing.py


示例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
开发者ID:Hank02,项目名称:posts,代码行数:7,代码来源:errorclass.py


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


示例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)
开发者ID:gajendrasharmagit,项目名称:pbspro,代码行数:19,代码来源:ptl_test_runner.py


示例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)
开发者ID:erikb85,项目名称:nose,代码行数:11,代码来源:result.py


示例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()
开发者ID:gajendrasharmagit,项目名称:pbspro,代码行数:11,代码来源:ptl_test_runner.py


示例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)
开发者ID:pombredanne,项目名称:f5test2,代码行数:12,代码来源:testopia.py


示例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
开发者ID:griddynamics,项目名称:bunch,代码行数:12,代码来源:__init__.py


示例16: _determineTeardownRoutine

 def _determineTeardownRoutine(self):
     context = self.context
     if isclass(context):
         names = self.classTeardown
     else:
         names = self.moduleTeardown
         if hasattr(context, '__path__'):
             names = self.packageTeardown + names
     for name in names:
         func = getattr(context, name, None)
         if callable(func):
             return func
     return self.tearDown
开发者ID:csplinter,项目名称:nose,代码行数:13,代码来源:suite.py


示例17: _determineSetupRoutine

 def _determineSetupRoutine(self):
     context = self.context
     if isclass(context):
         names = self.classSetup
     else:
         names = self.moduleSetup
         if hasattr(context, '__path__'):
             names = self.packageSetup + names
     for name in names:
         func = getattr(context, name, None)
         if callable(func):
             return func
     return self.setUp
开发者ID:csplinter,项目名称:nose,代码行数:13,代码来源:suite.py


示例18: teardownContext

 def teardownContext(self, context):
     log.debug("%s teardown context %s", self, context)
     if self.factory:
         if context in self.factory.was_torndown:
             return
         self.factory.was_torndown[context] = self
     if isclass(context):
         names = self.classTeardown
     else:
         names = self.moduleTeardown
         if hasattr(context, '__path__'):
             names = self.packageTeardown + names
     try_run(context, names)
     self.config.plugins.stopContext(context)
开发者ID:Byron,项目名称:bdep-oss,代码行数:14,代码来源:suite.py


示例19: teardownContext

 def teardownContext(self, context):
     log.debug("%s teardown context %s", self, context)
     if self.factory:
         self.factory.was_torndown[context] = self
     if isclass(context):
         names = ('teardown_class', 'teardown_all', 'teardownClass',
                  'teardownAll', 'tearDownClass', 'tearDownAll')
     else:
         names = ('teardown_module', 'teardownModule', 'tearDownModule',
                  'teardown')
         if hasattr(context, '__path__'):
             names = ('teardown_package', 'teardownPackage',
                      'tearDownPackage') + names
     try_run(context, names)
     self.config.plugins.stopContext(context)
开发者ID:scbarber,项目名称:horriblepoems,代码行数:15,代码来源:suite.py


示例20: loadTestsFromModule

    def loadTestsFromModule(self, module, 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)
            test_classes.sort(lambda a, b: cmp(a.__name__, b.__name__))
            test_funcs.sort(cmp_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?
        paths = getattr(module, '__path__', [])
        for path in paths:
            tests.extend(self.loadTestsFromDir(path))
            
        # Catch TypeError and AttributeError exceptions here and discard
        # them: the default plugin manager, NoPlugins, will raise TypeError
        # on generative calls.
        try:
            for test in self.config.plugins.loadTestsFromModule(module):
                tests.append(test)
        except (TypeError, AttributeError):
            pass
        except (KeyboardInterrupt, SystemExit):
            raise
        except:
            tests.append(Failure(*sys.exc_info()))

        return self.suiteClass(ContextList(tests, context=module))
开发者ID:scbarber,项目名称:horriblepoems,代码行数:48,代码来源:loader.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python util.resolve_name函数代码示例发布时间:2022-05-27
下一篇:
Python util.anyp函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap