Skip to content

Commit d75c148

Browse files
committed
Cover a pipe write that Ctrl-C interrupts before its first chunk
Nothing was written then, so the write raises KeyboardInterrupt at once rather than reporting a partial write.
1 parent 6a28fcf commit d75c148

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

‎tests/test_utils.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -720,12 +720,13 @@ def lend_terminal():
720720

721721

722722
@pytest.mark.skipif(sys.platform == "win32", reason="POSIX pipes")
723-
def test_pipeline_writer_reports_what_it_wrote_before_ctrl_c() -> None:
723+
@pytest.mark.parametrize("interrupted_chunk", [1, 2])
724+
def test_pipeline_writer_reports_what_it_wrote_before_ctrl_c(interrupted_chunk) -> None:
724725
"""Ctrl-C can interrupt a write between two chunks, once some of them are in the pipe already.
725726
726727
BufferedWriter takes an exception to mean that nothing was written, and would send its
727728
whole buffer again as it closes: the consumer would get that output twice. Ctrl-C must
728-
still cancel the command.
729+
still cancel the command. Before the first chunk, nothing was written, and it just does.
729730
"""
730731
import io
731732
import select
@@ -737,8 +738,8 @@ def test_pipeline_writer_reports_what_it_wrote_before_ctrl_c() -> None:
737738

738739
def write(fd, data):
739740
chunks.append(len(data))
740-
if len(chunks) == 2:
741-
# cmd2's SIGINT handler raises as the write goes on to its second chunk.
741+
if len(chunks) == interrupted_chunk:
742+
# cmd2's SIGINT handler raises as the write goes on to this chunk.
742743
raise KeyboardInterrupt
743744
return real_write(fd, data)
744745

0 commit comments

Comments
 (0)