本文整理匯總了Python中sample.VirtualMethods.getMargins方法的典型用法代碼示例。如果您正苦於以下問題:Python VirtualMethods.getMargins方法的具體用法?Python VirtualMethods.getMargins怎麽用?Python VirtualMethods.getMargins使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sample.VirtualMethods
的用法示例。
在下文中一共展示了VirtualMethods.getMargins方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: VirtualMethodsTest
# 需要導入模塊: from sample import VirtualMethods [as 別名]
# 或者: from sample.VirtualMethods import getMargins [as 別名]
#.........這裏部分代碼省略.........
self.assertRaises(TypeError, self.vm.sum2, 1, 2, 3)
def testReimplementedModifiedVirtualMethod2(self):
'''Override of the virtual method originally with three arguments,
the last one was removed and the default value set to 2000.'''
a0, a1 = 1, 2
ignored = 54321
result0 = self.vm.sum2(a0, a1)
result1 = self.evm.callSum2(a0, a1, ignored)
self.assertEqual(result0 * self.evm.multiplier, result1)
self.assert_(self.evm.sum2_called)
def testModifiedVirtualMethod3(self):
'''Virtual method originally with three arguments have the second
one removed and replaced by custom code that replaces it by the sum
of the first and the last arguments.'''
a0, a1 = 1, 2
result0 = self.vm.sum3(a0, a1)
self.assertEqual(result0, a0 + (a0 + a1) + a1)
result1 = self.vm.callSum3(a0, 10, a1)
self.assertNotEqual(result0, result1)
result2 = self.vm.callSum3(a0, a0 + a1, a1)
self.assertEqual(result0, result2)
self.assertRaises(TypeError, self.vm.sum3, 1, 2, 3)
def testReimplementedModifiedVirtualMethod3(self):
'''Override of the virtual method originally with three arguments
have the second one removed and replaced by custom code that
replaces it by the sum of the first and the last arguments.'''
a0, a1 = 1, 2
ignored = 54321
result0 = self.vm.sum3(a0, a1)
result1 = self.evm.callSum3(a0, ignored, a1)
self.assertEqual(result0 * self.evm.multiplier, result1)
self.assert_(self.evm.sum3_called)
def testModifiedVirtualMethod4(self):
'''Virtual method originally with three arguments, the
last one was removed and the default value set to 3000.'''
a0, a1 = 1, 2
default_value = 3000
result0 = self.vm.sum4(a0, a1)
self.assertEqual(result0, a0 + default_value + a1)
removed_arg_value = 100
result1 = self.vm.callSum4(a0, removed_arg_value, a1)
self.assertEqual(result1, a0 + removed_arg_value + a1)
self.assertRaises(TypeError, self.vm.sum4, 1, 2, 3)
def testReimplementedModifiedVirtualMethod4(self):
'''Override of the virtual method originally with three arguments,
the last one was removed and the default value set to 3000.
The method was modified with code injection on the binding override
(the one that receives calls from C++ with the original signature
and forwards it to Python overrides) that subtracts the value of the
second argument (removed in Python) from the value of the first
before sending them to Python.'''
a0, a1 = 1, 2
removed_arg_value = 2011
default_value = 3000
result = self.evm.callSum4(a0, removed_arg_value, a1)
self.assertEqual(result, (a0 - removed_arg_value + a1 + default_value) * self.evm.multiplier)
self.assert_(self.evm.sum4_called)
def testOverridenMethodResultModification(self):
'''Injected code modifies the result of a call to a virtual
method overridden in Python.'''
orig_name = self.vm.callName()
self.assertEqual(orig_name, 'VirtualMethods')
name = self.evm.callName()
self.assertEqual(name, 'PimpedExtendedVirtualMethods')
self.assertEqual(name, Str('PimpedExtendedVirtualMethods'))
self.assert_(self.evm.name_called)
def testInjectCodeCallsPythonVirtualMethodOverride(self):
'''When injected code calls the Python override by itself
no code for the method call should be generated.'''
self.evm.callCallMe()
self.assertEqual(self.evm.callMe_called, 1)
def testAllArgumentsRemoved(self):
values = (10, 20, 30, 40)
self.vm.setMargins(*values)
self.assertEquals(self.vm.getMargins(), values)
def testAllArgumentsRemovedCallVirtual(self):
values = (10, 20, 30, 40)
self.vm.setMargins(*values)
self.assertEquals(self.vm.callGetMargins(), values)
def testExtendedAllArgumentsRemoved(self):
values = (10, 20, 30, 40)
self.evm.setMargins(*values)
double = tuple([m*2 for m in values])
self.assertEquals(self.evm.getMargins(), double)
def testExtendedAllArgumentsRemovedCallVirtual(self):
values = (10, 20, 30, 40)
self.evm.setMargins(*values)
double = tuple([m*2 for m in values])
self.assertEquals(self.evm.callGetMargins(), double)
示例2: getMargins
# 需要導入模塊: from sample import VirtualMethods [as 別名]
# 或者: from sample.VirtualMethods import getMargins [as 別名]
def getMargins(self):
return tuple([m*2 for m in VirtualMethods.getMargins(self)])