Allow for custom stdout/stderr/stdin streams when instantiating a Command.

Review Request #12242 — Created April 20, 2022 and submitted

Information

RBTools
release-3.x

Reviewers

Command now takes stdout, stderr, and stdin arguments. These are
expected, in the case of custom streams, to be io.TextIOWrapper
instances, wrapping a io.BytesIO.

The standard and JSON output wrappers on Command instances will wrap
these instead of assuming the versions on sys. The log stream will
wrap stderr as well (it normally defaults to sys.stderr), ensuring
that all logs are, by default, outputted to that stream. This can, as
always, be overridden with a more explicit logging setup if automating
RBTools.

There's also *_is_atty attributes computed for each of these streams
when instantiating. These replace the previous .isatty() checks, and
are more robust, handling the case where this attribute is missing.

This will be used for unit tests that need to capture command output or
simulate input.

Tested running RBTools commands on Python 2, 3.6, and 3.10. Checked
default stdout, stderr, and stdin functionality.

Made use of this in upcoming unit test support. Verified that I could
override the streams successfully on all supported versions of Python
and grab the resulting output (or supply the resulting input).

Summary ID
Allow for custom stdout/stderr/stdin streams when instantiating a Command.
`Command` now takes `stdout`, `stderr`, and `stdin` arguments. These are expected, in the case of custom streams, to be `io.TextIOWrapper` instances, wrapping a `io.BytesIO`. The standard and JSON output wrappers on `Command` instances will wrap these instead of assuming the versions on `sys`. The log stream will wrap `stderr` as well (it normally defaults to `sys.stderr`), ensuring that all logs are, by default, outputted to that stream. This can, as always, be overridden with a more explicit logging setup if automating RBTools. There's also `*_is_atty` attributes computed for each of these streams when instantiating. These replace the previous `.isatty()` checks, and are more robust, handling the case where this attribute is missing. This will be used for unit tests that need to capture command output or simulate input.
1891eb211adc0b85e90840c1e890dcc133ddee54
david
  1. Ship It!
  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to release-3.x (d79b794)