Skip to content

Commit eca2199

Browse files
committed
Add tests for raise_if_error function
1 parent 45c4371 commit eca2199

File tree

1 file changed

+57
-2
lines changed

1 file changed

+57
-2
lines changed

tests/test_device.py

+57-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,57 @@
1-
def test_test():
2-
assert True
1+
import pytest
2+
3+
from xbee_helper import device, exceptions, ZigBee
4+
5+
6+
def test_raise_if_error_no_status():
7+
"""
8+
Should return None without raising if there's no "status" key in frame.
9+
"""
10+
assert device.raise_if_error({}) is None
11+
12+
13+
def test_raise_if_error_zero():
14+
"""
15+
Should return None without raising if "status" is set to b"\x00".
16+
"""
17+
assert device.raise_if_error(dict(status=b"\x00")) is None
18+
19+
20+
def test_raise_if_error_unknown():
21+
"""
22+
Should raise ZigBeeUnknownError if "status" is set to b"\x01".
23+
"""
24+
with pytest.raises(exceptions.ZigBeeUnknownError):
25+
device.raise_if_error(dict(status=b"\x01"))
26+
27+
28+
def test_raise_if_error_invalid_cmd():
29+
"""
30+
Should raise ZigBeeInvalidCommand if "status" is set to b"\x02".
31+
"""
32+
with pytest.raises(exceptions.ZigBeeInvalidCommand):
33+
device.raise_if_error(dict(status=b"\x02"))
34+
35+
36+
def test_raise_if_error_invalid_param():
37+
"""
38+
Should raise ZigBeeInvalidParameter if "status" is set to b"\x03".
39+
"""
40+
with pytest.raises(exceptions.ZigBeeInvalidParameter):
41+
device.raise_if_error(dict(status=b"\x03"))
42+
43+
44+
def test_raise_if_error_tx_failure():
45+
"""
46+
Should raise ZigBeeTxFailure if "status" is set to b"\x04".
47+
"""
48+
with pytest.raises(exceptions.ZigBeeTxFailure):
49+
device.raise_if_error(dict(status=b"\x04"))
50+
51+
52+
def test_raise_if_error_unknown_status():
53+
"""
54+
Should raise ZigBeeUnknownStatus if "status" is unrecognised.
55+
"""
56+
with pytest.raises(exceptions.ZigBeeUnknownStatus):
57+
device.raise_if_error(dict(status=b"\xFF"))

0 commit comments

Comments
 (0)