From 454e82e211e7796b1b43332103b9013fbe92bf7e Mon Sep 17 00:00:00 2001 From: ThearchyHelios Date: Wed, 21 Oct 2026 14:57:06 +0000 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E6=9E=90=E6=B5=8B=E8=AF=95=E7=9A=84?= =?UTF-8?q?=E3=80=8C=E4=BB=8A=E5=A4=A9=E3=80=8D=E6=8C=89=E9=A2=98=E9=9B=86?= =?UTF-8?q?=E7=9A=84=E6=97=B6=E5=8C=BA=E5=8F=96=EF=BC=8C=E4=B8=8D=E7=9C=8B?= =?UTF-8?q?=E6=9C=AC=E6=9C=BA=E6=97=B6=E5=8C=BA=EF=BC=9A=E9=A2=98=E9=9B=86?= =?UTF-8?q?=E9=87=8C=E7=9A=84=E6=9C=9F=E6=AC=A1=EF=BC=88=E4=B8=8A=E5=91=A8?= =?UTF-8?q?=E3=80=81=E6=9C=AC=E5=91=A8=EF=BC=89=E6=8C=89=20suite.timezone?= =?UTF-8?q?=20=E7=AE=97=EF=BC=8C=E7=94=9F=E6=88=90=E8=99=9A=E6=9E=84?= =?UTF-8?q?=E5=BA=93=E3=80=81=E5=88=A4=E4=BB=8A=E5=A4=A9=E6=98=AF=E4=B8=8D?= =?UTF-8?q?=E6=98=AF=E5=91=A8=E4=B8=80=E4=B9=9F=E7=85=A7=E5=AE=83=EF=BC=8C?= =?UTF-8?q?=E6=9C=AC=E6=9C=BA=E5=9C=A8=E5=88=AB=E7=9A=84=E6=97=B6=E5=8C=BA?= =?UTF-8?q?=EF=BC=88=E6=88=96=E8=B7=A8=E5=8D=88=E5=A4=9C=E9=82=A3=E5=87=A0?= =?UTF-8?q?=E4=B8=AA=E9=92=9F=E5=A4=B4=EF=BC=89=E6=97=B6=E4=B8=A4=E8=BE=B9?= =?UTF-8?q?=E4=B8=8D=E6=98=AF=E5=90=8C=E4=B8=80=E5=A4=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - test_eval_analysis_runs.py:TZ 从题集读,新增 now()(datetime.now(ZoneInfo(TZ))),生成库用 now().date(),原来写死的 Asia/Shanghai 去掉 - test_eval_analysis_suite.py:从题集内容取时区算今天,判周一也按它 - test_evals_api.py:零售样例题集的「今天」同样从题集取时区 --- backend/tests/test_eval_analysis_runs.py | 5 +++-- backend/tests/test_eval_analysis_suite.py | 11 +++++++---- backend/tests/test_evals_api.py | 5 +++-- 3 files changed, 13 insertions(+), 8 deletions(-) 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"] == []