mirror of
https://github.com/containers/podman-compose.git
synced 2025-04-22 16:39:01 +02:00
Merge pull request #1140 from whym/rename-comment
Fix comment, add tests, improve coding style
This commit is contained in:
commit
dd01d039bf
@ -1464,10 +1464,8 @@ class Podman:
|
|||||||
chunk = await self._readchunk(reader)
|
chunk = await self._readchunk(reader)
|
||||||
parts = chunk.split(b"\n")
|
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):
|
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:
|
if i < len(parts) - 1:
|
||||||
_formatted_print_with_nl(part.decode())
|
_formatted_print_with_nl(part.decode())
|
||||||
line_ongoing = False
|
line_ongoing = False
|
||||||
@ -1475,7 +1473,8 @@ class Podman:
|
|||||||
_formatted_print_without_nl(part.decode())
|
_formatted_print_without_nl(part.decode())
|
||||||
line_ongoing = True
|
line_ongoing = True
|
||||||
if line_ongoing:
|
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(
|
def exec(
|
||||||
self,
|
self,
|
||||||
|
@ -8,10 +8,10 @@ from podman_compose import Podman
|
|||||||
|
|
||||||
|
|
||||||
class DummyReader:
|
class DummyReader:
|
||||||
def __init__(self, data=[]):
|
def __init__(self, data=None):
|
||||||
self.data = data
|
self.data = data or []
|
||||||
|
|
||||||
async def readuntil(self, x):
|
async def readuntil(self, _):
|
||||||
return self.data.pop(0)
|
return self.data.pop(0)
|
||||||
|
|
||||||
def at_eof(self):
|
def at_eof(self):
|
||||||
@ -28,6 +28,16 @@ class TestComposeRunLogFormat(unittest.IsolatedAsyncioTestCase):
|
|||||||
await self.p._format_stream(reader, self.buffer, 'LL:')
|
await self.p._format_stream(reader, self.buffer, 'LL:')
|
||||||
self.assertEqual(self.buffer.getvalue(), 'LL: hello, world\n')
|
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):
|
async def test_empty_line(self):
|
||||||
reader = DummyReader([b'\n'])
|
reader = DummyReader([b'\n'])
|
||||||
await self.p._format_stream(reader, self.buffer, 'LL:')
|
await self.p._format_stream(reader, self.buffer, 'LL:')
|
||||||
|
Loading…
Reference in New Issue
Block a user