-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_exec_notebook.py
More file actions
705 lines (596 loc) · 25 KB
/
Copy pathtest_exec_notebook.py
File metadata and controls
705 lines (596 loc) · 25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
"""Tests for notebook execution via _exec_notebook."""
from pathlib import Path
from unittest.mock import patch
import nbformat
import pytest
from click.testing import CliRunner
from nbformat.v4 import new_code_cell, new_markdown_cell, new_notebook
from nbexec import protocol as proto
from nbexec.cli.exec_cmd import exec_code
def _make_notebook(cells, path):
"""Create a .ipynb file with the given cells at path."""
nb = new_notebook()
nb.cells = cells
with open(path, "w") as f:
nbformat.write(nb, f)
def _make_daemon_response(text="", status="ok", execution_count=1, outputs=None):
"""Create a fake daemon response dict."""
if outputs is None:
outputs = []
if text:
outputs.append({"output_type": "stream", "name": "stdout", "text": text})
return {
"status": status,
"execution_count": execution_count,
"cell_index": 0,
"outputs": outputs,
"text": text,
}
def _read_output_notebook(path):
"""Read and return a notebook from path."""
with open(path) as f:
return nbformat.read(f, as_version=4)
class TestExecNotebook:
"""Test executing .ipynb files through the CLI."""
def test_basic_notebook_execution(self, tmp_path):
"""Execute a notebook with two code cells, both succeed."""
nb_path = tmp_path / "test.ipynb"
_make_notebook(
[
new_code_cell(source="print('hello')"),
new_code_cell(source="print('world')"),
],
nb_path,
)
call_count = 0
def fake_send(method, params, timeout=None):
nonlocal call_count
call_count += 1
return _make_daemon_response(
text=f"cell{call_count}\n", execution_count=call_count
)
runner = CliRunner()
with patch("nbexec.cli.exec_cmd.send_to_daemon", side_effect=fake_send):
result = runner.invoke(
exec_code,
["--session", "test-session", "--file", str(nb_path)],
)
assert result.exit_code == 0
assert call_count == 2
assert "cell1" in result.output
assert "cell2" in result.output
def test_notebook_skips_markdown_and_empty_cells(self, tmp_path):
"""Only non-empty code cells are executed."""
nb_path = tmp_path / "test.ipynb"
_make_notebook(
[
new_markdown_cell(source="# Title"),
new_code_cell(source=""),
new_code_cell(source=" "),
new_code_cell(source="x = 1"),
],
nb_path,
)
call_count = 0
def fake_send(method, params, timeout=None):
nonlocal call_count
call_count += 1
return _make_daemon_response(text="ok\n")
runner = CliRunner()
with patch("nbexec.cli.exec_cmd.send_to_daemon", side_effect=fake_send):
result = runner.invoke(
exec_code,
["--session", "s", "--file", str(nb_path)],
)
assert result.exit_code == 0
assert call_count == 1
def test_notebook_stops_on_error(self, tmp_path):
"""Execution stops at the first failing cell."""
nb_path = tmp_path / "test.ipynb"
_make_notebook(
[
new_code_cell(source="good()"),
new_code_cell(source="bad()"),
new_code_cell(source="never_reached()"),
],
nb_path,
)
call_count = 0
def fake_send(method, params, timeout=None):
nonlocal call_count
call_count += 1
if call_count == 2:
return _make_daemon_response(text="NameError", status="error")
return _make_daemon_response(text="ok\n")
runner = CliRunner()
with patch("nbexec.cli.exec_cmd.send_to_daemon", side_effect=fake_send):
result = runner.invoke(
exec_code,
["--session", "s", "--file", str(nb_path)],
)
assert result.exit_code == 1
assert call_count == 2
def test_notebook_progress_markers(self, tmp_path):
"""Progress markers like '--- cell 1/3 ---' are printed."""
nb_path = tmp_path / "test.ipynb"
_make_notebook(
[
new_code_cell(source="a = 1"),
new_code_cell(source="b = 2"),
new_code_cell(source="c = 3"),
],
nb_path,
)
def fake_send(method, params, timeout=None):
return _make_daemon_response(text="")
runner = CliRunner()
with patch("nbexec.cli.exec_cmd.send_to_daemon", side_effect=fake_send):
result = runner.invoke(
exec_code,
["--session", "s", "--file", str(nb_path)],
)
assert result.exit_code == 0
assert "--- cell 1/3 ---" in result.output
assert "--- cell 2/3 ---" in result.output
assert "--- cell 3/3 ---" in result.output
def test_notebook_from_cell_to_cell(self, tmp_path):
"""--from-cell and --to-cell select a range of code cells."""
nb_path = tmp_path / "test.ipynb"
_make_notebook(
[
new_code_cell(source="cell_1()"),
new_code_cell(source="cell_2()"),
new_code_cell(source="cell_3()"),
new_code_cell(source="cell_4()"),
],
nb_path,
)
executed_code = []
def fake_send(method, params, timeout=None):
executed_code.append(params["code"])
return _make_daemon_response(text="ok\n")
runner = CliRunner()
with patch("nbexec.cli.exec_cmd.send_to_daemon", side_effect=fake_send):
result = runner.invoke(
exec_code,
[
"--session", "s",
"--file", str(nb_path),
"--from-cell", "2",
"--to-cell", "3",
],
)
assert result.exit_code == 0
assert executed_code == ["cell_2()", "cell_3()"]
def test_notebook_no_code_cells(self, tmp_path):
"""Notebook with only markdown cells fails gracefully."""
nb_path = tmp_path / "test.ipynb"
_make_notebook(
[new_markdown_cell(source="# Just a title")],
nb_path,
)
runner = CliRunner()
with patch("nbexec.cli.exec_cmd.send_to_daemon"):
result = runner.invoke(
exec_code,
["--session", "s", "--file", str(nb_path)],
)
assert result.exit_code == 1
assert "No code cells" in result.output
def test_cell_range_flags_rejected_for_non_notebook(self, tmp_path):
"""--from-cell / --to-cell only allowed with .ipynb files."""
py_path = tmp_path / "script.py"
py_path.write_text("x = 1\n")
runner = CliRunner()
with patch("nbexec.cli.exec_cmd.send_to_daemon"):
result = runner.invoke(
exec_code,
[
"--session", "s",
"--file", str(py_path),
"--from-cell", "1",
],
)
assert result.exit_code == 1
assert "--from-cell" in result.output
def test_notebook_captures_multiline_output(self, tmp_path):
"""Verify multi-line output from cells is captured correctly."""
nb_path = tmp_path / "test.ipynb"
_make_notebook(
[new_code_cell(source="for i in range(3): print(i)")],
nb_path,
)
def fake_send(method, params, timeout=None):
return _make_daemon_response(text="0\n1\n2\n")
runner = CliRunner()
with patch("nbexec.cli.exec_cmd.send_to_daemon", side_effect=fake_send):
result = runner.invoke(
exec_code,
["--session", "s", "--file", str(nb_path)],
)
assert result.exit_code == 0
assert "0\n1\n2" in result.output
class TestOutputNotebook:
"""Test the --output flag for writing executed notebooks."""
def test_full_run_explicit_output(self, tmp_path):
"""Full run with --output writes executed notebook to that path."""
nb_path = tmp_path / "input.ipynb"
out_path = tmp_path / "output.ipynb"
_make_notebook(
[
new_code_cell(source="print('hello')"),
new_code_cell(source="1 + 1"),
],
nb_path,
)
call_count = 0
def fake_send(method, params, timeout=None):
nonlocal call_count
call_count += 1
if call_count == 1:
return _make_daemon_response(
text="hello\n", execution_count=1,
outputs=[{"output_type": "stream", "name": "stdout", "text": "hello\n"}],
)
return _make_daemon_response(
text="2", execution_count=2,
outputs=[{"output_type": "execute_result", "data": {"text/plain": "2"}, "metadata": {}}],
)
runner = CliRunner()
with patch("nbexec.cli.exec_cmd.send_to_daemon", side_effect=fake_send):
result = runner.invoke(
exec_code,
["--session", "s", "--file", str(nb_path), "--output", str(out_path)],
)
assert result.exit_code == 0
assert out_path.exists()
out_nb = _read_output_notebook(out_path)
# Both cells should have outputs
code_cells = [c for c in out_nb.cells if c.cell_type == "code"]
assert len(code_cells) == 2
assert len(code_cells[0].outputs) == 1
assert code_cells[0].outputs[0].output_type == "stream"
assert code_cells[0].outputs[0].text == "hello\n"
assert code_cells[1].outputs[0].output_type == "execute_result"
assert code_cells[1].execution_count == 2
# stderr reports the output path
assert "Output notebook:" in result.output
def test_full_run_auto_output(self, tmp_path):
"""Full run without --output auto-generates <input>_out.ipynb."""
nb_path = tmp_path / "analysis.ipynb"
_make_notebook([new_code_cell(source="x = 1")], nb_path)
def fake_send(method, params, timeout=None):
return _make_daemon_response(text="", execution_count=1)
runner = CliRunner()
with patch("nbexec.cli.exec_cmd.send_to_daemon", side_effect=fake_send):
result = runner.invoke(
exec_code,
["--session", "s", "--file", str(nb_path)],
)
assert result.exit_code == 0
auto_path = tmp_path / "analysis_out.ipynb"
assert auto_path.exists()
assert str(auto_path) in result.output
def test_partial_run_no_output_flag(self, tmp_path):
"""Partial run without --output does NOT write an output notebook."""
nb_path = tmp_path / "test.ipynb"
_make_notebook(
[new_code_cell(source="a = 1"), new_code_cell(source="b = 2")],
nb_path,
)
def fake_send(method, params, timeout=None):
return _make_daemon_response(text="ok\n")
runner = CliRunner()
with patch("nbexec.cli.exec_cmd.send_to_daemon", side_effect=fake_send):
result = runner.invoke(
exec_code,
["--session", "s", "--file", str(nb_path), "--from-cell", "1", "--to-cell", "1"],
)
assert result.exit_code == 0
# No output notebook created
assert not (tmp_path / "test_out.ipynb").exists()
assert "Output notebook:" not in result.output
def test_partial_run_with_output(self, tmp_path):
"""Partial run with --output writes only the executed cells' outputs."""
nb_path = tmp_path / "test.ipynb"
out_path = tmp_path / "out.ipynb"
_make_notebook(
[
new_code_cell(source="a = 1"),
new_code_cell(source="b = 2"),
new_code_cell(source="c = 3"),
],
nb_path,
)
def fake_send(method, params, timeout=None):
return _make_daemon_response(
text="done\n", execution_count=1,
outputs=[{"output_type": "stream", "name": "stdout", "text": "done\n"}],
)
runner = CliRunner()
with patch("nbexec.cli.exec_cmd.send_to_daemon", side_effect=fake_send):
result = runner.invoke(
exec_code,
[
"--session", "s", "--file", str(nb_path),
"--from-cell", "2", "--to-cell", "2",
"--output", str(out_path),
],
)
assert result.exit_code == 0
out_nb = _read_output_notebook(out_path)
code_cells = [c for c in out_nb.cells if c.cell_type == "code"]
# Cell 2 (index 1) has outputs, cells 1 and 3 do not
assert len(code_cells[0].outputs) == 0
assert len(code_cells[1].outputs) == 1
assert code_cells[1].outputs[0].text == "done\n"
assert len(code_cells[2].outputs) == 0
def test_partial_run_incremental_output(self, tmp_path):
"""Two partial runs into the same output file accumulate outputs."""
nb_path = tmp_path / "test.ipynb"
out_path = tmp_path / "out.ipynb"
_make_notebook(
[
new_code_cell(source="a = 1"),
new_code_cell(source="b = 2"),
],
nb_path,
)
call_count = 0
def fake_send(method, params, timeout=None):
nonlocal call_count
call_count += 1
return _make_daemon_response(
text=f"r{call_count}\n", execution_count=call_count,
outputs=[{"output_type": "stream", "name": "stdout", "text": f"r{call_count}\n"}],
)
runner = CliRunner()
with patch("nbexec.cli.exec_cmd.send_to_daemon", side_effect=fake_send):
# First partial run: cell 1
runner.invoke(
exec_code,
["--session", "s", "--file", str(nb_path),
"--from-cell", "1", "--to-cell", "1",
"--output", str(out_path)],
)
# Second partial run: cell 2
runner.invoke(
exec_code,
["--session", "s", "--file", str(nb_path),
"--from-cell", "2", "--to-cell", "2",
"--output", str(out_path)],
)
out_nb = _read_output_notebook(out_path)
code_cells = [c for c in out_nb.cells if c.cell_type == "code"]
# Both cells should have outputs from their respective runs
assert len(code_cells[0].outputs) == 1
assert code_cells[0].outputs[0].text == "r1\n"
assert len(code_cells[1].outputs) == 1
assert code_cells[1].outputs[0].text == "r2\n"
def test_output_preserves_markdown_cells(self, tmp_path):
"""Output notebook preserves markdown cells from the input."""
nb_path = tmp_path / "test.ipynb"
out_path = tmp_path / "out.ipynb"
_make_notebook(
[
new_markdown_cell(source="# Header"),
new_code_cell(source="x = 42"),
new_markdown_cell(source="## Section 2"),
],
nb_path,
)
def fake_send(method, params, timeout=None):
return _make_daemon_response(text="", execution_count=1)
runner = CliRunner()
with patch("nbexec.cli.exec_cmd.send_to_daemon", side_effect=fake_send):
result = runner.invoke(
exec_code,
["--session", "s", "--file", str(nb_path), "--output", str(out_path)],
)
assert result.exit_code == 0
out_nb = _read_output_notebook(out_path)
assert len(out_nb.cells) == 3
assert out_nb.cells[0].cell_type == "markdown"
assert out_nb.cells[0].source == "# Header"
assert out_nb.cells[1].cell_type == "code"
assert out_nb.cells[2].cell_type == "markdown"
assert out_nb.cells[2].source == "## Section 2"
def test_output_written_on_error(self, tmp_path):
"""Output notebook is still written when a cell fails."""
nb_path = tmp_path / "test.ipynb"
out_path = tmp_path / "out.ipynb"
_make_notebook(
[
new_code_cell(source="ok()"),
new_code_cell(source="fail()"),
],
nb_path,
)
call_count = 0
def fake_send(method, params, timeout=None):
nonlocal call_count
call_count += 1
if call_count == 2:
return _make_daemon_response(
text="NameError", status="error", execution_count=2,
outputs=[{"output_type": "error", "ename": "NameError",
"evalue": "name 'fail' is not defined",
"traceback": ["NameError: name 'fail' is not defined"]}],
)
return _make_daemon_response(
text="ok\n", execution_count=1,
outputs=[{"output_type": "stream", "name": "stdout", "text": "ok\n"}],
)
runner = CliRunner()
with patch("nbexec.cli.exec_cmd.send_to_daemon", side_effect=fake_send):
result = runner.invoke(
exec_code,
["--session", "s", "--file", str(nb_path), "--output", str(out_path)],
)
assert result.exit_code == 1
# Output notebook is still written with partial results
assert out_path.exists()
out_nb = _read_output_notebook(out_path)
code_cells = [c for c in out_nb.cells if c.cell_type == "code"]
assert len(code_cells[0].outputs) == 1 # first cell succeeded
assert code_cells[1].outputs[0].output_type == "error"
def test_output_written_incrementally(self, tmp_path):
"""Output notebook is flushed to disk after each cell, not just at the end."""
nb_path = tmp_path / "test.ipynb"
out_path = tmp_path / "out.ipynb"
_make_notebook(
[
new_code_cell(source="a = 1"),
new_code_cell(source="b = 2"),
new_code_cell(source="c = 3"),
],
nb_path,
)
snapshots = [] # snapshot output notebook state after each cell
call_count = 0
def fake_send(method, params, timeout=None):
nonlocal call_count
call_count += 1
# After the first cell, the output file should already exist on disk.
if call_count > 1 and out_path.exists():
snapshots.append(_read_output_notebook(out_path))
return _make_daemon_response(
text=f"r{call_count}\n", execution_count=call_count,
outputs=[{"output_type": "stream", "name": "stdout", "text": f"r{call_count}\n"}],
)
runner = CliRunner()
with patch("nbexec.cli.exec_cmd.send_to_daemon", side_effect=fake_send):
result = runner.invoke(
exec_code,
["--session", "s", "--file", str(nb_path), "--output", str(out_path)],
)
assert result.exit_code == 0
# We should have captured 2 snapshots (before cell 2 and before cell 3)
assert len(snapshots) == 2
# After cell 1 completed, snapshot should have cell 1 output
code_cells_snap1 = [c for c in snapshots[0].cells if c.cell_type == "code"]
assert len(code_cells_snap1[0].outputs) == 1
assert code_cells_snap1[0].outputs[0].text == "r1\n"
# Cell 2 hasn't been recorded yet in this snapshot
assert len(code_cells_snap1[1].outputs) == 0
def test_output_rejected_for_non_notebook(self, tmp_path):
"""--output only allowed with .ipynb files."""
py_path = tmp_path / "script.py"
py_path.write_text("x = 1\n")
runner = CliRunner()
with patch("nbexec.cli.exec_cmd.send_to_daemon"):
result = runner.invoke(
exec_code,
["--session", "s", "--file", str(py_path), "--output", "out.ipynb"],
)
assert result.exit_code == 1
assert "--output" in result.output
def test_output_same_as_input_rejected(self, tmp_path):
"""--output pointing to the same file as --file is rejected."""
nb_path = tmp_path / "test.ipynb"
_make_notebook([new_code_cell(source="x = 1")], nb_path)
runner = CliRunner()
with patch("nbexec.cli.exec_cmd.send_to_daemon"):
result = runner.invoke(
exec_code,
["--session", "s", "--file", str(nb_path), "--output", str(nb_path)],
)
assert result.exit_code == 1
assert "same file" in result.output
class TestCtrlCInterrupt:
"""Test that Ctrl+C during execution sends interrupt to the daemon."""
def test_single_cell_ctrl_c_sends_interrupt(self):
"""Ctrl+C during single-cell exec interrupts the kernel and exits 130."""
calls = []
def fake_send(method, params, timeout=None):
calls.append(method)
if method == proto.EXEC:
raise KeyboardInterrupt
return {"interrupted": params["session_id"]}
runner = CliRunner()
with patch("nbexec.cli.exec_cmd.send_to_daemon", side_effect=fake_send):
result = runner.invoke(exec_code, ["--session", "s", "--code", "x = 1"])
assert result.exit_code == 130
assert "Interrupted" in result.output
assert calls == [proto.EXEC, proto.INTERRUPT]
def test_notebook_ctrl_c_sends_interrupt(self, tmp_path):
"""Ctrl+C mid-notebook interrupts and exits 130."""
nb_path = tmp_path / "test.ipynb"
_make_notebook(
[
new_code_cell(source="a = 1"),
new_code_cell(source="time.sleep(100)"),
new_code_cell(source="c = 3"),
],
nb_path,
)
exec_count = 0
calls = []
def fake_send(method, params, timeout=None):
nonlocal exec_count
calls.append(method)
if method == proto.EXEC:
exec_count += 1
if exec_count == 2:
raise KeyboardInterrupt
return _make_daemon_response(text="ok\n")
return {"interrupted": params["session_id"]}
runner = CliRunner()
with patch("nbexec.cli.exec_cmd.send_to_daemon", side_effect=fake_send):
result = runner.invoke(
exec_code,
["--session", "s", "--file", str(nb_path)],
)
assert result.exit_code == 130
assert "Interrupted" in result.output
# Cell 1 exec, cell 2 exec (interrupted), then interrupt sent
assert calls == [proto.EXEC, proto.EXEC, proto.INTERRUPT]
def test_notebook_ctrl_c_writes_partial_output(self, tmp_path):
"""Interrupted notebook still writes completed cells to output."""
nb_path = tmp_path / "test.ipynb"
out_path = tmp_path / "out.ipynb"
_make_notebook(
[
new_code_cell(source="a = 1"),
new_code_cell(source="b = 2"),
new_code_cell(source="c = 3"),
],
nb_path,
)
exec_count = 0
def fake_send(method, params, timeout=None):
nonlocal exec_count
if method == proto.EXEC:
exec_count += 1
if exec_count == 2:
raise KeyboardInterrupt
return _make_daemon_response(
text="ok\n", execution_count=1,
outputs=[{"output_type": "stream", "name": "stdout", "text": "ok\n"}],
)
return {"interrupted": params["session_id"]}
runner = CliRunner()
with patch("nbexec.cli.exec_cmd.send_to_daemon", side_effect=fake_send):
result = runner.invoke(
exec_code,
["--session", "s", "--file", str(nb_path), "--output", str(out_path)],
)
assert result.exit_code == 130
assert out_path.exists()
out_nb = _read_output_notebook(out_path)
code_cells = [c for c in out_nb.cells if c.cell_type == "code"]
# Only cell 1 completed; cells 2 and 3 have no outputs
assert len(code_cells[0].outputs) == 1
assert len(code_cells[1].outputs) == 0
assert len(code_cells[2].outputs) == 0
def test_interrupt_send_failure_still_exits(self):
"""If sending interrupt to daemon fails, CLI still exits 130."""
def fake_send(method, params, timeout=None):
if method == proto.EXEC:
raise KeyboardInterrupt
raise ConnectionError("daemon gone")
runner = CliRunner()
with patch("nbexec.cli.exec_cmd.send_to_daemon", side_effect=fake_send):
result = runner.invoke(exec_code, ["--session", "s", "--code", "x = 1"])
assert result.exit_code == 130
assert "Interrupted" in result.output