Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/python/test/properties.py @ 45

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

updated boost from 1_33_1 to 1_34_1

File size: 1.9 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"""
5This is test module for properties.
6
7>>> r = properties.ret_type()
8>>> r.i = 22.5
9>>> r.i
1022.5
11>>> c = properties.crash_me()
12>>> c.i.i
1342.5
14
15>>> X = properties.X
16
17>>> x1 = X(1)
18
19value read only
20>>> x1.value_r
211
22
23value read - write
24>>> x1.value_rw
251
26
27value direct access
28>>> x1.value_direct
291
30
31class instance count read - only
32>>> X.instance_count
331
34
35class instance count direct
36>>> X.instance_count_direct
371
38
39class instance count injected
40>>> X.instance_count_injected
411
42
43class instance count from object
44>>> x1.instance_count
451
46
47class instance count from object
48>>> x1.instance_count_direct
491
50
51class instance count from object:
52>>> x1.instance_count_injected
531
54
55as expected you can't assign new value to read only property
56>>> x1.value_r = 2
57Traceback (most recent call last):
58  File "properties.py", line 49, in ?
59    x1.value_r = 2
60AttributeError: can't set attribute
61
62setting value_rw to 2. value_direct:
63>>> x1.value_rw = 2
64>>> x1.value_rw
652
66
67setting value_direct to 3. value_direct:
68>>> x1.value_direct = 3
69>>> x1.value_direct
703
71
72>>> assert x1.value_r == 3
73
74>>> x2 = X(2)
75
76after creating second intstance of X instances count is 2
77>>> x2.instance_count
782
79
80>>> del x2
81>>> assert x1.instance_count == 1
82
83>>> assert properties.X.value_r_ds.__doc__ == "value_r_ds is read-only"
84
85>>> assert properties.X.value_rw_ds.__doc__ == "value_rw_ds is read-write"
86
87"""
88
89#import sys; sys.path.append(r'P:\Actimize4.0\smart_const\py_smart_const___Win32_Debug')
90import properties_ext as properties
91
92
93def run(args = None):
94    import sys
95    import doctest
96
97    if args is not None:
98        sys.argv = args
99    return doctest.testmod(sys.modules.get(__name__))
100   
101if __name__ == '__main__':
102    print "running..."
103    import sys
104    status = run()[0]
105    if (status == 0): print "Done."
106    sys.exit(status)
Note: See TracBrowser for help on using the repository browser.