File: common.py

package info (click to toggle)
python-bellows 0.40.5-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 992 kB
  • sloc: python: 13,630; sh: 7; makefile: 4
file content (15 lines) | stat: -rw-r--r-- 617 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from __future__ import annotations

from unittest.mock import AsyncMock

from bellows.ezsp.protocol import ProtocolHandler


def mock_ezsp_commands(ezsp: ProtocolHandler) -> ProtocolHandler:
    for command_name, (_command_id, tx_schema, _rx_schema) in ezsp.COMMANDS.items():
        # TODO: make this end-to-end instead of relying on this serialization hack
        async def fake_sender(*args, _command_name=command_name, _ezsp=ezsp, **kwargs):
            # Trigger an exception early
            _ezsp._ezsp_frame(_command_name, *args, **kwargs)

        setattr(ezsp, command_name, AsyncMock(wraps=fake_sender))