2727# ---------------------------------------------------------------------------
2828
2929
30- _FAKE_DERIVED_FROM = {
31- "run_id" : "parent-id" ,
32- "node_id" : "n1" ,
33- "step" : 1 ,
34- "metric_value" : 0.7 ,
35- }
30+ _FAKE_DERIVED_FROM = {"run_id" : "parent-id" , "node_id" : "n1" , "step" : 1 , "metric_value" : 0.7 }
3631
3732
38- def _fake_derive_response (
39- * , candidate_code : dict [str , str ] | None = None , ** run_overrides
40- ) -> dict :
33+ def _fake_derive_response (* , candidate_code : dict [str , str ] | None = None , ** run_overrides ) -> dict :
4134 """Build a canonical successful derive response.
4235
4336 Override any field in the inner ``run`` dict via kwargs (e.g.
@@ -105,10 +98,7 @@ def patched():
10598 ``patched.plain_ui.on_init`` (or ``live_ui.on_init``) for inspection.
10699 """
107100 with (
108- patch (
109- "weco.commands.run.derive.handle_authentication" ,
110- return_value = ("api-key" , {"Authorization" : "Bearer t" }),
111- ),
101+ patch ("weco.commands.run.derive.handle_authentication" , return_value = ("api-key" , {"Authorization" : "Bearer t" })),
112102 patch ("weco.commands.run.derive.WecoClient" ) as MockClient ,
113103 patch ("weco.commands.run.derive.run_optimization_loop" ) as mock_loop ,
114104 patch ("weco.heartbeat.HeartbeatSender" ),
@@ -234,12 +224,7 @@ def test_from_step_wiring(patched, from_step, expected_derive_from, expects_look
234224
235225
236226@pytest .mark .parametrize (
237- "loop_kwarg, expected" ,
238- [
239- ("eval_command" , "python test.py" ),
240- ("save_logs" , True ),
241- ("eval_timeout" , 600 ),
242- ],
227+ "loop_kwarg, expected" , [("eval_command" , "python test.py" ), ("save_logs" , True ), ("eval_timeout" , 600 )]
243228)
244229def test_loop_config_inherited_from_response (patched , loop_kwarg , expected ):
245230 """The loop receives its config from the derive response, not from
@@ -266,10 +251,7 @@ def test_additional_instructions_flow_through_to_derive_run(patched):
266251 """The (resolved) --additional-instructions value reaches the backend.
267252 Locks in the rename from the older `direction` field name."""
268253 _call_handle (additional_instructions = "focus on memory efficiency" )
269- assert (
270- patched .client .derive_run .call_args .kwargs ["additional_instructions" ]
271- == "focus on memory efficiency"
272- )
254+ assert patched .client .derive_run .call_args .kwargs ["additional_instructions" ] == "focus on memory efficiency"
273255
274256
275257# ---------------------------------------------------------------------------
@@ -283,8 +265,7 @@ def test_originals_use_inherited_source_when_local_files_missing(patched, tmp_pa
283265 pollute the working directory with generated code on every eval cycle."""
284266 monkeypatch .chdir (tmp_path ) # empty directory: no local files
285267 patched .client .derive_run .return_value = _fake_derive_response (
286- source_code = {"main.py" : "INHERITED" },
287- candidate_code = {"main.py" : "CANDIDATE" },
268+ source_code = {"main.py" : "INHERITED" }, candidate_code = {"main.py" : "CANDIDATE" }
288269 )
289270
290271 _call_handle ()
@@ -298,9 +279,7 @@ def test_originals_prefer_local_files_when_present(patched, tmp_path, monkeypatc
298279 the user may have made local edits since the parent run."""
299280 monkeypatch .chdir (tmp_path )
300281 (tmp_path / "main.py" ).write_text ("LOCAL_EDITED" )
301- patched .client .derive_run .return_value = _fake_derive_response (
302- source_code = {"main.py" : "INHERITED" }
303- )
282+ patched .client .derive_run .return_value = _fake_derive_response (source_code = {"main.py" : "INHERITED" })
304283
305284 _call_handle ()
306285
@@ -313,8 +292,7 @@ def test_originals_prefer_local_files_when_present(patched, tmp_path, monkeypatc
313292
314293
315294@pytest .mark .parametrize (
316- "output_mode, expected_ui, other_ui" ,
317- [("plain" , "plain_ui" , "live_ui" ), ("rich" , "live_ui" , "plain_ui" )],
295+ "output_mode, expected_ui, other_ui" , [("plain" , "plain_ui" , "live_ui" ), ("rich" , "live_ui" , "plain_ui" )]
318296)
319297def test_handler_picks_ui_for_output_mode (patched , output_mode , expected_ui , other_ui ):
320298 """Plain mode constructs PlainOptimizationUI, rich mode constructs
@@ -346,9 +324,7 @@ def test_handler_returns_false_when_loop_fails(patched):
346324 """Failed loop must propagate as ``False`` — the dispatcher relies on
347325 this to set the process exit code. Loop *success* is covered implicitly
348326 by every other test in this file (the default fixture exercises it)."""
349- patched .loop .return_value = OptimizationResult (
350- success = False , final_step = 3 , status = "error" , reason = "submit_failed"
351- )
327+ patched .loop .return_value = OptimizationResult (success = False , final_step = 3 , status = "error" , reason = "submit_failed" )
352328 assert _call_handle () is False
353329
354330
@@ -379,9 +355,7 @@ def test_plain_mode_skips_unchanged_files_prompt(patched):
379355
380356
381357@pytest .mark .parametrize (
382- "loop_success, expect_apply_called" ,
383- [(True , True ), (False , False )],
384- ids = ["success-applies-best" , "failure-skips-apply" ],
358+ "loop_success, expect_apply_called" , [(True , True ), (False , False )], ids = ["success-applies-best" , "failure-skips-apply" ]
385359)
386360def test_apply_best_only_after_successful_loop (patched , loop_success , expect_apply_called ):
387361 patched .loop .return_value = OptimizationResult (
@@ -424,11 +398,7 @@ def test_api_errors_exit_cleanly_with_code_1(patched, make_exception):
424398 assert exc .value .code == 1
425399
426400
427- @pytest .mark .parametrize (
428- "output_mode, expect_json_in_stderr" ,
429- [("plain" , True ), ("rich" , False )],
430- ids = ["plain" , "rich" ],
431- )
401+ @pytest .mark .parametrize ("output_mode, expect_json_in_stderr" , [("plain" , True ), ("rich" , False )], ids = ["plain" , "rich" ])
432402def test_derive_error_routed_through_correct_channel (patched , capsys , output_mode , expect_json_in_stderr ):
433403 """A DeriveError reaches the user via stderr+JSON in plain mode and
434404 styled console output in rich mode. Plain mode in particular must never
0 commit comments