Skip to content

Commit 287d63a

Browse files
committed
Using model validator for error instead
Signed-off-by: Erik Jaegervall <[email protected]>
1 parent c6b888b commit 287d63a

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

src/vss_tools/model.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,13 @@ def check_const_uid_format(cls, v: str | None) -> str | None:
126126
assert bool(re.match(pattern, v)), f"'{v}' is not a valid 'constUID'"
127127
return v
128128

129-
@field_validator("description", mode="before")
130-
@classmethod
131-
def ensure_description(cls, value: Any) -> Any:
129+
@model_validator(mode="after")
130+
def ensure_description(self) -> Self:
132131
"""Give better explanation for empty description."""
133-
134-
if value == "":
135-
raise ValueError(
136-
"all nodes in the final tree must have a description. "
137-
"Implicit branches are not allowed in final tree!"
138-
)
139-
return value
132+
assert (
133+
self.description != ""
134+
), "All nodes in the final tree must have a description. Implicit branches are not allowed in final tree!"
135+
return self
140136

141137

142138
class VSSDataBranch(VSSData):

tests/vspec/test_description_error/test_description_error.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ def test_description_error(vspec_file: str, type_file: str, type_out_file: str,
4040
assert process.returncode != 0
4141
log_content = log.read_text()
4242
print(log_content)
43-
assert "'type': 'value_error'" in log_content
43+
assert "'type': 'assertion_error'" in log_content
4444
assert "1 model error(s):" in log_content

tests/vspec/test_overlay/test_overlay.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,5 @@ def test_overlay_branch_error(tmp_path):
7171
assert process.returncode != 0
7272
log_content = log.read_text()
7373
assert "'A.AB' has 1 model error(s)" in log_content
74-
assert "'type': 'value_error'" in log_content
74+
assert "'type': 'assertion_error'" in log_content
7575
assert "description" in log_content

0 commit comments

Comments
 (0)