-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Raise an exception on end of input in CliRunner #2934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| click.echo(f.name) | ||
|
|
||
| result = runner.invoke(cli) | ||
| result = runner.invoke(cli, input="\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Newline needs to be inputted to simulate user input
|
I think we do want to raise try:
next()
except StopIteration:
raise EOFError |
| def mode(self) -> str: | ||
| return self._mode | ||
|
|
||
| def __next__(self) -> str: # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mypy claims the return type should be bytes because of IOBase but it should be matching with TextIOWrapper
Same issue as python/mypy#9643
e8fd432 to
e4f590e
Compare
26ce633 to
80efdf6
Compare
Description ----------- <!-- Include reference to internal ticket "Fixes WB-NNNNN" and/or GitHub issue "Fixes #NNNN" (if applicable) --> What does the PR do? Include a concise description of the PR contents. This PR fixes consistent test failures related to `wand docker` cli tests. This was caused by an update with our dependency `click` in version `v8.2.1`, which changed the behavior with how the `CliRunner` is handling input when there is a prompt but no more input provided. (see click [issue here](pallets/click#2934), and the [fix here](pallets/click#2934)) <!-- NEW: We're using a new changelog format that's more useful for users. Please see CHANGELOG.unreleased.md for details and update on relevant changes such as feature additions, bug fixes, or removals/deprecations. --> - [ ] I updated CHANGELOG.unreleased.md, or it's not applicable Testing ------- How was this PR tested? - running unit tests for `tests/unit_tests/test_cli.py` <!-- Ensure PR title compliance with the [conventional commits standards](https://github.com/wandb/wandb/blob/main/CONTRIBUTING.md#conventional-commits) -->
Description ----------- <!-- Include reference to internal ticket "Fixes WB-NNNNN" and/or GitHub issue "Fixes #NNNN" (if applicable) --> What does the PR do? Include a concise description of the PR contents. This PR fixes consistent test failures related to `wand docker` cli tests. This was caused by an update with our dependency `click` in version `v8.2.1`, which changed the behavior with how the `CliRunner` is handling input when there is a prompt but no more input provided. (see click [issue here](pallets/click#2934), and the [fix here](pallets/click#2934)) <!-- NEW: We're using a new changelog format that's more useful for users. Please see CHANGELOG.unreleased.md for details and update on relevant changes such as feature additions, bug fixes, or removals/deprecations. --> - [ ] I updated CHANGELOG.unreleased.md, or it's not applicable Testing ------- How was this PR tested? - running unit tests for `tests/unit_tests/test_cli.py` <!-- Ensure PR title compliance with the [conventional commits standards](https://github.com/wandb/wandb/blob/main/CONTRIBUTING.md#conventional-commits) -->
A discrepancy exists between the documentation of `click.prompt` and the actual behavior of `click.prompt` when mocked with `click.testing.CliRunner` on click 8.2.0 and below ([`pallets/click#2934`][BUG2934]): when prompting for input and if at end-of-file, the `CliRunner` may return an empty string instead of raising `click.Abort`. This usually translates to extra line breaks in the "mixed" and "echoed" runner output at the last prompt(s). We mitigate this discrepancy from both sides. On the code side, we wrap each call to `click.prompt` to treat aborts and empty responses the same, which is appropriate behavior for the types of prompts we issue. On the test side, we amend our existing tests to use empty-line input instead of no input, and explicitly test the "no input" scenario separately, accepting both the 8.2.0-or-lower or the 8.2.1-or-higher output. Because the behavior depends on the `click` version, which is beyond our control, we also adjust coverage measurement. [BUG2934]: pallets/click#2934
When end of input is reached in CliRunner,
_NamedTextIOWrapper.readlinecontinues to return an empty string which does not match the behavior when running the program at the command line (in this case an EOFError is raised which causes an Abort to be raised).Using
next()instead ofreadlinewill raiseStopIterationfromTextIOWrapper. If we want to perfectly match the behavior of regular input, we could override__next__to raiseEOFError(this will require a type: ignore due to mypy comparing types withIOBaseinstead ofTextIOWrapper).fixes #2787