• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 auto_ptr_ext import *
6>>> x = X(42)
7>>> x.value()
842
9>>> look(x), look(x)
10(42, 42)
11
12>>> maybe_steal(x, 0)
1342
14>>> look(x)
1542
16
17>>> maybe_steal(x, 1)
1842
19>>> broken_auto_ptr and -1 or look(x)
20-1
21
22>>> x = X(69)
23>>> steal(x)
2469
25>>> broken_auto_ptr and -1 or look(x)
26-1
27
28>>> if not broken_auto_ptr:
29...     try: x.value()
30...     except TypeError: pass
31...     else: print('expected a TypeError exception')
32
33>>> x = make()
34>>> look(x)
3577
36
37>>> z = callback(lambda z: z)
38>>> z.value()
3977
40
41>>> extract(x).value()
4277
43
44#
45# Test derived to base conversions
46#
47
48>>> y = Y(42)
49>>> y.value()
5042
51
52>>> try: maybe_steal(y, 0)
53... except TypeError: pass
54... else: print('expected a TypeError exception')
55
56>>> y.value()
5742
58
59>>> broken_auto_ptr and 42 or steal(y)
6042
61
62>>> if not broken_auto_ptr:
63...     try: y.value()
64...     except TypeError: pass
65...     else: print('expected a TypeError exception')
66
67>>> print(look.__doc__.splitlines()[1])
68look( (X)arg1) -> int :
69
70>>> print(steal.__doc__.splitlines()[1])
71steal( (X)arg1) -> int :
72
73>>> print(maybe_steal.__doc__.splitlines()[1])
74maybe_steal( (X)arg1, (bool)arg2) -> int :
75
76>>> print(make.__doc__.splitlines()[1])
77make() -> X :
78
79>>> print(callback.__doc__.splitlines()[1])
80callback( (object)arg1) -> X :
81
82>>> print(extract.__doc__.splitlines()[1])
83extract( (object)arg1) -> X :
84
85'''
86
87def run(args = None):
88    import sys
89    import doctest
90
91    if args is not None:
92        sys.argv = args
93    return doctest.testmod(sys.modules.get(__name__))
94
95if __name__ == '__main__':
96    print("running...")
97    import sys
98    status = run()[0]
99    if (status == 0): print("Done.")
100    sys.exit(status)
101