feat: validate uploaded pipeline data
This commit is contained in:
@@ -93,6 +93,42 @@ class PredictionHelpersTest(unittest.TestCase):
|
||||
|
||||
validate_input_frame(df)
|
||||
|
||||
def test_validate_input_frame_rejects_blank_pipe_id_with_source_row(self) -> None:
|
||||
df = pd.DataFrame([{column: 1 for column in INPUT_COLUMNS}])
|
||||
df[ID_COLUMN] = [" "]
|
||||
df["_excel_row"] = [7]
|
||||
|
||||
with self.assertRaisesRegex(PredictionError, "管道编号不能为空,Excel行:\\[7\\]"):
|
||||
validate_input_frame(df)
|
||||
|
||||
def test_validate_input_frame_rejects_duplicate_pipe_ids_after_trimming(self) -> None:
|
||||
df = pd.DataFrame([{column: 1 for column in INPUT_COLUMNS}] * 2)
|
||||
df[ID_COLUMN] = ["P001", " P001 "]
|
||||
|
||||
with self.assertRaisesRegex(PredictionError, "管道编号不能重复,Excel行:\\[2, 3\\]"):
|
||||
validate_input_frame(df)
|
||||
|
||||
def test_validate_input_frame_rejects_non_numeric_optional_value(self) -> None:
|
||||
df = pd.DataFrame([{column: 1 for column in INPUT_COLUMNS}])
|
||||
df["压力"] = ["未知"]
|
||||
|
||||
with self.assertRaisesRegex(PredictionError, "压力必须为有限数值,Excel行:\\[2\\]"):
|
||||
validate_input_frame(df)
|
||||
|
||||
def test_validate_input_frame_rejects_functional_defect_above_five(self) -> None:
|
||||
df = pd.DataFrame([{column: 1 for column in INPUT_COLUMNS}])
|
||||
df["功能缺陷"] = [6]
|
||||
|
||||
with self.assertRaisesRegex(PredictionError, "功能缺陷必须在0~5范围内,Excel行:\\[2\\]"):
|
||||
validate_input_frame(df)
|
||||
|
||||
def test_validate_input_frame_rejects_pipe_age_above_model_limit(self) -> None:
|
||||
df = pd.DataFrame([{column: 1 for column in INPUT_COLUMNS}])
|
||||
df[PIPE_AGE_COLUMN] = [74]
|
||||
|
||||
with self.assertRaisesRegex(PredictionError, "管龄(年)不能超过模型支持上限73年,Excel行:\\[2\\]"):
|
||||
validate_input_frame(df, max_pipe_age=73)
|
||||
|
||||
def test_example_workbook_contains_backend_contract_columns(self) -> None:
|
||||
workbook = load_workbook(Path(__file__).resolve().parents[1] / "example.xlsx", read_only=True)
|
||||
worksheet = workbook["Template"]
|
||||
@@ -139,6 +175,22 @@ class PredictionHelpersTest(unittest.TestCase):
|
||||
self.assertAlmostEqual(float(df.loc[0, "结构缺陷"]), 3.8)
|
||||
self.assertAlmostEqual(float(df.loc[0, "功能缺陷"]), 1.6)
|
||||
|
||||
def test_read_input_file_rejects_misaligned_detail_sheet_id(self) -> None:
|
||||
with TemporaryDirectory() as temp_dir:
|
||||
output_path = Path(temp_dir) / "input.xlsx"
|
||||
workbook = Workbook()
|
||||
template = workbook.active
|
||||
template.title = "Template"
|
||||
template.append(INPUT_COLUMNS)
|
||||
template.append(["P001", 5, 1, 100, 1, 1.2, 0.4, 20, 800, None, None])
|
||||
detail = workbook.create_sheet("缺陷计算")
|
||||
detail.append([ID_COLUMN] + ["缺陷"] * 9)
|
||||
detail.append(["P002"] + [None] * 9)
|
||||
workbook.save(output_path)
|
||||
|
||||
with self.assertRaisesRegex(PredictionError, "工作表的管道编号不一致,Excel行:2"):
|
||||
read_input_file(output_path, ".xlsx")
|
||||
|
||||
def test_prepare_model_features_maps_material_aliases_to_rc1_names(self) -> None:
|
||||
rows = []
|
||||
for value in ["镀锌", "2-钢塑", 11]:
|
||||
|
||||
Reference in New Issue
Block a user