1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
# Copyright David Abrahams 2004. Distributed under the Boost
# Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
"""
This is test module for properties.
>>> r = properties.ret_type()
>>> r.i = 22.5
>>> r.i
22.5
>>> c = properties.crash_me()
>>> c.i.i
42.5
>>> X = properties.X
>>> x1 = X(1)
value read only
>>> x1.value_r
1
>>> x1.value_r_f
1
value read - write
>>> x1.value_rw
1
value direct access
>>> x1.value_direct
1
class instance count read - only
>>> X.instance_count
1
class instance count direct
>>> X.instance_count_direct
1
class instance count injected
>>> X.instance_count_injected
1
class instance count from object
>>> x1.instance_count
1
class instance count from object
>>> x1.instance_count_direct
1
class instance count from object:
>>> x1.instance_count_injected
1
as expected you can't assign new value to read only property
>>> x1.value_r = 2
Traceback (most recent call last):
File "properties.py", line 49, in ?
x1.value_r = 2
AttributeError: can't set attribute
setting value_rw to 2. value_direct:
>>> x1.value_rw = 2
>>> x1.value_rw
2
setting value_direct to 3. value_direct:
>>> x1.value_direct = 3
>>> x1.value_direct
3
>>> assert x1.value_r == 3
>>> x2 = X(2)
after creating second intstance of X instances count is 2
>>> x2.instance_count
2
>>> del x2
>>> assert x1.instance_count == 1
>>> assert properties.X.value_r_ds.__doc__ == "value_r_ds is read-only"
>>> assert properties.X.value_rw_ds.__doc__ == "value_rw_ds is read-write"
>>> properties.X.value_r_f.fget.__doc__.strip().split("\\n")[0]
'None( (properties_ext.X)arg1) -> int :'
>>> properties.X.value_rw_ds.fget.__doc__.strip().split("\\n")[0]
'None( (properties_ext.X)arg1) -> int :'
>>> properties.X.value_rw_ds.fset.__doc__.strip().split("\\n")[0]
'None( (properties_ext.X)arg1, (int)arg2) -> None :'
>>> properties.X.value_rw_ds.fget.__doc__.strip().split("\\n")[0]
'None( (properties_ext.X)arg1) -> int :'
>>> properties.X.value_direct.fset.__doc__.strip().split("\\n")[0]
'None( (properties_ext.X)arg1, (int)arg2) -> None :'
>>> properties.X.value_direct.fget.__doc__.strip().split("\\n")[0]
'None( (properties_ext.X)arg1) -> int :'
"""
# FIXME: cases to cover: pointer-to-member, preconstructed function
#import sys; sys.path.append(r'P:\Actimize4.0\smart_const\py_smart_const___Win32_Debug')
import properties_ext as properties
def run(args = None):
import sys
import doctest
if args is not None:
sys.argv = args
return doctest.testmod(sys.modules.get(__name__))
if __name__ == '__main__':
print("running...")
import sys
status = run()[0]
if (status == 0): print("Done.")
sys.exit(status)
|