diff --git a/backend/tests/test_eval_analysis_runs.py b/backend/tests/test_eval_analysis_runs.py index e34e3e04..e6875410 100644 --- a/backend/tests/test_eval_analysis_runs.py +++ b/backend/tests/test_eval_analysis_runs.py @@ -32,8 +32,9 @@ from app.eval.gold import Context from tests import eval_samples as es from tests.fixtures.acceptance import retail_trends -TZ = "Asia/Shanghai" SUITE = json.loads((Path(__file__).parent / "fixtures" / "eval" / "analysis_suite.json").read_text(encoding="utf-8")) +#: 题集的时区:题目里的期次({{ schedule.* }})按它算,生成库的「今天」也按它取,不看本机时区 +TZ = SUITE["suite"]["timezone"] #: 题集里的第 1 题(上周销售额下降主要来自华东)和第 3 题(订单数的常规波动) REGION = next(c for c in SUITE["cases"] if c["seq"] == 1) ORDERS = next(c for c in SUITE["cases"] if c["seq"] == 3) @@ -53,7 +54,7 @@ async def engine_up(monkeypatch): @pytest.fixture async def source(tmp_path, scratch_source): - path = retail_trends.build(tmp_path / "trends.db", date.today()) + path = retail_trends.build(tmp_path / "trends.db", now().date()) sid = await scratch_source(retail_trends.SOURCE_NAME, path, schema=True) return {"id": sid, "name": retail_trends.SOURCE_NAME, "path": path} diff --git a/backend/tests/test_eval_analysis_suite.py b/backend/tests/test_eval_analysis_suite.py index 09a54222..0ce9c0e2 100644 --- a/backend/tests/test_eval_analysis_suite.py +++ b/backend/tests/test_eval_analysis_suite.py @@ -4,9 +4,10 @@ from __future__ import annotations import json -from datetime import date +from datetime import datetime from pathlib import Path from urllib.parse import quote +from zoneinfo import ZoneInfo import pytest from httpx import ASGITransport, AsyncClient @@ -33,9 +34,11 @@ async def engine_up(): async def test_the_analysis_suite_imports_and_every_expectation_computes(tmp_path, scratch_source): - path = retail_trends.build(tmp_path / "trends.db", date.today()) - sid = await scratch_source(retail_trends.SOURCE_NAME, path, schema=True) content = json.loads(SUITE_FILE.read_text(encoding="utf-8")) + # 「今天」按题集的时区取(题目里的期次按它算),不看本机时区:本机在别的时区时,跨日那几个钟头两边的今天不是同一天 + today = datetime.now(ZoneInfo(content["suite"]["timezone"])).date() + path = retail_trends.build(tmp_path / "trends.db", today) + sid = await scratch_source(retail_trends.SOURCE_NAME, path, schema=True) assert {c["seq"] for c in content["cases"]} == set(WANTED) assert all(c["gold"]["datasource"] == retail_trends.SOURCE_NAME for c in content["cases"]) async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client: @@ -44,7 +47,7 @@ async def test_the_analysis_suite_imports_and_every_expectation_computes(tmp_pat assert res.json()["imported"] == len(WANTED) and res.json()["skipped"] == [] suite = res.json()["suite"] assert all(c["gold"]["datasource_id"] == sid for c in suite["cases"]) - monday = date.today().weekday() == 0 + monday = today.weekday() == 0 for case in suite["cases"]: assert case["trial"]["status"] == "ok", (case["seq"], case["trial"]) trial = (await client.post(f"/api/evals/suites/{suite['id']}/cases/{case['id']}/trial")).json()["trial"] diff --git a/backend/tests/test_evals_api.py b/backend/tests/test_evals_api.py index 910938e7..1264129f 100644 --- a/backend/tests/test_evals_api.py +++ b/backend/tests/test_evals_api.py @@ -386,7 +386,9 @@ async def test_export_then_import_matches_sources_by_name(client, source): async def test_the_retail_sample_suite_trials_on_the_retail_database(client, tmp_path): """仓库里附的零售样例题集:在虚构零售库上导入,每道题都试算通过,期望和直接查库一样,陷阱按口径算。""" - today = datetime.now(ZoneInfo("Asia/Shanghai")).date() + # 「今天」按题集的时区取(题目里的期次按它算),不看本机时区:本机在别的时区时,跨日那几个钟头两边的今天不是同一天 + content = json.loads(SUITE_FILE.read_text(encoding="utf-8")) + today = datetime.now(ZoneInfo(content["suite"]["timezone"])).date() path = retail.build(tmp_path / "retail.db", today) await drop_source(name=retail.SOURCE_NAME) async with SessionLocal() as session: @@ -398,7 +400,6 @@ async def test_the_retail_sample_suite_trials_on_the_retail_database(client, tmp await session.commit() sid = row.id try: - content = json.loads(SUITE_FILE.read_text(encoding="utf-8")) res = await client.post("/api/evals/suites/import", json={"content": content}, headers=ACTOR) assert res.status_code == 201, res.text assert res.json()["imported"] == 6 and res.json()["skipped"] == []