@@ -21,38 +21,65 @@ def test_unscoped_enum():
21
21
22
22
# __members__ property
23
23
assert m .UnscopedEnum .__members__ == \
24
- {"EOne" : m .UnscopedEnum .EOne , "ETwo" : m .UnscopedEnum .ETwo }
24
+ {"EOne" : m .UnscopedEnum .EOne , "ETwo" : m .UnscopedEnum .ETwo , "EThree" : m . UnscopedEnum . EThree }
25
25
# __members__ readonly
26
26
with pytest .raises (AttributeError ):
27
27
m .UnscopedEnum .__members__ = {}
28
28
# __members__ returns a copy
29
29
foo = m .UnscopedEnum .__members__
30
30
foo ["bar" ] = "baz"
31
31
assert m .UnscopedEnum .__members__ == \
32
- {"EOne" : m .UnscopedEnum .EOne , "ETwo" : m .UnscopedEnum .ETwo }
32
+ {"EOne" : m .UnscopedEnum .EOne , "ETwo" : m .UnscopedEnum .ETwo , "EThree" : m . UnscopedEnum . EThree }
33
33
34
- assert m .UnscopedEnum .__doc__ == \
35
- '''An unscoped enumeration
34
+ for docstring_line in '''An unscoped enumeration
36
35
37
36
Members:
38
37
39
38
EOne : Docstring for EOne
40
39
41
- ETwo : Docstring for ETwo''' or m .UnscopedEnum .__doc__ == \
42
- '''An unscoped enumeration
43
-
44
- Members:
45
-
46
40
ETwo : Docstring for ETwo
47
41
48
- EOne : Docstring for EOne'''
42
+ EThree : Docstring for EThree''' .split ('\n ' ):
43
+ assert docstring_line in m .UnscopedEnum .__doc__
49
44
50
45
# Unscoped enums will accept ==/!= int comparisons
51
46
y = m .UnscopedEnum .ETwo
52
47
assert y == 2
53
48
assert 2 == y
54
49
assert y != 3
55
50
assert 3 != y
51
+ # Compare with None
52
+ assert (y != None ) # noqa: E711
53
+ assert not (y == None ) # noqa: E711
54
+ # Compare with an object
55
+ assert (y != object ())
56
+ assert not (y == object ())
57
+ # Compare with string
58
+ assert y != "2"
59
+ assert "2" != y
60
+ assert not ("2" == y )
61
+ assert not (y == "2" )
62
+
63
+ with pytest .raises (TypeError ):
64
+ y < object ()
65
+
66
+ with pytest .raises (TypeError ):
67
+ y <= object ()
68
+
69
+ with pytest .raises (TypeError ):
70
+ y > object ()
71
+
72
+ with pytest .raises (TypeError ):
73
+ y >= object ()
74
+
75
+ with pytest .raises (TypeError ):
76
+ y | object ()
77
+
78
+ with pytest .raises (TypeError ):
79
+ y & object ()
80
+
81
+ with pytest .raises (TypeError ):
82
+ y ^ object ()
56
83
57
84
assert int (m .UnscopedEnum .ETwo ) == 2
58
85
assert str (m .UnscopedEnum (2 )) == "UnscopedEnum.ETwo"
@@ -71,6 +98,11 @@ def test_unscoped_enum():
71
98
assert not (m .UnscopedEnum .ETwo < m .UnscopedEnum .EOne )
72
99
assert not (2 < m .UnscopedEnum .EOne )
73
100
101
+ # arithmetic
102
+ assert m .UnscopedEnum .EOne & m .UnscopedEnum .EThree == m .UnscopedEnum .EOne
103
+ assert m .UnscopedEnum .EOne | m .UnscopedEnum .ETwo == m .UnscopedEnum .EThree
104
+ assert m .UnscopedEnum .EOne ^ m .UnscopedEnum .EThree == m .UnscopedEnum .ETwo
105
+
74
106
75
107
def test_scoped_enum ():
76
108
assert m .test_scoped_enum (m .ScopedEnum .Three ) == "ScopedEnum::Three"
@@ -82,6 +114,12 @@ def test_scoped_enum():
82
114
assert not 3 == z
83
115
assert z != 3
84
116
assert 3 != z
117
+ # Compare with None
118
+ assert (z != None ) # noqa: E711
119
+ assert not (z == None ) # noqa: E711
120
+ # Compare with an object
121
+ assert (z != object ())
122
+ assert not (z == object ())
85
123
# Scoped enums will *NOT* accept >, <, >= and <= int comparisons (Will throw exceptions)
86
124
with pytest .raises (TypeError ):
87
125
z > 3
0 commit comments