统一实时标定身份解析并规范行尾
控制器与两个对话框共用 CalibrationService.read_identity,解析失败与缺 SN 分开上报; 本轮改动文件统一 LF,SN 必填回归已锁定。 定向 73 项、校准 UI 8 项与 lint 通过;未跑全量门禁。
This commit is contained in:
@@ -79,3 +79,52 @@ def test_the_same_configuration_named_differently_is_not_a_mismatch(tmp_path):
|
||||
|
||||
# ...but it does have to be a path: a non-path value simply differs.
|
||||
assert CalibrationService.same_path("D:/lab/a/sensor.json", "not a path\x00") is False
|
||||
|
||||
|
||||
# --------------------------------------------------- one parse, both answers
|
||||
|
||||
|
||||
def test_read_identity_returns_the_identity_and_no_error(tmp_path):
|
||||
"""The strict parse answers with the identity *and* says it succeeded."""
|
||||
path = _calibration_file(tmp_path, sensor_type="box", config_ref="D:/lab/a/sensor.json")
|
||||
|
||||
identity, error = CalibrationService.read_identity(path)
|
||||
|
||||
assert error == ""
|
||||
assert identity == {
|
||||
"sensor_type": "box",
|
||||
"sn": "SN-A",
|
||||
"config_ref": "D:/lab/a/sensor.json",
|
||||
}
|
||||
# The old name keeps its behaviour and is a thin wrapper over the one parse.
|
||||
assert CalibrationService.identity_of(path) == identity
|
||||
|
||||
|
||||
def test_read_identity_keeps_the_parsers_reason_when_the_file_cannot_be_read(tmp_path):
|
||||
broken = tmp_path / "broken.json"
|
||||
broken.write_text(
|
||||
json.dumps({"schema_version": 2, "unit": "N", "channels": {"fn": "bogus"}}),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
identity, error = CalibrationService.read_identity(broken)
|
||||
|
||||
assert identity == {}
|
||||
assert error
|
||||
assert "\n" not in error, "the reason must stay one line for the status bar"
|
||||
assert CalibrationService.identity_of(broken) == {}
|
||||
|
||||
|
||||
def test_read_identity_distinguishes_a_parsed_document_without_an_sn(tmp_path):
|
||||
"""A readable document that simply names no device is not a parse failure."""
|
||||
path = _calibration_file(tmp_path, sensor_type="box", config_ref="D:/lab/a/sensor.json")
|
||||
document = json.loads(path.read_text(encoding="utf-8"))
|
||||
document.pop("identity")
|
||||
document.pop("pipeline")
|
||||
path.write_text(json.dumps(document), encoding="utf-8")
|
||||
|
||||
identity, error = CalibrationService.read_identity(path)
|
||||
|
||||
assert error == ""
|
||||
assert identity["sn"] == ""
|
||||
assert identity["sensor_type"] == ""
|
||||
|
||||
Reference in New Issue
Block a user