3 from pybind11_tests
import enums
as m
7 assert str(m.UnscopedEnum.EOne) ==
"UnscopedEnum.EOne" 8 assert str(m.UnscopedEnum.ETwo) ==
"UnscopedEnum.ETwo" 9 assert str(m.EOne) ==
"UnscopedEnum.EOne" 12 assert m.UnscopedEnum.EOne.name ==
"EOne" 13 assert m.UnscopedEnum.ETwo.name ==
"ETwo" 14 assert m.EOne.name ==
"EOne" 16 with pytest.raises(AttributeError):
17 m.UnscopedEnum.EOne.name =
"" 19 foo = m.UnscopedEnum.EOne.name
21 assert m.UnscopedEnum.EOne.name ==
"EOne" 24 assert m.UnscopedEnum.__members__ == \
25 {
"EOne": m.UnscopedEnum.EOne,
"ETwo": m.UnscopedEnum.ETwo,
"EThree": m.UnscopedEnum.EThree}
27 with pytest.raises(AttributeError):
28 m.UnscopedEnum.__members__ = {}
30 foo = m.UnscopedEnum.__members__
32 assert m.UnscopedEnum.__members__ == \
33 {
"EOne": m.UnscopedEnum.EOne,
"ETwo": m.UnscopedEnum.ETwo,
"EThree": m.UnscopedEnum.EThree}
35 for docstring_line
in '''An unscoped enumeration 39 EOne : Docstring for EOne 41 ETwo : Docstring for ETwo 43 EThree : Docstring for EThree'''.
split(
'\n'):
44 assert docstring_line
in m.UnscopedEnum.__doc__
47 y = m.UnscopedEnum.ETwo
54 assert not (y ==
None)
64 with pytest.raises(TypeError):
67 with pytest.raises(TypeError):
70 with pytest.raises(TypeError):
73 with pytest.raises(TypeError):
76 with pytest.raises(TypeError):
79 with pytest.raises(TypeError):
82 with pytest.raises(TypeError):
85 assert int(m.UnscopedEnum.ETwo) == 2
86 assert str(m.UnscopedEnum(2)) ==
"UnscopedEnum.ETwo" 89 assert m.UnscopedEnum.EOne < m.UnscopedEnum.ETwo
90 assert m.UnscopedEnum.EOne < 2
91 assert m.UnscopedEnum.ETwo > m.UnscopedEnum.EOne
92 assert m.UnscopedEnum.ETwo > 1
93 assert m.UnscopedEnum.ETwo <= 2
94 assert m.UnscopedEnum.ETwo >= 2
95 assert m.UnscopedEnum.EOne <= m.UnscopedEnum.ETwo
96 assert m.UnscopedEnum.EOne <= 2
97 assert m.UnscopedEnum.ETwo >= m.UnscopedEnum.EOne
98 assert m.UnscopedEnum.ETwo >= 1
99 assert not (m.UnscopedEnum.ETwo < m.UnscopedEnum.EOne)
100 assert not (2 < m.UnscopedEnum.EOne)
103 assert m.UnscopedEnum.EOne & m.UnscopedEnum.EThree == m.UnscopedEnum.EOne
104 assert m.UnscopedEnum.EOne | m.UnscopedEnum.ETwo == m.UnscopedEnum.EThree
105 assert m.UnscopedEnum.EOne ^ m.UnscopedEnum.EThree == m.UnscopedEnum.ETwo
109 assert m.test_scoped_enum(m.ScopedEnum.Three) ==
"ScopedEnum::Three" 111 assert m.test_scoped_enum(z) ==
"ScopedEnum::Two" 120 assert not (z ==
None)
123 assert not (z ==
object())
125 with pytest.raises(TypeError):
127 with pytest.raises(TypeError):
129 with pytest.raises(TypeError):
131 with pytest.raises(TypeError):
135 assert m.ScopedEnum.Two < m.ScopedEnum.Three
136 assert m.ScopedEnum.Three > m.ScopedEnum.Two
137 assert m.ScopedEnum.Two <= m.ScopedEnum.Three
138 assert m.ScopedEnum.Two <= m.ScopedEnum.Two
139 assert m.ScopedEnum.Two >= m.ScopedEnum.Two
140 assert m.ScopedEnum.Three >= m.ScopedEnum.Two
144 assert str(m.ClassWithUnscopedEnum.EMode.EFirstMode) ==
"EMode.EFirstMode" 145 assert str(m.ClassWithUnscopedEnum.EFirstMode) ==
"EMode.EFirstMode" 147 f = m.ClassWithUnscopedEnum.test_function
148 first = m.ClassWithUnscopedEnum.EFirstMode
149 second = m.ClassWithUnscopedEnum.ESecondMode
153 assert f(first) ==
f(first)
154 assert not f(first) !=
f(first)
156 assert f(first) !=
f(second)
157 assert not f(first) ==
f(second)
159 assert f(first) ==
int(
f(first))
160 assert not f(first) !=
int(
f(first))
162 assert f(first) !=
int(
f(second))
163 assert not f(first) ==
int(
f(second))
166 x = {
f(first): 1,
f(second): 2}
170 assert str(x) ==
"{EMode.EFirstMode: 3, EMode.ESecondMode: 4}" 174 assert int(m.Flags.Read) == 4
175 assert int(m.Flags.Write) == 2
176 assert int(m.Flags.Execute) == 1
177 assert int(m.Flags.Read | m.Flags.Write | m.Flags.Execute) == 7
178 assert int(m.Flags.Read | m.Flags.Write) == 6
179 assert int(m.Flags.Read | m.Flags.Execute) == 5
180 assert int(m.Flags.Write | m.Flags.Execute) == 3
181 assert int(m.Flags.Write | 1) == 3
182 assert ~m.Flags.Write == -3
184 state = m.Flags.Read | m.Flags.Write
185 assert (state & m.Flags.Read) != 0
186 assert (state & m.Flags.Write) != 0
187 assert (state & m.Flags.Execute) == 0
188 assert (state & 1) == 0
192 assert int(state ^ state2) == -1
196 m.test_enum_to_int(m.Flags.Read)
197 m.test_enum_to_int(m.ClassWithUnscopedEnum.EMode.EFirstMode)
198 m.test_enum_to_uint(m.Flags.Read)
199 m.test_enum_to_uint(m.ClassWithUnscopedEnum.EMode.EFirstMode)
200 m.test_enum_to_long_long(m.Flags.Read)
201 m.test_enum_to_long_long(m.ClassWithUnscopedEnum.EMode.EFirstMode)
205 with pytest.raises(ValueError)
as excinfo:
206 m.register_bad_enum()
207 assert str(excinfo.value) ==
'SimpleEnum: element "ONE" already exists!'
def test_binary_operators()
void split(const G &g, const PredecessorMap< KEY > &tree, G &Ab1, G &Ab2)
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
def test_duplicate_enum_name()
def test_implicit_conversion()