Add test coverage for _as_int handling TypeError and ValueError (#8)

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
This commit is contained in:
Horizontal42 2026-08-19 17:13:07 +03:00 • committed by GitHub
parent 007fdb2509
commit d0b4451c40
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -7,6 +7,7 @@ from unittest.mock import AsyncMock, patch
import pytest import pytest
from netsleuth.speed import ( from netsleuth.speed import (
_as_int,
bufferbloat_delta, bufferbloat_delta,
mbps, mbps,
ookla_interface_args, ookla_interface_args,
@ -397,3 +398,16 @@ async def test_measure_with_bufferbloat_without_an_idle_baseline_grades_unknown(
) )
assert result.bufferbloat_down_ms is None assert result.bufferbloat_down_ms is None
assert result.bufferbloat_grade == "?" assert result.bufferbloat_grade == "?"
def test_as_int_returns_none_for_none():
assert _as_int(None) is None
def test_as_int_returns_none_for_invalid_string():
assert _as_int("abc") is None
def test_as_int_returns_parsed_integer_for_valid_string():
assert _as_int("123") == 123
assert _as_int("-456") == -456