当前位置: 首页>>代码示例>>Python>>正文


Python VirtualMethods.callVirtualMethod0方法代码示例

本文整理汇总了Python中sample.VirtualMethods.callVirtualMethod0方法的典型用法代码示例。如果您正苦于以下问题:Python VirtualMethods.callVirtualMethod0方法的具体用法?Python VirtualMethods.callVirtualMethod0怎么用?Python VirtualMethods.callVirtualMethod0使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sample.VirtualMethods的用法示例。


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

示例1: testMonkeyPatchOnVirtualMethod

# 需要导入模块: from sample import VirtualMethods [as 别名]
# 或者: from sample.VirtualMethods import callVirtualMethod0 [as 别名]
    def testMonkeyPatchOnVirtualMethod(self):
        '''Injects new 'virtualMethod0' on a VirtualMethods instance and makes C++ call it.'''
        vm = VirtualMethods()
        pt, val, cpx, b = Point(1.1, 2.2), 4, complex(3.3, 4.4), True

        result1 = vm.virtualMethod0(pt, val, cpx, b)
        result2 = vm.callVirtualMethod0(pt, val, cpx, b)
        self.assertEqual(result1, result2)
        self.assertEqual(result1, VirtualMethods.virtualMethod0(vm, pt, val, cpx, b))

        def myVirtualMethod0(obj, pt, val, cpx, b):
            self.duck_method_called = True
            return VirtualMethods.virtualMethod0(obj, pt, val, cpx, b) * self.multiplier
        vm.virtualMethod0 = types.MethodType(myVirtualMethod0, vm, VirtualMethods)

        result1 = vm.callVirtualMethod0(pt, val, cpx, b)
        self.assert_(self.duck_method_called)

        result2 = vm.virtualMethod0(pt, val, cpx, b)
        self.assertEqual(result1, result2)
        self.assertEqual(result1, VirtualMethods.virtualMethod0(vm, pt, val, cpx, b) * self.multiplier)

        # This is done to decrease the refcount of the vm object
        # allowing the object wrapper to be deleted before the
        # BindingManager. This is useful when compiling Shiboken
        # for debug, since the BindingManager destructor has an
        # assert that checks if the wrapper mapper is empty.
        vm.virtualMethod0 = None
开发者ID:OdyX,项目名称:Shiboken,代码行数:30,代码来源:duck_punching_test.py


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