fix: 区域表缺少编号列或米数不符时拒绝创建

This commit is contained in:
2026-10-25 07:20:39 +08:00
parent 22733f221c
commit 6b9a2ad860
2 changed files with 74 additions and 30 deletions
+18
View File
@@ -4,6 +4,7 @@ import os
import threading
from pathlib import Path
from app.features.download.ids import parse_table
from app.features.download.journal import CsvJournal, explain_os_error
from app.platform.client import NqiError
@@ -136,6 +137,23 @@ def test_file_errors_use_chinese(tmp_path: Path, monkeypatch):
journal.close()
def test_area_table_rules():
try:
parse_table([["序号", "栅格编码"], ["1", "541927061"]])
except ValueError as exc:
assert str(exc) == "请把编号列的表头写成 20米栅格ID 或 50米栅格ID"
else:
raise AssertionError("多列且没有编号列时应拒绝")
assert parse_table([["541927061"], ["544536471"]]) == (["541927061", "544536471"], 0)
try:
parse_table([["20米栅格ID"], ["12"]], "GRID50")
except ValueError as exc:
assert str(exc) == "表头是20米栅格,与所选的50米不一致"
else:
raise AssertionError("米数不一致时应拒绝")
assert parse_table([["栅格ID", "备注"], ["12", "a"]], "GRID50") == (["12"], 0)
def _patch_fsync(monkeypatch):
calls = []
original = os.fsync