]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/python/test/object.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)
4 from __future__
import print_function
6 >>> from object_ext import *
8 >>> type(ref_to_noncopyable())
9 <class 'object_ext.NotCopyable'>
13 >>> call_object_3(print1)
35 >>> try: obj_getattr(x, 'foo')
36 ... except AttributeError: pass
37 ... else: print('expected an exception')
38 >>> try: obj_objgetattr(x, 'objfoo')
39 ... except AttributeError: pass
40 ... else: print('expected an exception')
42 >>> obj_setattr(x, 'foo', 1)
45 >>> obj_objsetattr(x, 'objfoo', 1)
46 >>> try:obj_objsetattr(x, 1)
47 ... except TypeError: pass
48 ... else: print('expected an exception')
51 >>> obj_getattr(x, 'foo')
53 >>> obj_objgetattr(x, 'objfoo')
55 >>> try:obj_objgetattr(x, 1)
56 ... except TypeError: pass
57 ... else: print('expected an exception')
58 >>> obj_const_getattr(x, 'foo')
60 >>> obj_const_objgetattr(x, 'objfoo')
62 >>> obj_setattr42(x, 'foo')
65 >>> obj_objsetattr42(x, 'objfoo')
68 >>> obj_moveattr(x, 'foo', 'bar')
71 >>> obj_objmoveattr(x, 'objfoo', 'objbar')
74 >>> test_attr(x, 'foo')
76 >>> test_objattr(x, 'objfoo')
78 >>> test_not_attr(x, 'foo')
80 >>> test_not_objattr(x, 'objfoo')
83 >>> test_attr(x, 'foo')
86 >>> test_objattr(x, 'objfoo')
88 >>> test_not_attr(x, 'foo')
90 >>> test_not_objattr(x, 'objfoo')
92 >>> obj_delattr(x, 'foo')
93 >>> obj_objdelattr(x, 'objfoo')
94 >>> try:obj_delattr(x, 'foo')
95 ... except AttributeError: pass
96 ... else: print('expected an exception')
97 >>> try:obj_objdelattr(x, 'objfoo')
98 ... except AttributeError: pass
99 ... else: print('expected an exception')
104 >>> obj_setitem(d, 'foo', 1)
107 >>> obj_getitem(d, 'foo')
109 >>> obj_const_getitem(d, 'foo')
111 >>> obj_setitem42(d, 'foo')
112 >>> obj_getitem(d, 'foo')
116 >>> obj_moveitem(d, 'foo', 'bar')
119 >>> obj_moveitem2(d, 'bar', d, 'baz')
122 >>> test_item(d, 'foo')
124 >>> test_not_item(d, 'foo')
127 >>> test_item(d, 'foo')
129 >>> test_not_item(d, 'foo')
134 >>> assert check_string_slice()
138 >>> def print_args(*args, **kwds):
139 ... print(args, kwds)
140 >>> test_call(print_args, (0, 1, 2, 3), {'a':'A'})
141 (0, 1, 2, 3) {'a': 'A'}
144 >>> assert check_binary_operators()
148 >>> assert check_inplace(list(range(3)), X())
151 Now make sure that object is actually managing reference counts
157 >>> def death(r): print('death')
159 >>> r = weakref.ref(z, death)
161 >>> obj_getattr(z, 'foo')
167 def run(args
= None):
173 return doctest
.testmod(sys
.modules
.get(__name__
))
175 if __name__
== '__main__':
179 if (status
== 0): print("Done.")