From baccce4f3fba524e7c839363a5fd533dd28d8a03 Mon Sep 17 00:00:00 2001 From: Yusuke Matsubara Date: Tue, 11 Feb 2025 18:30:56 +0900 Subject: [PATCH 1/3] Fix comments related to logging Signed-off-by: Yusuke Matsubara --- podman_compose.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/podman_compose.py b/podman_compose.py index 5a0e138..24e2d41 100755 --- a/podman_compose.py +++ b/podman_compose.py @@ -1464,10 +1464,8 @@ class Podman: chunk = await self._readchunk(reader) parts = chunk.split(b"\n") - # Iff parts ends with '', the last part is a incomplete line; - # The rest are complete lines - for i, part in enumerate(parts): + # Iff part is last and non-empty, we leave an ongoing line to be completed later if i < len(parts) - 1: _formatted_print_with_nl(part.decode()) line_ongoing = False @@ -1475,7 +1473,8 @@ class Podman: _formatted_print_without_nl(part.decode()) line_ongoing = True if line_ongoing: - print(file=sink, end="\n") # End the unfinished line + # Make sure the last line ends with EOL + print(file=sink, end="\n") def exec( self, From c289a3b82757c8bd7d6ad898251809cae26c8879 Mon Sep 17 00:00:00 2001 From: Yusuke Matsubara Date: Tue, 25 Feb 2025 01:38:55 +0200 Subject: [PATCH 2/3] Fix logging test coding style Signed-off-by: Yusuke Matsubara --- tests/unit/test_compose_run_log_format.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit/test_compose_run_log_format.py b/tests/unit/test_compose_run_log_format.py index 878ead6..e63f5be 100644 --- a/tests/unit/test_compose_run_log_format.py +++ b/tests/unit/test_compose_run_log_format.py @@ -8,10 +8,10 @@ from podman_compose import Podman class DummyReader: - def __init__(self, data=[]): - self.data = data + def __init__(self, data=None): + self.data = data or [] - async def readuntil(self, x): + async def readuntil(self, _): return self.data.pop(0) def at_eof(self): From 81a0a5933e8c723faa7910266d76b9e22ee6f761 Mon Sep 17 00:00:00 2001 From: Yusuke Matsubara Date: Tue, 25 Feb 2025 01:39:12 +0200 Subject: [PATCH 3/3] Add more logging tests Signed-off-by: Yusuke Matsubara --- tests/unit/test_compose_run_log_format.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/unit/test_compose_run_log_format.py b/tests/unit/test_compose_run_log_format.py index e63f5be..64871a7 100644 --- a/tests/unit/test_compose_run_log_format.py +++ b/tests/unit/test_compose_run_log_format.py @@ -28,6 +28,16 @@ class TestComposeRunLogFormat(unittest.IsolatedAsyncioTestCase): await self.p._format_stream(reader, self.buffer, 'LL:') self.assertEqual(self.buffer.getvalue(), 'LL: hello, world\n') + async def test_empty(self): + reader = DummyReader([]) + await self.p._format_stream(reader, self.buffer, 'LL:') + self.assertEqual(self.buffer.getvalue(), '') + + async def test_empty2(self): + reader = DummyReader([b'']) + await self.p._format_stream(reader, self.buffer, 'LL:') + self.assertEqual(self.buffer.getvalue(), '') + async def test_empty_line(self): reader = DummyReader([b'\n']) await self.p._format_stream(reader, self.buffer, 'LL:')