]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/python/test/test_enum.py
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / python / test / test_enum.py
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 >>> from enum_ext import *
6
7 >>> identity(color.red) # in case of duplicated enums it always take the last enum
8 enum_ext.color.blood
9
10 >>> identity(color.green)
11 enum_ext.color.green
12
13 >>> identity(color.blue)
14 enum_ext.color.blue
15
16 >>> identity(color(1)) # in case of duplicated enums it always take the last enum
17 enum_ext.color.blood
18
19 >>> identity(color(2))
20 enum_ext.color.green
21
22 >>> identity(color(3))
23 enum_ext.color(3)
24
25 >>> identity(color(4))
26 enum_ext.color.blue
27
28 --- check export to scope ---
29
30 >>> identity(red)
31 enum_ext.color.blood
32
33 >>> identity(green)
34 enum_ext.color.green
35
36 >>> identity(blue)
37 enum_ext.color.blue
38
39 >>> try: identity(1)
40 ... except TypeError: pass
41 ... else: print('expected a TypeError')
42
43 >>> c = colorized()
44 >>> c.x
45 enum_ext.color.blood
46 >>> c.x = green
47 >>> c.x
48 enum_ext.color.green
49 >>> red == blood
50 True
51 >>> red == green
52 False
53 >>> hash(red) == hash(blood)
54 True
55 >>> hash(red) == hash(green)
56 False
57 '''
58
59 # pickling of enums only works with Python 2.3 or higher
60 exercise_pickling = '''
61 >>> import pickle
62 >>> p = pickle.dumps(color.green, pickle.HIGHEST_PROTOCOL)
63 >>> l = pickle.loads(p)
64 >>> identity(l)
65 enum_ext.color.green
66 '''
67
68 def run(args = None):
69 import sys
70 import doctest
71 import pickle
72
73 if args is not None:
74 sys.argv = args
75 self = sys.modules.get(__name__)
76 if (hasattr(pickle, "HIGHEST_PROTOCOL")):
77 self.__doc__ += exercise_pickling
78 return doctest.testmod(self)
79
80 if __name__ == '__main__':
81 print("running...")
82 import sys
83 status = run()[0]
84 if (status == 0): print("Done.")
85 sys.exit(status)