コード例 #1
0
ファイル: conftest.py プロジェクト: tlskinneriv/keymaster
def mock_client_fixture(controller_state, version_state):
    """Mock a client."""

    with patch("homeassistant.components.zwave_js.ZwaveClient",
               autospec=True) as client_class:
        client = client_class.return_value

        async def connect():
            await asyncio.sleep(0)
            client.connected = True

        async def listen(driver_ready: asyncio.Event) -> None:
            driver_ready.set()
            await asyncio.sleep(30)
            assert False, "Listen wasn't canceled!"

        async def disconnect():
            client.connected = False

        client.connect = AsyncMock(side_effect=connect)
        client.listen = AsyncMock(side_effect=listen)
        client.disconnect = AsyncMock(side_effect=disconnect)
        client.driver = Driver(client, controller_state)

        client.version = VersionInfo.from_message(version_state)
        client.ws_server_url = "ws://test:3000/zjs"

        yield client
コード例 #2
0
ファイル: test_config_flow.py プロジェクト: jhofker/core-1
def mock_get_server_version(server_version_side_effect):
    """Mock server version."""
    version_info = VersionInfo(
        driver_version="mock-driver-version",
        server_version="mock-server-version",
        home_id=1234,
    )
    with patch(
            "homeassistant.components.zwave_js.config_flow.get_server_version",
            side_effect=server_version_side_effect,
            return_value=version_info,
    ) as mock_version:
        yield mock_version
コード例 #3
0
def mock_get_server_version(server_version_side_effect,
                            server_version_timeout):
    """Mock server version."""
    version_info = VersionInfo(
        driver_version="mock-driver-version",
        server_version="mock-server-version",
        home_id=1234,
        min_schema_version=0,
        max_schema_version=1,
    )
    with patch(
            "openpeerpower.components.zwave_js.config_flow.get_server_version",
            side_effect=server_version_side_effect,
            return_value=version_info,
    ) as mock_version, patch(
            "openpeerpower.components.zwave_js.config_flow.SERVER_VERSION_TIMEOUT",
            new=server_version_timeout,
    ):
        yield mock_version