本文整理匯總了Python中sample.VirtualMethods.sum1方法的典型用法代碼示例。如果您正苦於以下問題:Python VirtualMethods.sum1方法的具體用法?Python VirtualMethods.sum1怎麽用?Python VirtualMethods.sum1使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sample.VirtualMethods
的用法示例。
在下文中一共展示了VirtualMethods.sum1方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: VirtualMethodsTest
# 需要導入模塊: from sample import VirtualMethods [as 別名]
# 或者: from sample.VirtualMethods import sum1 [as 別名]
class VirtualMethodsTest(unittest.TestCase):
'''Test case for modified virtual methods.'''
def setUp(self):
self.vm = VirtualMethods()
self.evm = ExtendedVirtualMethods()
def tearDown(self):
del self.vm
del self.evm
def testModifiedVirtualMethod0(self):
'''Renamed virtual method.'''
a0, a1, a2 = 2, 3, 5
result0 = self.vm.callSum0(a0, a1, a2)
result1 = self.vm.sumThree(a0, a1, a2)
self.assertEqual(result0, a0 + a1 + a2)
self.assertEqual(result0, result1)
self.assertRaises(AttributeError, getattr, self.vm, 'sum0')
def testReimplementedModifiedVirtualMethod0(self):
'''Override of a renamed virtual method.'''
a0, a1, a2 = 2, 3, 5
result0 = self.vm.callSum0(a0, a1, a2)
result1 = self.vm.sumThree(a0, a1, a2)
result2 = self.evm.callSum0(a0, a1, a2)
self.assertEqual(result0, result1)
self.assertEqual(result0 * self.evm.multiplier, result2)
self.assert_(self.evm.sumThree_called)
self.assertFalse(self.evm.sum0_called)
def testModifiedVirtualMethod1(self):
'''Virtual method with three arguments and the last one
changed to have the default value set to 1000.'''
a0, a1, a2 = 2, 3, 5
result0 = self.vm.sum1(a0, a1)
self.assertEqual(result0, a0 + a1 + 1000)
result1 = self.vm.sum1(a0, a1, a2)
result2 = self.vm.callSum1(a0, a1, a2)
self.assertEqual(result1, result2)
def testReimplementedModifiedVirtualMethod1(self):
'''Override of the virtual method with three arguments and
the last one changed to have the default value set to 1000.'''
a0, a1 = 2, 3
result0 = self.vm.sum1(a0, a1)
result1 = self.evm.callSum1(a0, a1, 1000)
self.assertEqual(result0 * self.evm.multiplier, result1)
self.assert_(self.evm.sum1_called)
def testModifiedVirtualMethod2(self):
'''Virtual method originally with three arguments, the last
one was removed and the default value set to 2000.'''
a0, a1 = 1, 2
result0 = self.vm.sum2(a0, a1)
self.assertEqual(result0, a0 + a1 + 2000)
result1 = self.vm.sum2(a0, a1)
result2 = self.vm.callSum2(a0, a1, 2000)
self.assertEqual(result1, result2)
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
#.........這裏部分代碼省略.........
示例2: sum1
# 需要導入模塊: from sample import VirtualMethods [as 別名]
# 或者: from sample.VirtualMethods import sum1 [as 別名]
def sum1(self, a0, a1, a2):
self.sum1_called = True
return VirtualMethods.sum1(self, a0, a1, a2) * self.multiplier