Skip to content

Commit 4a2be8d

Browse files
Kasper JungeRalphify
authored andcommitted
refactor: use consistent TypedDict field access in ConsoleEmitter
Changed data.get("max_iterations") to data["max_iterations"] since it's a required field in RunStartedData. The .get() was masking incomplete test data — updated all RUN_STARTED test events to include every required field (max_iterations, delay) matching the TypedDict contract. Co-authored-by: Ralphify <noreply@ralphify.co>
1 parent 4f47bc4 commit 4a2be8d

2 files changed

Lines changed: 39 additions & 6 deletions

File tree

src/ralphify/_console_emitter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def _on_run_started(self, data: RunStartedData) -> None:
103103
command_count = data["commands"]
104104
if command_count > 0:
105105
info_parts.append(_plural(command_count, "command"))
106-
max_iter = data.get("max_iterations")
106+
max_iter = data["max_iterations"]
107107
if max_iter is not None:
108108
info_parts.append(f"max {_plural(max_iter, 'iteration')}")
109109
if info_parts:

tests/test_console_emitter.py

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ def test_run_started_shows_ralph_name(self):
2828
emitter, console = _capture_emitter()
2929
emitter.emit(
3030
_make_event(
31-
EventType.RUN_STARTED, ralph_name="my-ralph", timeout=0, commands=0
31+
EventType.RUN_STARTED,
32+
ralph_name="my-ralph",
33+
timeout=0,
34+
commands=0,
35+
max_iterations=None,
36+
delay=0,
3237
)
3338
)
3439
output = console.export_text()
@@ -39,7 +44,12 @@ def test_run_started_shows_timeout(self):
3944
emitter, console = _capture_emitter()
4045
emitter.emit(
4146
_make_event(
42-
EventType.RUN_STARTED, ralph_name="test", timeout=120, commands=0
47+
EventType.RUN_STARTED,
48+
ralph_name="test",
49+
timeout=120,
50+
commands=0,
51+
max_iterations=None,
52+
delay=0,
4353
)
4454
)
4555
output = console.export_text()
@@ -48,15 +58,29 @@ def test_run_started_shows_timeout(self):
4858
def test_run_started_shows_command_count(self):
4959
emitter, console = _capture_emitter()
5060
emitter.emit(
51-
_make_event(EventType.RUN_STARTED, ralph_name="test", timeout=0, commands=3)
61+
_make_event(
62+
EventType.RUN_STARTED,
63+
ralph_name="test",
64+
timeout=0,
65+
commands=3,
66+
max_iterations=None,
67+
delay=0,
68+
)
5269
)
5370
output = console.export_text()
5471
assert "3 commands" in output
5572

5673
def test_run_started_singular_command(self):
5774
emitter, console = _capture_emitter()
5875
emitter.emit(
59-
_make_event(EventType.RUN_STARTED, ralph_name="test", timeout=0, commands=1)
76+
_make_event(
77+
EventType.RUN_STARTED,
78+
ralph_name="test",
79+
timeout=0,
80+
commands=1,
81+
max_iterations=None,
82+
delay=0,
83+
)
6084
)
6185
output = console.export_text()
6286
assert "1 command" in output
@@ -72,6 +96,7 @@ def test_run_started_shows_max_iterations(self):
7296
timeout=0,
7397
commands=0,
7498
max_iterations=5,
99+
delay=0,
75100
)
76101
)
77102
output = console.export_text()
@@ -80,7 +105,14 @@ def test_run_started_shows_max_iterations(self):
80105
def test_run_started_no_info_line_when_no_config(self):
81106
emitter, console = _capture_emitter()
82107
emitter.emit(
83-
_make_event(EventType.RUN_STARTED, ralph_name="test", timeout=0, commands=0)
108+
_make_event(
109+
EventType.RUN_STARTED,
110+
ralph_name="test",
111+
timeout=0,
112+
commands=0,
113+
max_iterations=None,
114+
delay=0,
115+
)
84116
)
85117
output = console.export_text()
86118
# Should still show the ralph name header
@@ -97,6 +129,7 @@ def test_run_started_combines_info(self):
97129
timeout=60,
98130
commands=2,
99131
max_iterations=3,
132+
delay=0,
100133
)
101134
)
102135
output = console.export_text()

0 commit comments

Comments
 (0)