forked from commitizen-tools/commitizen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_exceptions.py
More file actions
38 lines (29 loc) · 1.34 KB
/
test_exceptions.py
File metadata and controls
38 lines (29 loc) · 1.34 KB
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
import pytest
from commitizen.exceptions import ExitCode
def test_from_str_with_decimal():
"""Test from_str with decimal values."""
assert ExitCode.from_str("0") == ExitCode.EXPECTED_EXIT
assert ExitCode.from_str("1") == ExitCode.NO_COMMITIZEN_FOUND
assert ExitCode.from_str("32") == ExitCode.COMMIT_MESSAGE_LENGTH_LIMIT_EXCEEDED
def test_from_str_with_enum_name():
"""Test from_str with enum names."""
assert ExitCode.from_str("EXPECTED_EXIT") == ExitCode.EXPECTED_EXIT
assert ExitCode.from_str("NO_COMMITIZEN_FOUND") == ExitCode.NO_COMMITIZEN_FOUND
assert (
ExitCode.from_str("COMMIT_MESSAGE_LENGTH_LIMIT_EXCEEDED")
== ExitCode.COMMIT_MESSAGE_LENGTH_LIMIT_EXCEEDED
)
def test_from_str_with_whitespace():
"""Test from_str with whitespace in enum names."""
assert ExitCode.from_str(" EXPECTED_EXIT ") == ExitCode.EXPECTED_EXIT
assert ExitCode.from_str("\tNO_COMMITIZEN_FOUND\t") == ExitCode.NO_COMMITIZEN_FOUND
def test_from_str_with_invalid_values():
"""Test from_str with invalid values."""
with pytest.raises(KeyError):
ExitCode.from_str("invalid_name")
with pytest.raises(ValueError):
ExitCode.from_str("999") # Out of range decimal
with pytest.raises(KeyError):
ExitCode.from_str("")
with pytest.raises(KeyError):
ExitCode.from_str(" ")