Skip to content

Commit 6e6f63a

Browse files
committed
Fix unit tests
1 parent a9d50d2 commit 6e6f63a

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

tests/test_api.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import asyncio
2-
from unittest.mock import MagicMock, patch, sentinel
2+
from unittest.mock import AsyncMock, MagicMock, patch, sentinel
33

44
import pytest
55
import serial_asyncio
@@ -37,10 +37,13 @@ async def mock_conn(loop, protocol_factory, **kwargs):
3737
await api.connect()
3838

3939

40-
def test_close(api):
40+
@pytest.mark.asyncio
41+
async def test_disconnect(api):
4142
uart = api._uart
42-
api.close()
43-
assert uart.close.call_count == 1
43+
uart.disconnect = AsyncMock()
44+
45+
await api.disconnect()
46+
assert uart.disconnect.call_count == 1
4447
assert api._uart is None
4548

4649

tests/test_application.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,28 +102,28 @@ async def mock_get_network_state():
102102

103103
@pytest.mark.asyncio
104104
async def test_disconnect_success(app):
105-
api = MagicMock()
105+
api = AsyncMock()
106106

107107
app._api = api
108108
await app.disconnect()
109109

110-
api.close.assert_called_once()
110+
api.disconnect.assert_called_once()
111111
assert app._api is None
112112

113113

114114
@pytest.mark.asyncio
115115
async def test_disconnect_failure(app, caplog):
116-
api = MagicMock()
117-
api.disconnect = MagicMock(side_effect=RuntimeError("Broken"))
116+
api = AsyncMock()
117+
api.reset = AsyncMock(side_effect=RuntimeError("Broken"))
118118

119119
app._api = api
120120

121121
with caplog.at_level(logging.WARNING):
122122
await app.disconnect()
123123

124-
assert "disconnect" in caplog.text
124+
assert "Failed to reset before disconnect" in caplog.text
125125

126-
api.close.assert_called_once()
126+
api.disconnect.assert_called_once()
127127
assert app._api is None
128128

129129

tests/test_uart.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,6 @@ def test_escape(gw):
108108
assert r == data_escaped
109109

110110

111-
def test_length(gw):
112-
data = b"\x80\x10\x00\x05\xaa\x00\x0f?\xf0\xff"
113-
length = 5
114-
r = gw._length(data)
115-
assert r == length
116-
117-
118111
def test_checksum(gw):
119112
data = b"\x00\x0f?\xf0"
120113
checksum = 0xAA

0 commit comments

Comments
 (0)