Files
liqiang b119135836
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
ai-agent-book 精选快照(<2MB 代码与文档,来自 github.com/bojieli/ai-agent-book)
2026-08-20 13:12:50 +00:00

77 lines
2.3 KiB
Python

"""Blank integer CSV cells must load as 0, not ValueError from int('')."""
import csv
from pathlib import Path
from reporting_tools import ReportingEnvironment
def _write_csv(path: Path, tests_value: str) -> None:
with path.open("w", newline="", encoding="utf-8") as handle:
writer = csv.DictWriter(
handle,
fieldnames=[
"row_id",
"org_unit_id",
"period",
"parent_org_unit",
"tests",
"confirmed_cases",
"deaths",
"report_expected",
"report_submitted",
"stockout_days",
],
)
writer.writeheader()
writer.writerow(
{
"row_id": "r1",
"org_unit_id": "ou1",
"period": "2024Q1",
"parent_org_unit": "p1",
"tests": tests_value,
"confirmed_cases": "5",
"deaths": "0",
"report_expected": "1",
"report_submitted": "1",
"stockout_days": "0",
}
)
def test_blank_tests_field_loads_as_zero(tmp_path):
path = tmp_path / "blank.csv"
_write_csv(path, "")
env = ReportingEnvironment(path)
assert env.rows[0]["tests"] == 0
assert env.rows[0]["confirmed_cases"] == 5
def test_whitespace_tests_field_loads_as_zero(tmp_path):
path = tmp_path / "space.csv"
_write_csv(path, " ")
env = ReportingEnvironment(path)
assert env.rows[0]["tests"] == 0
def test_numeric_tests_unchanged(tmp_path):
path = tmp_path / "ok.csv"
_write_csv(path, "12")
env = ReportingEnvironment(path)
assert env.rows[0]["tests"] == 12
def test_reporting_environment_call_null_arguments(tmp_path):
"""JSON null tool arguments should behave like an empty object."""
import pytest
path = tmp_path / "ok.csv"
_write_csv(path, "12")
env = ReportingEnvironment(path)
with pytest.raises(TypeError) as null_exc:
env.call("calculate_test_positivity", None)
with pytest.raises(TypeError) as empty_exc:
env.call("calculate_test_positivity", {})
assert "mapping" not in str(null_exc.value)
assert str(null_exc.value) == str(empty_exc.value)