forked from kljohann/genpybind-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenums_test.py
66 lines (51 loc) · 2.57 KB
/
enums_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import sys
import pytest
import pyenums as m
def test_unscoped_enum():
assert m.test_enum(m.YES) == "Yes"
assert m.test_enum(m.NO) == "No"
assert m.test_enum(m.MAYBE) == "Maybe"
assert m.YES == m.State.YES
assert m.YES == m.State(0)
assert sorted(m.State.__members__.keys()) == ["MAYBE", "NO", "YES"]
assert int(m.YES) == 0 and m.YES == 0
with pytest.raises(TypeError, match="unsupported operand type"):
m.YES | m.NO # pylint: disable=pointless-statement
def test_arithmetic_enum():
assert int(m.Access.Read | m.Access.Write | m.Access.Execute) == 7
assert int(m.Access.Read | m.Access.Write) == 6
assert int(m.Access.Write) == 2
state = m.Access.Read | m.Access.Write
assert (state & m.Access.Read) != 0
assert (state & m.Access.Write) != 0
assert (state & m.Access.Execute) == 0
def test_scoped_enum():
assert m.Color(2) == m.Color.blue
assert m.test_enum(m.Color.red) == "red"
assert m.test_enum(m.Color.green) == "green"
assert m.test_enum(m.Color.blue) == "blue"
with pytest.raises(TypeError):
m.test_enum(2)
# FIXME: Find out why test is failing
# with pytest.raises(TypeError, match="incompatible function arguments"):
# m.Color.blue == 0 # pylint: disable=pointless-statement
# FIXME: Find out why test is failing
# with pytest.raises(TypeError, match="incompatible function arguments"):
# 0 == m.Color.blue # pylint: disable=pointless-statement,misplaced-comparison-constant
# FIXME: Find out why test is failing
# with pytest.raises(TypeError, match="incompatible function arguments"):
# m.Color.blue == "uiae" # pylint: disable=pointless-statement
# FIXME: Find out why test is failing
# with pytest.raises(TypeError, match="incompatible function arguments"):
# "uiae" == m.Color.blue # pylint: disable=pointless-statement,misplaced-comparison-constant
assert not hasattr(m, "blue")
if sys.version_info.major < 3:
pytest.skip("scoped enum comparison test only works for python3")
with pytest.raises(TypeError, match="not supported between instances of"):
m.Color.blue < 0 # pylint: disable=pointless-statement
with pytest.raises(TypeError, match="not supported between instances of"):
0 < m.Color.blue # pylint: disable=pointless-statement,misplaced-comparison-constant
def test_export_values():
assert m.EnumerationFromScoped == m.ScopedButExportValues.EnumerationFromScoped
assert hasattr(m.UnscopedNoExport, "EnumerationNotExported")
assert not hasattr(m, "EnumeratinNotExported")