File: common.py

package info (click to toggle)
zwave-js-server-python 0.67.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,820 kB
  • sloc: python: 15,886; sh: 21; javascript: 16; makefile: 2
file content (26 lines) | stat: -rw-r--r-- 756 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""Common methods for tests."""

import asyncio
from typing import Protocol
from unittest.mock import AsyncMock


class MockCommandProtocol(Protocol):
    """Represent the function signature of the mock_command callable."""

    def __call__(
        self, command: dict, response: dict, success: bool = True
    ) -> list[dict]:
        """Represent the signature of the mock_command callable."""


def update_ws_client_msg_queue(fixture, new_messages):
    """Update a ws client fixture with a new message queue."""
    to_receive = asyncio.Queue()
    for message in new_messages:
        to_receive.put_nowait(message)

    async def receive_json():
        return await to_receive.get()

    fixture.receive_json = AsyncMock(side_effect=receive_json)