1# Copyright David Abrahams 2004. Distributed under the Boost
2# Software License, Version 1.0. (See accompanying
3# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4'''
5>>> from virtual_functions_ext import *
6
7>>> class C1(concrete):
8...     def f(self, y):
9...         return concrete.f(self, Y(-y.value()))
10
11>>> class C2(concrete):
12...     pass
13
14>>> class A1(abstract):
15...     def f(self, y):
16...         return y.value() * 2
17...     def g(self, y):
18...         return self
19
20>>> class A2(abstract):
21...     pass
22
23
24>>> y1 = Y(16)
25>>> y2 = Y(17)
26
27
28
29#
30# Test abstract with f,g overridden
31#
32>>> a1 = A1(42)
33>>> a1.value()
3442
35
36# Call f,g indirectly from C++
37>>> a1.call_f(y1)
3832
39>>> assert type(a1.call_g(y1)) is abstract
40
41# Call f directly from Python
42>>> a1.f(y2)
4334
44
45#
46# Test abstract with f not overridden
47#
48>>> a2 = A2(42)
49>>> a2.value()
5042
51
52# Call f indirectly from C++
53>>> try: a2.call_f(y1)
54... except AttributeError: pass
55... else: print('no exception')
56
57# Call f directly from Python
58>>> try: a2.call_f(y2)
59... except AttributeError: pass
60... else: print('no exception')
61
62############# Concrete Tests ############
63
64#
65# Test concrete with f overridden
66#
67>>> c1 = C1(42)
68>>> c1.value()
6942
70
71# Call f indirectly from C++
72>>> c1.call_f(y1)
73-16
74
75# Call f directly from Python
76>>> c1.f(y2)
77-17
78
79#
80# Test concrete with f not overridden
81#
82>>> c2 = C2(42)
83>>> c2.value()
8442
85
86# Call f indirectly from C++
87>>> c2.call_f(y1)
8816
89
90# Call f directly from Python
91>>> c2.f(y2)
9217
93
94
95'''
96
97def run(args = None):
98    import sys
99    import doctest
100
101    if args is not None:
102        sys.argv = args
103    return doctest.testmod(sys.modules.get(__name__))
104
105if __name__ == '__main__':
106    print("running...")
107    import sys
108    status = run()[0]
109    if (status == 0): print("Done.")
110    sys.exit(status)
111