Add stderr/stdin stream control for console utilities.
Review Request #12246 — Created April 21, 2022 and submitted
This adds
stderr
andstdin
control forget_input()
,get_pass()
,
confirm()
, andconfirm_select()
utilities. When hooked up properly,
this enables unit tests to automate code paths that require user input.If
stdin
is a TTY, these will prompt the user for input as normal.
Otherwise, they'll read a line fromstdin
. This allows for scripting
inputs.While here, a few additional tweaks were made to these very old
utilities:
-
confirm()
no longer uses a private method indistutils
to check
for Yes/No input strings. Instead, the checks are now under our
control. -
confirm()
andconfirm_select()
now show bad user input in quotes.
Unit tests were also added for all these functions.
Unit tests pass.
Summary | ID |
---|---|
7466ee80285d0ccac2482267f449e6baf0714927 |
Description | From | Last Updated |
---|---|---|
I need to spend a little more time thinking about how this interacts with things like piping a diff filename... … |
chipx86 |
-
-
I need to spend a little more time thinking about how this interacts with things like piping a diff filename... There wouldn't be anything to read after consuming the diff (assuming we read it before invoking any of these commands), and we could then infinite loop on some of these...
This isn't necessarily a blocker for the other work I have in progress. I'll mull it over.
- Change Summary:
-
Fixed the prompt string type on all versions of Python.
We now cast to Unicode for writing. Tested in unit tests and with manual invocation on all versions.
Python 3 was using Unicode already. Python 2 auto-casts string types.
- Commits:
-
Summary ID f8d7b89870f3173c69fa858f0a97106a4ed93cc0 7466ee80285d0ccac2482267f449e6baf0714927