-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: some tests * fix: potential bug with command task * feat: centralize writing * fix: tests * feat: get signal info * fix: clear command flag on connect * fix: update version
- Loading branch information
1 parent
8a7bb94
commit 0eb5295
Showing
6 changed files
with
240 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ pre-commit | |
mypy | ||
ruff | ||
pydantic | ||
pre-commit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# type: ignore | ||
from unittest.mock import AsyncMock, MagicMock, PropertyMock, patch | ||
|
||
import pytest | ||
|
||
from madvr.madvr import Madvr | ||
|
||
|
||
@pytest.fixture | ||
def mock_madvr(): | ||
with patch("madvr.madvr.asyncio.open_connection", new_callable=AsyncMock), patch( | ||
"madvr.madvr.Madvr.connected", new_callable=PropertyMock, return_value=True | ||
): | ||
madvr = Madvr("192.168.1.100") | ||
# ignore mypy | ||
# | ||
madvr.writer = AsyncMock() | ||
madvr.reader = AsyncMock() | ||
madvr._set_connected = AsyncMock() | ||
madvr._clear_attr = AsyncMock() | ||
madvr.is_device_connectable = AsyncMock() | ||
madvr.close_connection = AsyncMock() | ||
madvr._construct_command = AsyncMock() | ||
madvr._write_with_timeout = AsyncMock() | ||
madvr.stop = MagicMock() | ||
madvr.stop_commands_flag = MagicMock() | ||
madvr.stop_heartbeat = MagicMock() | ||
madvr.add_command_to_queue = AsyncMock() | ||
madvr._reconnect = AsyncMock() | ||
madvr._write_with_timeout = AsyncMock() | ||
|
||
# Mock the background tasks to prevent warnings | ||
madvr.task_handle_queue = AsyncMock() | ||
madvr.task_read_notifications = AsyncMock() | ||
# madvr.send_heartbeat = AsyncMock() | ||
madvr.task_ping_until_alive = AsyncMock() | ||
madvr.task_refresh_info = AsyncMock() | ||
yield madvr | ||
|
||
|
||
@pytest.fixture | ||
def mock_send_magic_packet(): | ||
with patch("madvr.madvr.send_magic_packet") as mock: | ||
yield mock | ||
|
||
|
||
@pytest.fixture | ||
def mock_wait_for(): | ||
async def mock_wait_for_func(coro, timeout): | ||
return await coro | ||
|
||
with patch("asyncio.wait_for", mock_wait_for_func): | ||
yield |
Oops, something went wrong.