]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/python/test/newtest.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)
9 Prove that we get an appropriate error from trying to return a type
10 for which we have no registered to_python converter
12 >>> def check_unregistered(f, msgprefix):
15 ... except TypeError as x:
16 ... if not str(x).startswith(msgprefix):
19 ... print('expected a TypeError')
21 >>> check_unregistered(make_unregistered, 'No to_python (by-value) converter found for C++ type')
22 >>> check_unregistered(make_unregistered2, 'No Python class registered for C++ class')
30 >>> unwrap_int_const_ref(n)
34 >>> unwrap_simple_ref(s)
36 >>> unwrap_simple_const_ref(s)
41 Can't get a non-const reference to a built-in integer object
45 ... else: print('no exception')
47 >>> unwrap_int_const_ref(9)
55 ... else: print('no exception')
57 >>> wrap_int_const_ref(n)
60 >>> unwrap_simple_ref(wrap_simple(s))
63 >>> unwrap_simple_ref(wrap_simple_ref(s))
66 >>> unwrap_simple_ref(wrap_simple_const_ref(s))
72 >>> unwrap_simple(g(s))
78 >>> f_mutable_ref(g(s))
84 >>> f_mutable_ptr(g(s))
90 Create an extension class which wraps "complicated" (init1 and get_n)
91 are a complicated constructor and member function, respectively.
93 >>> c1 = complicated(s, 99)
96 >>> c2 = complicated(s)
100 a quick regression test for a bug where None could be converted
101 to the target of any member function. To see it, we need to
102 access the __dict__ directly, to bypass the type check supplied
103 by the Method property which wraps the method when accessed as an
106 >>> try: A.__dict__['name'](None)
107 ... except TypeError: pass
108 ... else: print('expected an exception!')
123 ... else: print('no exception')
128 ... else: print('no exception')
133 ... else: print('no exception')
145 ... else: print('no exception')
150 ... else: print('no exception')
159 ... else: print('no exception')
167 ... else: print('no exception')
179 >>> take_d_shared_ptr(d).name()
182 >>> d_as_a = d_factory()
183 >>> dd = take_d(d_as_a)
186 >>> print(g.__doc__.splitlines()[1])
187 g( (Simple)arg1) -> Simple :
191 def run(args
= None):
199 return doctest
.testmod(sys
.modules
.get(__name__
))
201 if __name__
== '__main__':
205 if (status
== 0): print("Done.")