Skip to content

Commit 2a0e3ba

Browse files
authored
testing/CliRunner: Fix regression related to EOF introduced in 262bdf0 (#2940)
2 parents 36deba8 + e11a1ef commit 2a0e3ba

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Unreleased
2424
- Lazily import ``shutil``. :pr:`3023`
2525
- Properly forward exception information to resources registered with
2626
``click.core.Context.with_resource()``. :issue:`2447` :pr:`3058`
27+
- Fix regression related to EOF handling in CliRunner. :issue:`2939`:pr:`2940`
2728

2829
Version 8.2.2
2930
-------------

src/click/testing.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,6 @@ def name(self) -> str:
127127
def mode(self) -> str:
128128
return self._mode
129129

130-
def __next__(self) -> str: # type: ignore
131-
try:
132-
line = super().__next__()
133-
except StopIteration as e:
134-
raise EOFError() from e
135-
return line
136-
137130

138131
def make_input_stream(
139132
input: str | bytes | t.IO[t.Any] | None, charset: str
@@ -359,7 +352,10 @@ def isolation(
359352
@_pause_echo(echo_input) # type: ignore
360353
def visible_input(prompt: str | None = None) -> str:
361354
sys.stdout.write(prompt or "")
362-
val = next(text_input).rstrip("\r\n")
355+
try:
356+
val = next(text_input).rstrip("\r\n")
357+
except StopIteration as e:
358+
raise EOFError() from e
363359
sys.stdout.write(f"{val}\n")
364360
sys.stdout.flush()
365361
return val
@@ -368,7 +364,10 @@ def visible_input(prompt: str | None = None) -> str:
368364
def hidden_input(prompt: str | None = None) -> str:
369365
sys.stdout.write(f"{prompt or ''}\n")
370366
sys.stdout.flush()
371-
return next(text_input).rstrip("\r\n")
367+
try:
368+
return next(text_input).rstrip("\r\n")
369+
except StopIteration as e:
370+
raise EOFError() from e
372371

373372
@_pause_echo(echo_input) # type: ignore
374373
def _getchar(echo: bool) -> str:

tests/test_chain.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ def processor(iterator):
163163
return processor
164164

165165
result = runner.invoke(cli, args, input=input)
166-
# last two lines are '' and 'Aborted!'
167-
assert result.output.splitlines()[:-2] == expect
166+
assert not result.exception
167+
assert result.output.splitlines() == expect
168168

169169

170170
def test_args_and_chain(runner):

0 commit comments

Comments
 (0)