2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-19 04:22:16 +00:00
Files
python/test/properties.py
Eisuke Kawashima aa458d2ca9 fix(test.properties): use doctest.ELLIPSIS for traceback
Since python 3.11 (PEP 657) traceback info is changed
fix #460
2025-10-25 15:22:21 -04:00

128 lines
2.6 KiB
Python

# 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 # doctest: +ELLIPSIS
Traceback (most recent call last):
...
AttributeError: ...
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)