Skip to content

Commit 14859a3

Browse files
committed
test_address: test for bad input
1 parent ec17e8b commit 14859a3

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

tests/test_address.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11

2-
from alsa_midi import Address
2+
import errno
3+
4+
import pytest
5+
6+
from alsa_midi import Address, ALSAError
37

48

59
def test_construct_int():
@@ -16,20 +20,46 @@ def test_construct_int_int():
1620
assert addr.port_id == 2
1721

1822

23+
def test_construct_int_str():
24+
with pytest.raises(ValueError):
25+
Address(129, "x") # type: ignore
26+
27+
1928
def test_construct_tuple():
2029
addr = Address((1, 2))
2130
assert isinstance(addr, Address)
2231
assert addr.client_id == 1
2332
assert addr.port_id == 2
2433

2534

35+
def test_construct_tuple_str():
36+
with pytest.raises(ValueError):
37+
Address(("x", "y")) # type: ignore
38+
39+
40+
def test_construct_tuple_too_long():
41+
with pytest.raises(ValueError):
42+
Address((1, 2, 3)) # type: ignore
43+
44+
45+
def test_construct_tuple_too_short():
46+
with pytest.raises(ValueError):
47+
Address((1,)) # type: ignore
48+
49+
2650
def test_construct_string():
2751
addr = Address("130:10")
2852
assert isinstance(addr, Address)
2953
assert addr.client_id == 130
3054
assert addr.port_id == 10
3155

3256

57+
def test_construct_string_bad():
58+
with pytest.raises(ALSAError) as err:
59+
Address("x:y")
60+
assert err.value.errnum == -errno.EINVAL
61+
62+
3363
def test_copy():
3464
addr1 = Address(129, 2)
3565
addr2 = Address(addr1)

0 commit comments

Comments
 (0)