-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Handle non-UTF-8 lines in plugin output for logging (#8399)
* fix: Handle non-UTF-8 lines in plugin output for logging #8377 * Test change --------- Co-authored-by: nKandel <npkand+3070@gmail.com> Co-authored-by: Edgar Ramírez-Mondragón <edgar@meltano.com>
- Loading branch information
1 parent
1c0dd78
commit b06f1ea
Showing
3 changed files
with
37 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from __future__ import annotations | ||
|
||
import asyncio | ||
|
||
import pytest | ||
|
||
from meltano.core.logging.utils import capture_subprocess_output | ||
|
||
|
||
class AsyncReader(asyncio.StreamReader): | ||
def __init__(self, lines: list[bytes]): | ||
self.lines = lines | ||
|
||
def at_eof(self) -> bool: | ||
return not self.lines | ||
|
||
async def readline(self) -> bytes: | ||
return self.lines.pop(0) if self.lines else b"" | ||
|
||
|
||
@pytest.mark.asyncio() | ||
async def test_capture_subprocess_output(): | ||
INPUT_LINES = [b"LINE\n", b"LINE 2\n", b"\xed\n"] | ||
OUTPUT_LINES = [] | ||
|
||
class LineWriter: | ||
def writeline(self, line: str): | ||
OUTPUT_LINES.append(line) | ||
|
||
reader = AsyncReader(INPUT_LINES) | ||
|
||
await capture_subprocess_output(reader, LineWriter()) | ||
assert ["LINE\n", "LINE 2\n", "�\n"] == OUTPUT_LINES |