From 59a1f7823e449bb768988fdc07c861616485fb80 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 7 Oct 2026 03:54:54 +0000 Subject: [PATCH] test: add error paths test for _add metric helper Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com> --- tests/test_metrics.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/test_metrics.py b/tests/test_metrics.py index 0d42121..e01d79a 100644 --- a/tests/test_metrics.py +++ b/tests/test_metrics.py @@ -1,6 +1,6 @@ from __future__ import annotations -from netsleuth.metrics import Metric, collect_metrics, render_csv, render_prometheus +from netsleuth.metrics import Metric, _add, collect_metrics, render_csv, render_prometheus def _report(**overrides) -> dict: @@ -84,3 +84,15 @@ def test_render_csv_has_a_header_row_and_quotes_a_comma_in_a_label(): lines = text.strip().splitlines() assert lines[0] == "metric,labels,value" assert '"target=a, b"' in lines[1] + + +def test_add_ignores_uncastable_values(): + metrics: list[Metric] = [] + + # Uncastable string raises ValueError + _add(metrics, "test_metric", "abc") + assert len(metrics) == 0 + + # Incompatible type like dict raises TypeError + _add(metrics, "test_metric", {"some": "dict"}) + assert len(metrics) == 0