Skip to content

Commit

Permalink
Test get length command (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinHjelmare authored Aug 4, 2022
1 parent 48d6e19 commit 0ff5d31
Showing 1 changed file with 58 additions and 2 deletions.
60 changes: 58 additions & 2 deletions tests/model/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,68 @@
import pytest

from aiovlc.client import Client
from aiovlc.exceptions import AuthError, CommandError
from aiovlc.model.command import Info, Password, Status
from aiovlc.exceptions import AuthError, CommandError, CommandParseError
from aiovlc.model.command import GetLength, Info, Password, Status

# pylint: disable=unused-argument


@pytest.mark.parametrize(
"read, length",
[(b"372\r\n> ", 372), (b"\r\n> ", 0)],
)
async def test_get_length(
transport: tuple[AsyncMock, AsyncMock],
client_connected: Client,
read: list[bytes],
length: int,
) -> None:
"""Test the get length command."""
mock_reader, mock_writer = transport
mock_reader.readuntil.return_value = read

command = GetLength()
output = await command.send(client_connected)

assert mock_writer.write.call_count == 1
assert mock_writer.write.call_args == call(b"get_length\n")
assert mock_reader.readuntil.call_count == 1
assert output
assert output.length == length


@pytest.mark.parametrize(
"read, error, error_message",
[
(b"> ", CommandParseError, "Could not get length."),
(
b"unexpected\r\n> ",
CommandParseError,
"Could not get length.",
),
],
)
async def test_get_length_error(
transport: tuple[AsyncMock, AsyncMock],
client_connected: Client,
read: list[bytes],
error: Type[Exception],
error_message: str,
) -> None:
"""Test the get length command errors."""
mock_reader, mock_writer = transport
mock_reader.readuntil.return_value = read

command = GetLength()
with pytest.raises(error) as err:
await command.send(client_connected)

assert str(err.value) == error_message
assert mock_writer.write.call_count == 1
assert mock_writer.write.call_args == call(b"get_length\n")
assert mock_reader.readuntil.call_count == 1


async def test_info_command(
transport: tuple[AsyncMock, AsyncMock],
client_connected: Client,
Expand Down

0 comments on commit 0ff5d31

Please sign in to comment.