Skip to content

Commit 6059e68

Browse files
committed
fix(logfiles): handle incomplete lines without preserving endings
- Changed splitlines(keepends=True) to splitlines(keepends=False) - Updated logic to handle incomplete lines at the end of chunks
1 parent 41fec36 commit 6059e68

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

cardano_node_tests/utils/logfiles.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,10 @@ def _search_log_lines( # noqa: C901
222222
# Prepend any leftover from the last chunk
223223
if incomplete_line:
224224
chunk = incomplete_line + chunk
225-
lines = chunk.splitlines(keepends=True) # Preserve line endings
225+
lines = chunk.splitlines(keepends=False)
226226

227-
# Check if the last line is incomplete
228-
incomplete_line = lines.pop() if not lines[-1].endswith(("\n", "\r")) else ""
227+
# Handle incomplete lines at the end of the chunk
228+
incomplete_line = lines.pop() if chunk[-1] not in "\n\r" else ""
229229

230230
for line in lines:
231231
look_back_buf.append(line)
@@ -318,10 +318,10 @@ def find_msgs_in_logs(
318318
# Prepend any leftover from the last chunk
319319
if incomplete_line:
320320
chunk = incomplete_line + chunk
321-
lines = chunk.splitlines(keepends=True) # Preserve line endings
321+
lines = chunk.splitlines(keepends=False)
322322

323-
# Check if the last line is incomplete
324-
incomplete_line = lines.pop() if not lines[-1].endswith(("\n", "\r")) else ""
323+
# Handle incomplete lines at the end of the chunk
324+
incomplete_line = lines.pop() if chunk[-1] not in "\n\r" else ""
325325

326326
for line in lines:
327327
if regex_comp.search(line):
@@ -373,12 +373,10 @@ def check_msgs_presence_in_logs( # noqa: C901
373373
# Prepend any leftover from the last chunk
374374
if incomplete_line:
375375
chunk = incomplete_line + chunk
376-
lines = chunk.splitlines(keepends=True) # Preserve line endings
376+
lines = chunk.splitlines(keepends=False)
377377

378-
# Check if the last line is incomplete
379-
incomplete_line = (
380-
lines.pop() if not lines[-1].endswith(("\n", "\r")) else ""
381-
)
378+
# Handle incomplete lines at the end of the chunk
379+
incomplete_line = lines.pop() if chunk[-1] not in "\n\r" else ""
382380

383381
for line in lines:
384382
if regex_comp.search(line):

0 commit comments

Comments
 (0)