Skip to content

Commit 6c07a40

Browse files
committed
chore: Add tests for invalid cases
1 parent 589a998 commit 6c07a40

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

tests/data/test_code_mappings.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,45 @@
22
These tests exercise the custom enum methods using arbitrary enum values.
33
"""
44

5+
import pytest
6+
57
from roborock.data.b01_q10.b01_q10_code_mappings import B01_Q10_DP
68

79

8-
def test_from_code():
10+
def test_from_code() -> None:
911
"""Test from_code method."""
1012
assert B01_Q10_DP.START_CLEAN == B01_Q10_DP.from_code(201)
1113
assert B01_Q10_DP.PAUSE == B01_Q10_DP.from_code(204)
1214
assert B01_Q10_DP.STOP == B01_Q10_DP.from_code(206)
1315

1416

15-
def test_from_name():
17+
def test_invalid_from_code() -> None:
18+
"""Test invalid from_code method."""
19+
with pytest.raises(ValueError, match="999999 is not a valid code for B01_Q10_DP") as ex:
20+
B01_Q10_DP.from_code(999999)
21+
22+
23+
def test_from_name() -> None:
1624
"""Test from_name method."""
1725
assert B01_Q10_DP.START_CLEAN == B01_Q10_DP.from_name("START_CLEAN")
1826
assert B01_Q10_DP.PAUSE == B01_Q10_DP.from_name("pause")
1927
assert B01_Q10_DP.STOP == B01_Q10_DP.from_name("Stop")
2028

2129

22-
def test_from_value():
30+
def test_invalid_from_name() -> None:
31+
"""Test invalid from_name method."""
32+
with pytest.raises(ValueError, match="INVALID_NAME is not a valid name for B01_Q10_DP") as ex:
33+
B01_Q10_DP.from_name("INVALID_NAME")
34+
35+
36+
def test_from_value() -> None:
2337
"""Test from_value method."""
2438
assert B01_Q10_DP.START_CLEAN == B01_Q10_DP.from_value("dpStartClean")
2539
assert B01_Q10_DP.PAUSE == B01_Q10_DP.from_value("dpPause")
2640
assert B01_Q10_DP.STOP == B01_Q10_DP.from_value("dpStop")
41+
42+
43+
def test_invalid_from_value() -> None:
44+
"""Test invalid from_value method."""
45+
with pytest.raises(ValueError, match="invalid_value is not a valid value for B01_Q10_DP") as ex:
46+
B01_Q10_DP.from_value("invalid_value")

0 commit comments

Comments
 (0)