Skip to content

Commit

Permalink
Update tests for full coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
lamr02n committed Nov 4, 2024
1 parent cb28048 commit 340866a
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ async def test_send_logline_no_logline(self):

class TestReceiveLogline(unittest.IsolatedAsyncioTestCase):
@patch("src.logserver.server.logger")
async def test_receive_one_logline(self, mock_logger):
async def test_receive_logline(self, mock_logger):
reader = AsyncMock()
data_queue = MagicMock()
server_instance = LogServer()
Expand All @@ -364,6 +364,45 @@ async def test_receive_one_logline(self, mock_logger):

self.assertEqual(data_queue.put.call_count, 2)

@patch("src.logserver.server.logger")
async def test_receive_without_separator(self, mock_logger):
reader = AsyncMock()
data_queue = MagicMock()
server_instance = LogServer()
server_instance.data_queue = data_queue

reader.readuntil = AsyncMock(
side_effect=asyncio.exceptions.IncompleteReadError(b"", 100)
)

# noinspection PyAsyncCall
asyncio.create_task(server_instance.receive_logline(reader))

@patch("src.logserver.server.logger")
async def test_receive_too_long(self, mock_logger):
reader = AsyncMock()
data_queue = MagicMock()
server_instance = LogServer()
server_instance.data_queue = data_queue

reader.readuntil = AsyncMock(side_effect=asyncio.LimitOverrunError("", 1))

# noinspection PyAsyncCall
asyncio.create_task(server_instance.receive_logline(reader))

@patch("src.logserver.server.logger")
async def test_receive_raise_other_exception(self, mock_logger):
reader = AsyncMock()
data_queue = MagicMock()
server_instance = LogServer()
server_instance.data_queue = data_queue

reader.readuntil = AsyncMock(side_effect=ValueError("Something went wrong"))

with self.assertRaises(ValueError):
task = asyncio.create_task(server_instance.receive_logline(reader))
await task


class TestGetNextLogline(unittest.TestCase):
def test_valid(self):
Expand Down

0 comments on commit 340866a

Please sign in to comment.