MCPcopy Create free account
hub / github.com/pybind/pybind11 / test_scoped_enum

Function test_scoped_enum

tests/test_enum.py:133–165  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

131
132
133def test_scoped_enum():
134 assert m.test_scoped_enum(m.ScopedEnum.Three) == "ScopedEnum::Three"
135 z = m.ScopedEnum.Two
136 assert m.test_scoped_enum(z) == "ScopedEnum::Two"
137
138 # Scoped enums will *NOT* accept ==/!= int comparisons (Will always return False)
139 assert not z == 3
140 assert not 3 == z
141 assert z != 3
142 assert 3 != z
143 # Compare with None
144 assert z != None # noqa: E711
145 assert not (z == None) # noqa: E711
146 # Compare with an object
147 assert z != object()
148 assert not (z == object())
149 # Scoped enums will *NOT* accept >, <, >= and <= int comparisons (Will throw exceptions)
150 with pytest.raises(TypeError):
151 z > 3 # noqa: B015
152 with pytest.raises(TypeError):
153 z < 3 # noqa: B015
154 with pytest.raises(TypeError):
155 z >= 3 # noqa: B015
156 with pytest.raises(TypeError):
157 z <= 3 # noqa: B015
158
159 # order
160 assert m.ScopedEnum.Two < m.ScopedEnum.Three
161 assert m.ScopedEnum.Three > m.ScopedEnum.Two
162 assert m.ScopedEnum.Two <= m.ScopedEnum.Three
163 assert m.ScopedEnum.Two <= m.ScopedEnum.Two
164 assert m.ScopedEnum.Two >= m.ScopedEnum.Two
165 assert m.ScopedEnum.Three >= m.ScopedEnum.Two
166
167
168def test_implicit_conversion():

Callers

nothing calls this directly

Calls 1

objectFunction · 0.50

Tested by

no test coverage detected