调整列名并添加输入验证
This commit is contained in:
@@ -11,6 +11,7 @@ from openpyxl import load_workbook
|
||||
from app.prediction import (
|
||||
FEATURES,
|
||||
ID_COLUMN,
|
||||
INPUT_COLUMNS,
|
||||
PIPE_AGE_COLUMN,
|
||||
PredictionError,
|
||||
estimate_remaining_life,
|
||||
@@ -59,6 +60,18 @@ class PredictionHelpersTest(unittest.TestCase):
|
||||
|
||||
self.assertIn("缺少必要字段", ctx.exception.message)
|
||||
|
||||
def test_validate_input_frame_accepts_current_template_columns(self) -> None:
|
||||
df = pd.DataFrame([{column: 1 for column in INPUT_COLUMNS}])
|
||||
|
||||
validate_input_frame(df)
|
||||
|
||||
def test_example_workbook_columns_match_backend_contract(self) -> None:
|
||||
workbook = load_workbook(Path(__file__).resolve().parents[1] / "example.xlsx", read_only=True)
|
||||
worksheet = workbook["Template"]
|
||||
headers = [cell.value for cell in next(worksheet.iter_rows(min_row=1, max_row=1))]
|
||||
|
||||
self.assertEqual(headers, INPUT_COLUMNS)
|
||||
|
||||
def test_read_input_file_preserves_text_pipe_ids(self) -> None:
|
||||
with TemporaryDirectory() as temp_dir:
|
||||
output_path = Path(temp_dir) / "input.xlsx"
|
||||
@@ -97,8 +110,8 @@ class PredictionHelpersTest(unittest.TestCase):
|
||||
]
|
||||
summary_rows = [{"pipe_id": "P001"}, {"pipe_id": "P002"}]
|
||||
summary_sheet_rows = [
|
||||
{"管道编号": "P001", "管龄": "10 年", "健康概率": 0.7, "预计剩余寿命": 2.0, "健康等级": "IV级"},
|
||||
{"管道编号": "P002", "管龄": "12 年", "健康概率": 0.6, "预计剩余寿命": 1.5, "健康等级": "III级"},
|
||||
{ID_COLUMN: "P001", PIPE_AGE_COLUMN: "10 年", "健康概率": 0.7, "预计剩余寿命": 2.0, "健康等级": "IV级"},
|
||||
{ID_COLUMN: "P002", PIPE_AGE_COLUMN: "12 年", "健康概率": 0.6, "预计剩余寿命": 1.5, "健康等级": "III级"},
|
||||
]
|
||||
|
||||
with TemporaryDirectory() as temp_dir:
|
||||
|
||||
Reference in New Issue
Block a user