-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_main.py
112 lines (89 loc) · 2.89 KB
/
test_main.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
from enum import auto
import pytest
from autoname import AutoName, AutoNameLower, AutoNameUpper, StrEnum, transform
def test_normal_autoname():
class Foo(AutoName):
Final = auto()
really = auto()
KIDDING = auto()
HolyCow = auto()
whatTheMeow = auto()
assert Foo.Final.value == "Final"
assert Foo.really.value == "really"
assert Foo.KIDDING.value == "KIDDING"
assert Foo.HolyCow.value == "HolyCow"
assert Foo.whatTheMeow.value == "whatTheMeow"
def test_lower_autoname():
class Foo(AutoNameLower):
Final = auto()
really = auto()
KIDDING = auto()
HolyCow = auto()
whatTheMeow = auto()
assert Foo.Final.value == "final"
assert Foo.really.value == "really"
assert Foo.KIDDING.value == "kidding"
assert Foo.HolyCow.value == "holycow"
assert Foo.whatTheMeow.value == "whatthemeow"
def test_upper_autoname():
class Foo(AutoNameUpper):
Final = auto()
really = auto()
KIDDING = auto()
HolyCow = auto()
whatTheMeow = auto()
assert Foo.Final.value == "FINAL"
assert Foo.really.value == "REALLY"
assert Foo.KIDDING.value == "KIDDING"
assert Foo.HolyCow.value == "HOLYCOW"
assert Foo.whatTheMeow.value == "WHATTHEMEOW"
def test_alias_StrEnum():
class Foo(StrEnum):
Final = auto()
really = auto()
KIDDING = auto()
HolyCow = auto()
whatTheMeow = auto()
assert Foo.Final.value == "Final"
assert Foo.really.value == "really"
assert Foo.KIDDING.value == "KIDDING"
assert Foo.HolyCow.value == "HolyCow"
assert Foo.whatTheMeow.value == "whatTheMeow"
def test_autoname_decorator():
@transform(function=str.lower)
class Foo(StrEnum):
Final = auto()
really = auto()
KIDDING = auto()
HolyCow = auto()
whatTheMeow = auto()
assert Foo.Final.value == "final"
assert Foo.really.value == "really"
assert Foo.KIDDING.value == "kidding"
assert Foo.HolyCow.value == "holycow"
assert Foo.whatTheMeow.value == "whatthemeow"
@transform(function=str.upper)
class Foo(AutoName):
Final = auto()
really = auto()
KIDDING = auto()
HolyCow = auto()
whatTheMeow = auto()
assert Foo.Final.value == "FINAL"
assert Foo.really.value == "REALLY"
assert Foo.KIDDING.value == "KIDDING"
assert Foo.HolyCow.value == "HOLYCOW"
assert Foo.whatTheMeow.value == "WHATTHEMEOW"
def test_autoname_decorator_no_transform():
with pytest.raises(TypeError) as excinfo:
@transform
class Foo(StrEnum):
Final = auto()
really = auto()
KIDDING = auto()
HolyCow = auto()
whatTheMeow = auto()
assert (
"transform() missing 1 required keyword-only argument: 'function'"
in str(excinfo.value)
)