Skip to content

Commit 8e27ac6

Browse files
committed
Testing for error cases.
1 parent 4a06661 commit 8e27ac6

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

apps/py/ch09_testing/lib.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ def __init__(self, name: str = None, price: float = 0.0,
1212

1313

1414
def all_guitars(style: Optional[str]) -> List[Guitar]:
15+
if style is None or not style.strip():
16+
raise ValueError(f"'{style}' is an invalid style.")
17+
1518
style = style.lower()
1619

1720
log(f"Guitars for {style}")

apps/py/ch09_testing/test_lib.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from typing import List
22

3+
import pytest
4+
35
import lib
46
import pytest_mock
57
# noinspection PyUnresolvedReferences
@@ -37,3 +39,8 @@ def test_all_guitars(guitar_data: List[lib.Guitar], mocker: pytest_mock.MockFixt
3739
types = {g.style for g in guitars}
3840

3941
assert types == {'acoustic', 'electric'}
42+
43+
44+
def test_invalid_style():
45+
with pytest.raises(ValueError):
46+
lib.all_guitars(None)

0 commit comments

Comments
 (0)