2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-21 05:02:17 +00:00
Files
python/test/virtual_functions.py
Dave Abrahams c18d8fa967 added first virtual function tests
[SVN r13183]
2002-03-12 21:14:03 +00:00

101 lines
1.4 KiB
Python

'''
>>> from virtual_functions_ext import *
>>> class C1(concrete):
... def f(self, y):
... return concrete.f(self, Y(-y.value()))
>>> class C2(concrete):
... pass
<<<>>> class A1(abstract):
<<<... def f(self, y):
<<<... return abstract.f(self, Y(-y.value()))
<<<
<<<>>> class A2(abstract):
<<<... pass
<<<
>>> y1 = Y(16)
>>> y2 = Y(17)
#
# Test abstract with f overridden
#
<<<>>> a1 = A1(42)
<<<>>> a1.value()
<<<42
<<<
<<<# Call f indirectly from C++
<<<>>> a1.call_f(y1)
<<<-16
<<<
<<<# Call f directly from Python
<<<>>> a1.f(y2)
<<<-17
<<<
<<<#
<<<# Test abstract with f not overridden
<<<#
<<<>>> a2 = A2(42)
<<<>>> A2.value()
<<<42
<<<
<<<# Call f indirectly from C++
<<<>>> c1.call_f(y1)
<<<16
<<<
<<<# Call f directly from Python
<<<>>> c1.f(y2)
<<<17
<<<
############# Concrete Tests ############
#
# Test concrete with f overridden
#
>>> c1 = C1(42)
>>> c1.value()
42
# Call f indirectly from C++
>>> c1.call_f(y1)
-16
# Call f directly from Python
>>> c1.f(y2)
-17
#
# Test concrete with f not overridden
#
>>> c2 = C2(42)
>>> c2.value()
42
# Call f indirectly from C++
>>> c2.call_f(y1)
16
# Call f directly from Python
>>> c2.f(y2)
17
'''
def run(args = None):
import sys
import doctest
if args is not None:
sys.argv = args
return doctest.testmod(sys.modules.get(__name__))
if __name__ == '__main__':
print "running..."
import sys
sys.exit(run()[0])