Skip to content

Commit c3c3e60

Browse files
committed
Better message when dictionary (object) expected.
1 parent 027624d commit c3c3e60

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

schema_salad/tests/test_cwl11.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ def test_outputBinding(cwl_v1_2_schema: SchemaType) -> None:
6767

6868
def test_yaml_tab_error(cwl_v1_2_schema: SchemaType) -> None:
6969
"""Tabs in the file."""
70+
res: Any = ""
7071
with pytest.raises(
7172
ValidationException,
7273
match=r".+found\s+character\s+'\\t'\s+that\s+cannot\s+start\s+any\s+token$",
7374
):
7475
res = load_cwl(cwl_v1_2_schema, src="test_real_cwl/tabs_rna_seq_workflow.cwl")
75-
print(res)
76+
print(res)

schema_salad/tests/test_errors.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,12 @@ def test_error_message5() -> None:
132132

133133
t = "test_schema/test5.cwl"
134134
match = r"""
135-
^.+test5\.cwl:2:1: Object\s+'.+test5\.cwl'\s+is\s+not valid because
136-
\s+tried 'Workflow'\s+but
137-
.+test5\.cwl:7:1: the 'steps'\s+field\s+is\s+not\s+valid\s+because
138-
\s+tried array\s+of\s+<WorkflowStep>\s+but
139-
.+test5\.cwl:7:9: item is\s+invalid\s+because
140-
\s+is not a\s+dict$"""[
135+
^.+test5\.cwl:2:1: Object\s+'.+test5\.cwl'\s+is\s+not\s+valid\s+because
136+
\s+tried\s+'Workflow'\s+but
137+
.+test5\.cwl:7:1: the\s+'steps'\s+field\s+is\s+not\s+valid\s+because
138+
\s+tried\s+array\s+of\s+<WorkflowStep>\s+but
139+
.+test5\.cwl:7:9: item\s+is\s+invalid\s+because
140+
\s+is\s+not\s+a\s+dict.\s+Expected\s+a\s+WorkflowStep\s+object.$"""[
141141
1:
142142
]
143143
with pytest.raises(ValidationException, match=match):

schema_salad/validate.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def validate_ex(
196196
raise ValidationException(
197197
"the value {} is not a valid {}, expected {}{}".format(
198198
vpformat(datum),
199-
expected_schema.name,
199+
friendly(expected_schema.name),
200200
"one of " if len(expected_schema.symbols) > 1 else "",
201201
"'" + "', '".join(expected_schema.symbols) + "'",
202202
)
@@ -299,7 +299,9 @@ def validate_ex(
299299
if isinstance(expected_schema, avro.schema.RecordSchema):
300300
if not isinstance(datum, MutableMapping):
301301
if raise_ex:
302-
raise ValidationException("is not a dict")
302+
raise ValidationException(
303+
f"is not a dict. Expected a {friendly(expected_schema.name)} object."
304+
)
303305
return False
304306

305307
classmatch = None

0 commit comments

Comments
 (0)