Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/python/test/object.py @ 29

Last change on this file since 29 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 2.1 KB
Line 
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 object_ext import *
6
7>>> type(ref_to_noncopyable())
8<class 'object_ext.NotCopyable'>
9
10>>> def print1(x):
11...     print x
12>>> call_object_3(print1)
133
14>>> message()
15'hello, world!'
16>>> number()
1742
18
19>>> test('hi')
201
21>>> test(None)
220
23>>> test_not('hi')
240
25>>> test_not(0)
261
27
28        Attributes
29
30>>> class X: pass
31...
32>>> x = X()
33
34>>> try: obj_getattr(x, 'foo')
35... except AttributeError: pass
36... else: print 'expected an exception'
37
38>>> obj_setattr(x, 'foo', 1)
39>>> x.foo
401
41>>> obj_getattr(x, 'foo')
421
43>>> obj_const_getattr(x, 'foo')
441
45>>> obj_setattr42(x, 'foo')
46>>> x.foo
4742
48>>> obj_moveattr(x, 'foo', 'bar')
49>>> x.bar
5042
51>>> test_attr(x, 'foo')
521
53>>> test_not_attr(x, 'foo')
540
55>>> x.foo = None
56>>> test_attr(x, 'foo')
570
58>>> test_not_attr(x, 'foo')
591
60
61        Items
62
63>>> d = {}
64>>> obj_setitem(d, 'foo', 1)
65>>> d['foo']
661
67>>> obj_getitem(d, 'foo')
681
69>>> obj_const_getitem(d, 'foo')
701
71>>> obj_setitem42(d, 'foo')
72>>> obj_getitem(d, 'foo')
7342
74>>> d['foo']
7542
76>>> obj_moveitem(d, 'foo', 'bar')
77>>> d['bar']
7842
79>>> obj_moveitem2(d, 'bar', d, 'baz')
80>>> d['baz']
8142
82>>> test_item(d, 'foo')
831
84>>> test_not_item(d, 'foo')
850
86>>> d['foo'] = None
87>>> test_item(d, 'foo')
880
89>>> test_not_item(d, 'foo')
901
91
92        Slices
93       
94>>> assert check_string_slice()
95
96        Operators
97
98       
99>>> assert check_binary_operators()
100
101>>> class X: pass
102...
103>>> assert check_inplace(range(3), X())
104
105
106       Now make sure that object is actually managing reference counts
107       
108>>> import weakref
109>>> class Z: pass
110...
111>>> z = Z()
112>>> def death(r): print 'death'
113...
114>>> r = weakref.ref(z, death)
115>>> z.foo = 1
116>>> obj_getattr(z, 'foo')
1171
118>>> del z
119death
120'''
121
122def run(args = None):
123    import sys
124    import doctest
125
126    if args is not None:
127        sys.argv = args
128    return doctest.testmod(sys.modules.get(__name__))
129   
130if __name__ == '__main__':
131    print "running..."
132    import sys
133    status = run()[0]
134    if (status == 0): print "Done."
135    sys.exit(status)
Note: See TracBrowser for help on using the repository browser.