优化代码,增加更新测试用例功能

This commit is contained in:
2026-06-04 13:53:31 +08:00
parent fb86198565
commit 83a425c235
9 changed files with 247 additions and 88 deletions
+15 -15
View File
@@ -4,14 +4,14 @@ from openpyxl import Workbook
from src.core.mil_read_case_excel import (
read_excel_case,
__get_template_version,
__analysis_action,
_get_template_version,
_analysis_action,
)
from src.core.mil_create_data_excel import (
create_excel_case,
__init_data_log,
__analysis_case,
__analysis_step,
_init_data_log,
_analysis_case,
_analysis_step,
)
from src.core.exceptions import ExcelReadError, ExcelFormatError, CaseDataError
from src.core.base import DataLog
@@ -69,7 +69,7 @@ def test_get_template_version():
sheet.cell(2, 1, "v1.0.0")
sheet.cell(3, 1, None)
version = __get_template_version(sheet)
version = _get_template_version(sheet)
assert version == "v1.0.0"
@@ -78,7 +78,7 @@ def test_get_template_version_empty():
wb = Workbook()
sheet = wb.active
version = __get_template_version(sheet)
version = _get_template_version(sheet)
assert version is None
@@ -88,7 +88,7 @@ def test_analysis_action_valid(sample_data_dict):
sheet = wb.create_sheet("TestSheet")
sheet.cell(1, 1, "Test")
action = __analysis_action(sheet, 1, 3, "signal1=newvalue", sample_data_dict, "test.xlsx")
action = _analysis_action(sheet, 1, 3, "signal1=newvalue", sample_data_dict, "test.xlsx")
assert "signal1" in action
assert action["signal1"] == "newvalue"
@@ -99,7 +99,7 @@ def test_analysis_action_multiple(sample_data_dict):
sheet = wb.create_sheet("TestSheet")
sheet.cell(1, 1, "Test")
action = __analysis_action(sheet, 1, 3, "signal1=v1; signal2=v2", sample_data_dict, "test.xlsx")
action = _analysis_action(sheet, 1, 3, "signal1=v1; signal2=v2", sample_data_dict, "test.xlsx")
assert "signal1" in action
assert "signal2" in action
assert action["signal1"] == "v1"
@@ -113,7 +113,7 @@ def test_analysis_action_invalid_signal(sample_data_dict):
sheet.cell(1, 1, "Test")
with pytest.raises(CaseDataError, match="信号 .* 不存在"):
__analysis_action(sheet, 1, 3, "invalid_signal=value", sample_data_dict, "test.xlsx")
_analysis_action(sheet, 1, 3, "invalid_signal=value", sample_data_dict, "test.xlsx")
def test_init_data_log(sample_data_dict):
@@ -122,7 +122,7 @@ def test_init_data_log(sample_data_dict):
for name in data_copy:
data_copy[name]["datalog"] = data_copy[name]["datalog"].copy()
__init_data_log(data_copy)
_init_data_log(data_copy)
for name in data_copy:
assert len(data_copy[name]["datalog"]) == 1
@@ -143,7 +143,7 @@ def test_analysis_step_with_action(sample_data_dict):
for name in data_copy:
data_copy[name]["datalog"] = data_copy[name]["datalog"].copy()
__analysis_step(step_dict, data_copy)
_analysis_step(step_dict, data_copy)
assert len(data_copy["signal1"]["datalog"]) == 3
assert data_copy["signal1"]["datalog"][-1].time == 1.5
@@ -164,14 +164,14 @@ def test_analysis_step_without_action(sample_data_dict):
data_copy[name]["datalog"] = data_copy[name]["datalog"].copy()
initial_length = len(data_copy["signal1"]["datalog"])
__analysis_step(step_dict, data_copy)
_analysis_step(step_dict, data_copy)
assert len(data_copy["signal1"]["datalog"]) == initial_length + 1
def test_analysis_case(sample_data_dict, sample_sheets_dict):
"""验证用例分析"""
result = __analysis_case(sample_data_dict, sample_sheets_dict)
result = _analysis_case(sample_data_dict, sample_sheets_dict)
assert "TestCase1" in result
assert "TestCase2" not in result
@@ -188,7 +188,7 @@ def test_analysis_case_skips_enabled_cases(sample_data_dict):
}
}
result = __analysis_case(sample_data_dict, sheets_dict)
result = _analysis_case(sample_data_dict, sheets_dict)
assert "EnabledCase" not in result