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

Python pyversion.ismethod函数代码示例

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

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



在下文中一共展示了ismethod函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: wanted

 def wanted(attr, cls=cls, sel=self.selector):
     item = getattr(cls, attr, None)
     if isfunction(item):
         item = unbound_method(cls, item)
     elif not ismethod(item):
         return False
     return sel.wantMethod(item)
开发者ID:crobinsonut,项目名称:nose,代码行数:7,代码来源:loader.py


示例2: try_run

def try_run(obj, names):
    """Given a list of possible method names, try to run them with the
    provided object. Keep going until something works. Used to run
    setup/teardown methods for module, package, and function tests.
    """
    for name in names:
        func = getattr(obj, name, None)
        if func is not None:
            if type(obj) == types.ModuleType:
                # py.test compatibility
                try:
                    args, varargs, varkw, defaults = inspect.getargspec(func)
                    if hasattr(func, '__call__') and ismethod(func.__call__):
                        args.pop(0)
                except TypeError:
                    # Not a function. If it's callable, call it anyway
                    if hasattr(func, '__call__'):
                        func = func.__call__
                    try:
                        args, varargs, varkw, defaults = \
                            inspect.getargspec(func)
                        args.pop(0) # pop the self off
                    except TypeError:
                        raise TypeError("Attribute %s of %r is not a python "
                                        "function. Only functions or callables"
                                        " may be used as fixtures." %
                                        (name, obj))
                if len(args):
                    log.debug("call fixture %s.%s(%s)", obj, name, obj)
                    return func(obj)
            log.debug("call fixture %s.%s", obj, name)
            return func()
开发者ID:andrewmwhite,项目名称:nose,代码行数:32,代码来源:util.py


示例3: _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


示例4: _expand_tests

def _expand_tests(obj, parent):
    if inspect.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)

    tests = []
    if isinstance(obj, list):
        tests = obj
    elif ismethod(obj):
        tests = [obj.__name__]

    _tests = []
    for test in tests:
        _tests += _make_dataprovided_tests(parent, test)

    return _tests
开发者ID:z00sts,项目名称:lode_runner,代码行数:17,代码来源:dataprovider.py


示例5: generate

 def generate(g=generator, c=cls):
     try:
         for test in g():
             test_func, arg = self.parseGeneratedTest(test)
             if not callable(test_func):
                 test_func = unbound_method(c, getattr(c, test_func))
             if ismethod(test_func):
                 yield MethodTestCase(test_func, arg=arg, descriptor=g)
             elif isfunction(test_func):
                 # In this case we're forcing the 'MethodTestCase'
                 # to run the inline function as its test call,
                 # but using the generator method as the 'method of
                 # record' (so no need to pass it as the descriptor)
                 yield MethodTestCase(g, test=test_func, arg=arg)
             else:
                 yield Failure(TypeError, "%s is not a function or method" % test_func)
     except KeyboardInterrupt:
         raise
     except:
         exc = sys.exc_info()
         yield Failure(exc[0], exc[1], exc[2], address=test_address(generator))
开发者ID:eallik,项目名称:nose,代码行数:21,代码来源:loader.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python pyversion.sort_list函数代码示例发布时间:2022-05-27
下一篇:
Python xunit.Xunit类代码示例发布时间: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