From 34662fecc9535c7d8d0a8e7d42fafa4b9e005c89 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Mon, 13 Jun 2022 12:55:31 -0400 Subject: tests: Fix with latest argcomplete Signed-off-by: Cole Robinson --- virtinst/cli.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'virtinst') diff --git a/virtinst/cli.py b/virtinst/cli.py index 52be9f29..c42fc0f0 100644 --- a/virtinst/cli.py +++ b/virtinst/cli.py @@ -552,7 +552,15 @@ def autocomplete(parser): kwargs = {"validator": _completer_validator} if xmlutil.in_testsuite(): import io - kwargs["output_stream"] = io.BytesIO() + class MyStream(io.StringIO): + # Custom class to handle both bytes() and str() on write. + # With argcomplete 2.0.0 and/or python3.10 something changed + # here, so this should hopefully cover back compat + def write(self, msg, *args, **kwargs): + if type(msg) is bytes: + msg = msg.decode("utf-8") # pragma: no cover + return super().write(msg, *args, **kwargs) + kwargs["output_stream"] = MyStream() kwargs["exit_method"] = sys.exit # This fdopen hackery is to avoid argcomplete debug_stream behavior @@ -568,7 +576,7 @@ def autocomplete(parser): argcomplete.autocomplete(parser, **kwargs) except SystemExit: if xmlutil.in_testsuite(): - output = kwargs["output_stream"].getvalue().decode("utf-8") + output = kwargs["output_stream"].getvalue() print(output) raise -- cgit v1.2.1