Skip to content
Myr

Raise an exception on end of input in CliRunner

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by kyu243 · committed by David Lord · parent cfa6f4a · Browse files · 5 files+27 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+27 added−6 removed

  • tests:+17 added−4 removed
  • other:+10 added−2 removed

5 files+27 added−6 removed

modified:src/click/testing.py+9 added-2 removed
114 unmodified lines
115 @property116 def mode(self) -> str:117 return self._mode118119 def __next__(self) -> str: # type: ignore120 try:121 line = super().__next__()122 except StopIteration as e:123 raise EOFError() from e124 return line125126127def make_input_stream(128 input: str | bytes | t.IO[t.Any] | None, charset: str129) -> t.BinaryIO:130 # Is already an input stream.
216 unmodified lines
347348 @_pause_echo(echo_input) # type: ignore349 def visible_input(prompt: str | None = None) -> str:350 sys.stdout.write(prompt or "")344 val = text_input.readline().rstrip("\r\n")351 val = next(text_input).rstrip("\r\n")352 sys.stdout.write(f"{val}\n")353 sys.stdout.flush()354 return val355356 @_pause_echo(echo_input) # type: ignore357 def hidden_input(prompt: str | None = None) -> str:358 sys.stdout.write(f"{prompt or ''}\n")359 sys.stdout.flush()353 return text_input.readline().rstrip("\r\n")360 return next(text_input).rstrip("\r\n")361362 @_pause_echo(echo_input) # type: ignore363 def _getchar(echo: bool) -> str:364 char = sys.stdin.read(1)
201 unmodified lines
modified:tests/test_chain.py+2 added-2 removed
161 unmodified lines
162163 return processor164165 result = runner.invoke(cli, args, input=input)166 assert not result.exception167 assert result.output.splitlines() == expect166 # last two lines are '' and 'Aborted!'167 assert result.output.splitlines()[:-2] == expect168169170def test_args_and_chain(runner):171 @click.group(chain=True)
74 unmodified lines
modified:tests/test_termui.py+2 added-2 removed
240 unmodified lines
241 @click.option("-f", default=__file__, prompt="file", type=click.File(**file_kwargs))242 def cli(f):243 click.echo(f.name)244245 result = runner.invoke(cli)245 result = runner.invoke(cli, input="\n")246 assert result.output == f"file [{__file__}]: \n{__file__}\n"247248249def test_secho(runner):
200 unmodified lines
450 ("prompt", "input", "default", "expect"),451 [452 (True, "password\npassword", None, "password"),453 ("Confirm Password", "password\npassword\n", None, "password"),454 (True, "", "", ""),454 (True, "\n\n", "", ""),455 (False, None, None, None),456 ],457)458def test_confirmation_prompt(runner, prompt, input, default, expect):
29 unmodified lines
modified:tests/test_utils.py+13 added
177 unmodified lines
178 out, err = capsys.readouterr()179 assert out == "Password:\ninterrupted\n"180181182def test_prompts_eof(runner):183 """If too few lines of input are given, prompt should exit, not hang."""184185 @click.command186 def echo():187 for _ in range(3):188 click.echo(click.prompt("", type=int))189190 # only provide two lines of input for three prompts191 result = runner.invoke(echo, input="1\n2\n")192 assert result.exit_code == 1193194195def _test_gen_func():196 yield "a"197 yield "b"198 yield "c"
473 unmodified lines
modified:CHANGES.rst+1 added
5 unmodified lines
6- Fix flag value handling for flag options with a provided type. :issue:`2894`7 :issue:`2897` :pr:`2930`8- Fix shell completion for nested groups. :issue:`2906` :pr:`2907`9- Flush ``sys.stderr`` at the end of ``CliRunner.invoke``. :issue:`2682`10- Fix EOF handling for stdin input in CliRunner. :issue:`2787`1112Version 8.2.013-------------14
1231 unmodified lines