|
1 | 1 | import asyncio
|
2 |
| - |
| 2 | +import sys |
3 | 3 | import pytest
|
4 | 4 | import serial
|
5 | 5 | import serial_asyncio
|
|
12 | 12 | DEVICE_CONFIG = config.SCHEMA_DEVICE({config.CONF_DEVICE_PATH: "/dev/null"})
|
13 | 13 |
|
14 | 14 |
|
| 15 | + |
15 | 16 | @pytest.fixture
|
16 | 17 | def api():
|
17 | 18 | api = zigate_api.ZiGate(DEVICE_CONFIG)
|
@@ -58,17 +59,26 @@ async def test_api_new(conn_mck):
|
58 | 59 |
|
59 | 60 | @pytest.mark.asyncio
|
60 | 61 | @patch.object(zigate_api.ZiGate, "set_raw_mode", new_callable=AsyncMock)
|
61 |
| -@patch.object(zigpy_zigate.uart, "connect") |
62 |
| -async def test_probe_success(mock_connect, mock_raw_mode): |
| 62 | +@pytest.mark.parametrize( |
| 63 | + "port", |
| 64 | + ('/dev/null', 'pizigate:/dev/ttyAMA0'), |
| 65 | +) |
| 66 | +async def test_probe_success(mock_raw_mode, port, monkeypatch): |
63 | 67 | """Test device probing."""
|
64 | 68 |
|
| 69 | + async def mock_conn(loop, protocol_factory, **kwargs): |
| 70 | + protocol = protocol_factory() |
| 71 | + loop.call_soon(protocol.connection_made, None) |
| 72 | + return None, protocol |
| 73 | + monkeypatch.setattr(serial_asyncio, "create_serial_connection", mock_conn) |
| 74 | + DEVICE_CONFIG = zigpy_zigate.config.SCHEMA_DEVICE( |
| 75 | + {zigpy_zigate.config.CONF_DEVICE_PATH: port} |
| 76 | + ) |
| 77 | + sys.modules['RPi'] = MagicMock() |
| 78 | + sys.modules['RPi.GPIO'] = MagicMock() |
65 | 79 | res = await zigate_api.ZiGate.probe(DEVICE_CONFIG)
|
66 | 80 | assert res is True
|
67 |
| - assert mock_connect.call_count == 1 |
68 |
| - assert mock_connect.await_count == 1 |
69 |
| - assert mock_connect.call_args[0][0] == DEVICE_CONFIG |
70 | 81 | assert mock_raw_mode.call_count == 1
|
71 |
| - assert mock_connect.return_value.close.call_count == 1 |
72 | 82 |
|
73 | 83 |
|
74 | 84 | @pytest.mark.asyncio
|
|
0 commit comments