[29] | 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 | This is test module for properties. |
---|
| 6 | |
---|
| 7 | >>> r = properties.ret_type() |
---|
| 8 | >>> r.i = 22.5 |
---|
| 9 | >>> r.i |
---|
| 10 | 22.5 |
---|
| 11 | >>> c = properties.crash_me() |
---|
| 12 | >>> c.i.i |
---|
| 13 | 42.5 |
---|
| 14 | |
---|
| 15 | >>> X = properties.X |
---|
| 16 | |
---|
| 17 | >>> x1 = X(1) |
---|
| 18 | |
---|
| 19 | value read only |
---|
| 20 | >>> x1.value_r |
---|
| 21 | 1 |
---|
| 22 | |
---|
| 23 | value read - write |
---|
| 24 | >>> x1.value_rw |
---|
| 25 | 1 |
---|
| 26 | |
---|
| 27 | value direct access |
---|
| 28 | >>> x1.value_direct |
---|
| 29 | 1 |
---|
| 30 | |
---|
| 31 | class instance count read - only |
---|
| 32 | >>> X.instance_count |
---|
| 33 | 1 |
---|
| 34 | |
---|
| 35 | class instance count direct |
---|
| 36 | >>> X.instance_count_direct |
---|
| 37 | 1 |
---|
| 38 | |
---|
| 39 | class instance count injected |
---|
| 40 | >>> X.instance_count_injected |
---|
| 41 | 1 |
---|
| 42 | |
---|
| 43 | class instance count from object |
---|
| 44 | >>> x1.instance_count |
---|
| 45 | 1 |
---|
| 46 | |
---|
| 47 | class instance count from object |
---|
| 48 | >>> x1.instance_count_direct |
---|
| 49 | 1 |
---|
| 50 | |
---|
| 51 | class instance count from object: |
---|
| 52 | >>> x1.instance_count_injected |
---|
| 53 | 1 |
---|
| 54 | |
---|
| 55 | as expected you can't assign new value to read only property |
---|
| 56 | >>> x1.value_r = 2 |
---|
| 57 | Traceback (most recent call last): |
---|
| 58 | File "properties.py", line 49, in ? |
---|
| 59 | x1.value_r = 2 |
---|
| 60 | AttributeError: can't set attribute |
---|
| 61 | |
---|
| 62 | setting value_rw to 2. value_direct: |
---|
| 63 | >>> x1.value_rw = 2 |
---|
| 64 | >>> x1.value_rw |
---|
| 65 | 2 |
---|
| 66 | |
---|
| 67 | setting value_direct to 3. value_direct: |
---|
| 68 | >>> x1.value_direct = 3 |
---|
| 69 | >>> x1.value_direct |
---|
| 70 | 3 |
---|
| 71 | |
---|
| 72 | >>> assert x1.value_r == 3 |
---|
| 73 | |
---|
| 74 | >>> x2 = X(2) |
---|
| 75 | |
---|
| 76 | after creating second intstance of X instances count is 2 |
---|
| 77 | >>> x2.instance_count |
---|
| 78 | 2 |
---|
| 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') |
---|
| 90 | import properties_ext as properties |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | def 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 | |
---|
| 101 | if __name__ == '__main__': |
---|
| 102 | print "running..." |
---|
| 103 | import sys |
---|
| 104 | status = run()[0] |
---|
| 105 | if (status == 0): print "Done." |
---|
| 106 | sys.exit(status) |
---|