]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/python/test/extract.py
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)
5 >>> from extract_ext import *
7 Just about anything has a truth value in Python
9 >>> assert check_bool(None)
10 >>> extract_bool(None)
13 >>> assert check_bool(2)
17 >>> assert not check_bool('')
19 Check that object manager types work properly. These are a different
20 case because they wrap Python objects instead of being wrapped by them.
22 >>> assert not check_list(2)
23 >>> try: x = extract_list(2)
24 ... except TypeError as x:
25 ... if str(x) != 'Expecting an object of type list; got an object of type int instead':
28 ... print('expected an exception, got', x, 'instead')
30 Can't extract a list from a tuple. Use list(x) to convert a sequence
33 >>> assert not check_list((1, 2, 3))
34 >>> assert check_list([1, 2, 3])
35 >>> extract_list([1, 2, 3])
38 Can get a char const* from a Python string:
40 >>> assert check_cstring('hello')
41 >>> extract_cstring('hello')
44 Can't get a char const* from a Python int:
46 >>> assert not check_cstring(1)
47 >>> try: x = extract_cstring(1)
48 ... except TypeError: pass
50 ... print('expected an exception, got', x, 'instead')
52 Extract an std::string (class) rvalue from a native Python type
54 >>> assert check_string('hello')
55 >>> extract_string('hello')
58 Constant references are not treated as rvalues for the purposes of
61 >>> assert not check_string_cref('hello')
63 We can extract lvalues where appropriate:
78 Demonstrate that double-extraction of an rvalue works, and all created
79 copies of the object are destroyed:
87 General check for cleanliness:
100 return doctest
.testmod(sys
.modules
.get(__name__
))
102 if __name__
== '__main__':
106 if (status
== 0): print("Done.")