Skip to content

Commit d2fd5e7

Browse files
authored
Add a test case to handle partial characters at the end
1 parent dc31427 commit d2fd5e7

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

tests/runners.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ def _runner(out="", err="", **kwargs):
7070
runner = klass(Context(config=Config(overrides=kwargs)))
7171
if "exits" in kwargs:
7272
runner.returncode = Mock(return_value=kwargs.pop("exits"))
73-
out_file = BytesIO(out.encode())
74-
err_file = BytesIO(err.encode())
73+
out_file = BytesIO(out.encode() if isinstance(out, str) else out)
74+
err_file = BytesIO(err.encode() if isinstance(err, str) else err)
7575
runner.read_proc_stdout = out_file.read
7676
runner.read_proc_stderr = err_file.read
7777
return runner
@@ -549,6 +549,13 @@ def handles_incremental_decoding(self):
549549
runner.run(_, out_stream=out)
550550
assert out.getvalue() == expected_out
551551

552+
def handles_trailing_partial_character(self):
553+
out = StringIO()
554+
# Only output the first 3 out of the 4 bytes in 𠜎
555+
self._runner(out=b"\xf0\xa0\x9c").run(_, out_stream=out)
556+
# Should produce a single unicode replacement character
557+
assert out.getvalue() == "�"
558+
552559
class input_stream_handling:
553560
# NOTE: actual autoresponder tests are elsewhere. These just test that
554561
# stdin works normally & can be overridden.

0 commit comments

Comments
 (0)