properties.py 1.9 KB

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