def _get_working_mock_ffmpeg():
    """Return a working ffmpeg."""
    ffmpeg = MagicMock()
    ffmpeg.open = AsyncMock(return_value=True)
    ffmpeg.close = AsyncMock(return_value=True)
    ffmpeg.kill = AsyncMock(return_value=True)
    return ffmpeg
Ejemplo n.º 2
0
def _get_failing_mock_ffmpeg():
    """Return an ffmpeg that fails to shutdown."""
    ffmpeg = MagicMock()
    type(ffmpeg.process).pid = PropertyMock(return_value=PID_THAT_WILL_NEVER_BE_ALIVE)
    ffmpeg.open = AsyncMock(return_value=False)
    ffmpeg.close = AsyncMock(side_effect=OSError)
    ffmpeg.kill = AsyncMock(side_effect=OSError)
    return ffmpeg
Ejemplo n.º 3
0
def _get_exits_after_startup_mock_ffmpeg():
    """Return a ffmpeg that will have an invalid pid."""
    ffmpeg = MagicMock()
    type(ffmpeg.process).pid = PropertyMock(return_value=PID_THAT_WILL_NEVER_BE_ALIVE)
    ffmpeg.open = AsyncMock(return_value=True)
    ffmpeg.close = AsyncMock(return_value=True)
    ffmpeg.kill = AsyncMock(return_value=True)
    return ffmpeg
Ejemplo n.º 4
0
def mock_datagram_client(recv_response):
    """Define a mocked datagram client."""
    mock_datagram_client = MagicMock()
    mock_datagram_client.connect = AsyncMock()
    mock_datagram_client.recv = recv_response
    mock_datagram_client.send = AsyncMock()
    mock_datagram_client.close = MagicMock()

    with patch("asyncio_dgram.connect", return_value=mock_datagram_client):
        yield mock_datagram_client
Ejemplo n.º 5
0
async def test_migration_missing_tables():
    app = MagicMock()
    conn = MagicMock()
    conn.close = AsyncMock()

    appdb = zigpy.appdb.PersistingListener(conn, app)

    appdb._get_table_versions = AsyncMock(return_value={
        "table1_v1": "1",
        "table1": "",
        "table2_v1": "1"
    })

    results = MagicMock()
    results.__aiter__.return_value = results
    results.__anext__.side_effect = StopIteration

    appdb.execute = MagicMock()
    appdb.execute.return_value.__aenter__.return_value = results

    # Migrations must explicitly specify all old tables, even if they will be untouched
    with pytest.raises(RuntimeError):
        await appdb._migrate_tables({
            "table1_v1": "table1_v2",
            # "table2_v1": "table2_v2",
        })

    # The untouched table will never be queried
    await appdb._migrate_tables({"table1_v1": "table1_v2", "table2_v1": None})

    appdb.execute.assert_called_once_with("SELECT * FROM table1_v1")

    with pytest.raises(AssertionError):
        appdb.execute.assert_called_once_with("SELECT * FROM table2_v1")

    await appdb.shutdown()