Skip to content

Commit

Permalink
Test get time command (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinHjelmare authored Aug 4, 2022
1 parent 5a52acd commit 48e8bb3
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/model/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,60 @@ async def test_get_length_error(
assert mock_reader.readuntil.call_count == 1


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

output = await client_connected.get_time()

assert mock_writer.write.call_count == 1
assert mock_writer.write.call_args == call(b"get_time\n")
assert mock_reader.readuntil.call_count == 1
assert output
assert output.time == time_result


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

with pytest.raises(error) as err:
await client_connected.get_time()

assert str(err.value) == error_message
assert mock_writer.write.call_count == 1
assert mock_writer.write.call_args == call(b"get_time\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 48e8bb3

Please sign in to comment.