Skip to content

Commit 690d840

Browse files
Евгений БлиновЕвгений Блинов
authored andcommitted
Add validation for percentile with NaN/inf and null durations in JSON
1 parent 7521147 commit 690d840

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

tests/units/test_benchmark_result.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,16 @@ def test_percentile_above_100_raises(self) -> None:
190190
with pytest.raises(ValueError, match='percentile'):
191191
result.percentile(101)
192192

193+
def test_percentile_nan_raises(self) -> None:
194+
result = make_result((1.0, 2.0, 3.0))
195+
with pytest.raises(ValueError, match='percentile'):
196+
result.percentile(float('nan'))
197+
198+
def test_percentile_inf_raises(self) -> None:
199+
result = make_result((1.0, 2.0, 3.0))
200+
with pytest.raises(ValueError, match='percentile'):
201+
result.percentile(float('inf'))
202+
193203
def test_percentile_preserves_fsum_mean(self) -> None:
194204
durations = tuple(0.1 * i for i in range(1, 11))
195205
result = make_result(durations)
@@ -356,6 +366,11 @@ def test_from_json_durations_with_invalid_element_raises(self) -> None:
356366
with pytest.raises(ValueError, match='could not convert'):
357367
BenchmarkResult.from_json(payload)
358368

369+
def test_from_json_durations_with_null_element_raises(self) -> None:
370+
payload = json.dumps({'durations': [0.1, None], 'is_primary': True})
371+
with pytest.raises(TypeError):
372+
BenchmarkResult.from_json(payload)
373+
359374
def test_from_json_empty_durations_list_raises(self) -> None:
360375
payload = json.dumps({'durations': [], 'is_primary': True})
361376
with pytest.raises(ZeroDivisionError):

0 commit comments

Comments
 (0)