diff options
author | Cole Robinson <crobinso@redhat.com> | 2022-06-13 12:55:31 -0400 |
---|---|---|
committer | Cole Robinson <crobinso@redhat.com> | 2022-06-13 13:20:01 -0400 |
commit | 34662fecc9535c7d8d0a8e7d42fafa4b9e005c89 (patch) | |
tree | a30074f7926f18729dfe7d5ce608fe99eaf5dd1b /virtinst | |
parent | ddead32287a807450054a80e382558da7f904890 (diff) | |
download | virt-manager-34662fecc9535c7d8d0a8e7d42fafa4b9e005c89.tar.gz |
tests: Fix with latest argcomplete
Signed-off-by: Cole Robinson <crobinso@redhat.com>
Diffstat (limited to 'virtinst')
-rw-r--r-- | virtinst/cli.py | 12 |
1 files changed, 10 insertions, 2 deletions
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 |