|
9 | 9 | from sigmatch import SignatureMismatchError |
10 | 10 |
|
11 | 11 | from microbenchmark import BenchmarkResult, Scenario, ScenarioGroup, arguments |
12 | | -from microbenchmark.scenario import _fn_call_str |
| 12 | +from microbenchmark.scenario import _fn_call_str, _render_result |
13 | 13 |
|
14 | 14 | # --------------------------------------------------------------------------- |
15 | 15 | # Construction |
@@ -354,7 +354,7 @@ def fake_timer() -> float: |
354 | 354 | scenario = Scenario(lambda: None, name='s', number=3, timer=fake_timer) |
355 | 355 | result = scenario.run(warmup=2) |
356 | 356 |
|
357 | | - assert tick[0] == 12 # warmup: 2*2=4, loop_start: 1, run: 3*2=6, loop_end: 1 → 12 |
| 357 | + assert tick[0] == 8 # loop_start: 1, run: 3*2=6, loop_end: 1 → 8 (warmup has no timer calls) |
358 | 358 | assert len(result.durations) == 3 |
359 | 359 | assert result.durations == pytest.approx((1.0, 1.0, 1.0)) |
360 | 360 |
|
@@ -603,3 +603,9 @@ def test_fn_call_str_non_oserror_propagates(): |
603 | 603 |
|
604 | 604 | with pytest.raises(ValueError, match='unexpected'), patch('microbenchmark.scenario.superrepr', side_effect=ValueError('unexpected')): |
605 | 605 | _fn_call_str(fn, None) |
| 606 | + |
| 607 | + |
| 608 | +def test_render_result_raises_when_scenario_is_none(): |
| 609 | + result = BenchmarkResult.from_json('{"durations":[0.001,0.002],"is_primary":true,"scenario":null}') |
| 610 | + with pytest.raises(ValueError, match='scenario must not be None'): |
| 611 | + _render_result(result) |
0 commit comments