forked from DIMO-Network/dimo-python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_errors.py
More file actions
33 lines (24 loc) · 1012 Bytes
/
test_errors.py
File metadata and controls
33 lines (24 loc) · 1012 Bytes
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
import pytest
from dimo.errors import DimoTypeError, check_type, check_optional_type
def test_check_type_passes_for_correct_type():
# call check_type with valid args which should not raise anything
check_type("count", 5, int)
def test_check_type_raises_for_incorrect_type():
with pytest.raises(DimoTypeError) as exc:
check_type("name", 123, str)
err = exc.value
assert err.param_name == "name"
assert err.expected_type is str
assert isinstance(err.actual_value, int)
assert "name must be a str" in str(err)
assert "but was entered as type int" in str(err)
def test_check_optional_type_allows_none():
# None is allowed
check_optional_type("maybe", None, dict)
def test_check_optional_type_raises_for_wrong_non_none():
with pytest.raises(DimoTypeError) as exc:
check_optional_type("maybe", 3.14, str)
err = exc.value
assert err.param_name == "maybe"
assert err.expected_type is str
assert isinstance(err.actual_value, float)