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

Python pyversion.unbound_method函数代码示例

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

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



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

示例1: test_test_address

    def test_test_address(self):
        # test addresses are specified as
        #     package.module:class.method
        #     /path/to/file.py:class.method
        # converted into 3-tuples (file, module, callable)
        # all terms optional
        test_address = util.test_address
        absfile = util.absfile
        class Foo:
            def bar(self):
                pass
        def baz():
            pass

        f = Foo()

        class FooTC(unittest.TestCase):
            def test_one(self):
                pass
            def test_two(self):
                pass

        class CustomTestType(type):
            pass
        class CustomTC(unittest.TestCase):
            __metaclass__ = CustomTestType
            def test_one(self):
                pass
            def test_two(self):
                pass

        foo_funct = case.FunctionTestCase(baz)
        foo_functu = unittest.FunctionTestCase(baz)

        foo_mtc = case.MethodTestCase(unbound_method(Foo, Foo.bar))

        me = util.src(absfile(__file__))
        self.assertEqual(test_address(baz),
                         (me, __name__, 'baz'))
        assert test_address(Foo) == (me, __name__, 'Foo')
        assert test_address(unbound_method(Foo, Foo.bar)) == (me, __name__,
                                                              'Foo.bar')
        assert test_address(f) == (me, __name__, 'Foo')
        assert test_address(f.bar) == (me, __name__, 'Foo.bar')
        assert test_address(nose) == (
            util.src(absfile(nose.__file__)), 'nose', None)

        # test passing the actual test callable, as the
        # missed test plugin must do
        self.assertEqual(test_address(FooTC('test_one')),
                         (me, __name__, 'FooTC.test_one'))
        self.assertEqual(test_address(CustomTC('test_one')),
                         (me, __name__, 'CustomTC.test_one'))
        self.assertEqual(test_address(foo_funct),
                         (me, __name__, 'baz'))
        self.assertEqual(test_address(foo_functu),
                         (me, __name__, 'baz'))
        self.assertEqual(test_address(foo_mtc),
                         (me, __name__, 'Foo.bar'))
开发者ID:AndryulE,项目名称:kitsune,代码行数:59,代码来源:test_utils.py


示例2: test_address

    def test_address(self):
        from nose.util import absfile, src
        class TC(unittest.TestCase):
            def runTest(self):
                raise Exception("error")

        def dummy(i):
            pass

        def test():
            pass

        class Test:
            def test(self):
                pass

            def test_gen(self):
                def tryit(i):
                    pass
                for i in range (0, 2):
                    yield tryit, i

            def try_something(self, a, b):
                pass

        fl = src(absfile(__file__))
        case = nose.case.Test(TC())
        self.assertEqual(case.address(), (fl, __name__, 'TC.runTest'))

        case = nose.case.Test(nose.case.FunctionTestCase(test))
        self.assertEqual(case.address(), (fl, __name__, 'test'))

        case = nose.case.Test(nose.case.FunctionTestCase(
            dummy, arg=(1,), descriptor=test))
        self.assertEqual(case.address(), (fl, __name__, 'test'))

        case = nose.case.Test(nose.case.MethodTestCase(
                                  unbound_method(Test, Test.test)))
        self.assertEqual(case.address(), (fl, __name__, 'Test.test'))

        case = nose.case.Test(
            nose.case.MethodTestCase(unbound_method(Test, Test.try_something),
                                     arg=(1,2,),
                                     descriptor=unbound_method(Test,
                                                               Test.test_gen)))
        self.assertEqual(case.address(),
                         (fl, __name__, 'Test.test_gen'))

        case = nose.case.Test(
            nose.case.MethodTestCase(unbound_method(Test, Test.test_gen),
                                     test=dummy, arg=(1,)))
        self.assertEqual(case.address(),
                         (fl, __name__, 'Test.test_gen'))
开发者ID:adpayne237,项目名称:zambiamobile,代码行数:53,代码来源:test_cases.py


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


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


示例5: test_method_raw

    def test_method_raw(self):
        class TC(object):
            def test(self):
                pass

        case = nose.case.MethodTestCase(unbound_method(TC, TC.test))
        eq_(nice_test_address(case),
            'nosenicedots/tests/test_units.py:TC.test')
开发者ID:kmanalo,项目名称:nose-nicedots,代码行数:8,代码来源:test_units.py


示例6: test_method_gen

    def test_method_gen(self):
        def fn(x):
            pass
        class TC(object):
            def test_gen(self):
                yield fn, (1,)

        case = nose.case.MethodTestCase(unbound_method(TC, TC.test_gen))
        eq_(nice_test_address(case),
            'nosenicedots/tests/test_units.py:TC.test_gen')
开发者ID:kmanalo,项目名称:nose-nicedots,代码行数:10,代码来源:test_units.py


示例7: test_class_and_method_str_attr

    def test_class_and_method_str_attr(self):
        class TestP(object):
            foo = 'a'

            def h(self):
                pass
            h.foo = 'b'

        def i():
            pass
        i.foo = 'a'

        plug = AttributeSelector()
        plug.attribs = [[('foo', 'a'), ('foo', 'b')]]
        assert plug.wantMethod(unbound_method(TestP, TestP.h)) is not False
        assert plug.wantFunction(i) is False

        plug.attribs = [[('foo', 'b')]]
        assert plug.wantMethod(unbound_method(TestP, TestP.h)) is not False
        assert plug.wantFunction(i) is False
开发者ID:matthewstory,项目名称:nose,代码行数:20,代码来源:test_plugins.py


示例8: test_method_test_case

    def test_method_test_case(self):
        res = unittest.TestResult()

        a = []
        class TestClass(object):
            def test_func(self, a=a):
                a.append(1)

        case = nose.case.MethodTestCase(unbound_method(TestClass,
                                                       TestClass.test_func))
        case(res)
        assert a[0] == 1
开发者ID:adpayne237,项目名称:zambiamobile,代码行数:12,代码来源:test_cases.py


示例9: test_class_attr

    def test_class_attr(self):
        class TestP:
            foo = True
            def h():
                pass

        def i():
            pass

        plug = AttributeSelector()
        plug.attribs = [[('foo', True)]]
        assert plug.wantMethod(unbound_method(TestP, TestP.h)) is not False
        assert plug.wantFunction(i) is False
开发者ID:jiffyclub,项目名称:nose,代码行数:13,代码来源:test_plugins.py


示例10: test_method_test_case_fixtures

    def test_method_test_case_fixtures(self):        
        res = unittest.TestResult()
        called = []
        class TestClass(object):
            def setup(self):
                called.append('setup')
            def teardown(self):
                called.append('teardown')
            def test_func(self):
                called.append('test')

        case = nose.case.MethodTestCase(unbound_method(TestClass,
                                                       TestClass.test_func))
        case(res)
        self.assertEqual(called, ['setup', 'test', 'teardown'])

        class TestClassFailingSetup(TestClass):
            def setup(self):
                called.append('setup')
                raise Exception("failed")
        called[:] = []
        case = nose.case.MethodTestCase(unbound_method(TestClassFailingSetup,
                                            TestClassFailingSetup.test_func))
        case(res)
        self.assertEqual(called, ['setup'])        

        class TestClassFailingTest(TestClass):
            def test_func(self):
                called.append('test')
                raise Exception("failed")
            
        called[:] = []
        case = nose.case.MethodTestCase(unbound_method(TestClassFailingTest,
                                            TestClassFailingTest.test_func))
        case(res)
        self.assertEqual(called, ['setup', 'test', 'teardown'])     
开发者ID:adpayne237,项目名称:zambiamobile,代码行数:36,代码来源:test_cases.py


示例11: test_method_test_case_with_metaclass

    def test_method_test_case_with_metaclass(self):
        res = unittest.TestResult()
        
        class TestType(type):
            def __new__(cls, name, bases, dct):
                return type.__new__(cls, name, bases, dct)
        a = []
        class TestClass(object, metaclass=TestType):
            def test_func(self, a=a):
                a.append(1)

        case = nose.case.MethodTestCase(unbound_method(TestClass,
                                                       TestClass.test_func))
        case(res)
        assert a[0] == 1
开发者ID:GaloisInc,项目名称:echronos,代码行数:15,代码来源:test_cases.py


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


示例13: test_context

    def test_context(self):
        class TC(unittest.TestCase):
            def runTest(self):
                pass
        def test():
            pass

        class Test:
            def test(self):
                pass

        case = nose.case.Test(TC())
        self.assertEqual(case.context, TC)

        case = nose.case.Test(nose.case.FunctionTestCase(test))
        self.assertEqual(case.context, sys.modules[__name__])

        case = nose.case.Test(nose.case.MethodTestCase(unbound_method(Test,
                                                           Test.test)))
        self.assertEqual(case.context, Test)
开发者ID:adpayne237,项目名称:zambiamobile,代码行数:20,代码来源:test_cases.py


示例14: test_MethodTestCase_repr_is_consistent_with_mutable_args

    def test_MethodTestCase_repr_is_consistent_with_mutable_args(self):
        class Foo(object):
            def __init__(self):
                self.bar = 'unmodified'
            def __repr__(self):
                return "Foo(%s)" % self.bar

        class FooTester(object):
            def test_foo(self, foo):
                pass

        foo = Foo()
        case = nose.case.FunctionTestCase(
            unbound_method(FooTester, FooTester.test_foo), arg=(foo,))
        case_repr_before = case.__repr__()
        foo.bar = "snafu'd!"
        case_repr_after = case.__repr__()
        assert case_repr_before == case_repr_after, (
            "Modifying a mutable object arg during test case changed the test "
            "case's __repr__")
开发者ID:Averroes,项目名称:nose,代码行数:20,代码来源:test_cases.py


示例15: 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


示例16: test_is_selected_selects_method_unbound

 def test_is_selected_selects_method_unbound(self):
     plugin = NoseSelectPlugin()
     plugin.add_criterion('DummyTest.test_foo')
     self.assertTrue(plugin._is_selected(unbound_method(DummyTest, DummyTest.test_foo)))
开发者ID:domenkozar,项目名称:nose-selecttests,代码行数:4,代码来源:tests.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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