Skip to content

Commit

Permalink
Test info command (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinHjelmare authored Aug 4, 2022
1 parent 26d88b4 commit 48d6e19
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
2 changes: 1 addition & 1 deletion aiovlc/model/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def parse_output(self, output: list[str]) -> InfoOutput:
value = value.strip() # type: ignore[union-attr]
data[section][key.strip()] = value
else:
raise CommandParseError("Unexpected line in info output")
raise CommandParseError(f"Unexpected line in info output: {line}")
return InfoOutput(data=data)


Expand Down
65 changes: 63 additions & 2 deletions tests/model/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,72 @@

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

# pylint: disable=unused-argument


async def test_info_command(
transport: tuple[AsyncMock, AsyncMock],
client_connected: Client,
) -> None:
"""Test the info command."""
mock_reader, mock_writer = transport
mock_reader.readuntil.return_value = (
b"+----[ Meta data ]\r\n"
b"|\r\n"
b"| filename: test_song.mp3\r\n"
b"|\r\n"
b"+----[ Stream 0 ]\r\n"
b"|\r\n"
b"| Channels: Stereo\r\n"
b"| Codec: MPEG Audio layer 1/2 (mpga)\r\n"
b"| Bits per sample: 32\r\n"
b"| Type: Audio\r\n"
b"| Sample rate: 44100 Hz\r\n"
b"|\r\n"
b"+----[ end of stream info ]\r\n"
b"> "
)

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

assert mock_writer.write.call_count == 1
assert mock_writer.write.call_args == call(b"info\n")
assert mock_reader.readuntil.call_count == 1
assert output
assert output.data == {
0: {
"Bits per sample": 32,
"Channels": "Stereo",
"Codec": "MPEG Audio layer 1/2 (mpga)",
"Sample rate": "44100 Hz",
"Type": "Audio",
},
"data": {"filename": "test_song.mp3"},
}


async def test_info_command_error(
transport: tuple[AsyncMock, AsyncMock],
client_connected: Client,
) -> None:
"""Test the info command error."""
mock_reader, mock_writer = transport
mock_reader.readuntil.return_value = b"unexpected\r\n" b"> "

command = Info()
with pytest.raises(CommandError) as err:
await command.send(client_connected)

assert str(err.value) == "Unexpected line in info output: unexpected"

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


@pytest.mark.parametrize(
"read, read_call_count",
[([b"Welcome, Master\r\n", b"> "], 4), ([b"Welcome, Master> \r\n"], 3)],
Expand Down Expand Up @@ -61,7 +122,7 @@ async def test_password_command_error(
error: Type[Exception],
error_message: str,
) -> None:
"""Test the password command."""
"""Test the password command errors."""
password = "test-password"
mock_reader, mock_writer = transport
mock_reader.readuntil.side_effect = [
Expand Down

0 comments on commit 48d6e19

Please sign in to comment.