Skip to content

Commit

Permalink
Better message when dictionary (object) expected.
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-c committed Jun 6, 2023
1 parent 027624d commit c3c3e60
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
3 changes: 2 additions & 1 deletion schema_salad/tests/test_cwl11.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ def test_outputBinding(cwl_v1_2_schema: SchemaType) -> None:

def test_yaml_tab_error(cwl_v1_2_schema: SchemaType) -> None:
"""Tabs in the file."""
res: Any = ""
with pytest.raises(
ValidationException,
match=r".+found\s+character\s+'\\t'\s+that\s+cannot\s+start\s+any\s+token$",
):
res = load_cwl(cwl_v1_2_schema, src="test_real_cwl/tabs_rna_seq_workflow.cwl")
print(res)
print(res)
12 changes: 6 additions & 6 deletions schema_salad/tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ def test_error_message5() -> None:

t = "test_schema/test5.cwl"
match = r"""
^.+test5\.cwl:2:1: Object\s+'.+test5\.cwl'\s+is\s+not valid because
\s+tried 'Workflow'\s+but
.+test5\.cwl:7:1: the 'steps'\s+field\s+is\s+not\s+valid\s+because
\s+tried array\s+of\s+<WorkflowStep>\s+but
.+test5\.cwl:7:9: item is\s+invalid\s+because
\s+is not a\s+dict$"""[
^.+test5\.cwl:2:1: Object\s+'.+test5\.cwl'\s+is\s+not\s+valid\s+because
\s+tried\s+'Workflow'\s+but
.+test5\.cwl:7:1: the\s+'steps'\s+field\s+is\s+not\s+valid\s+because
\s+tried\s+array\s+of\s+<WorkflowStep>\s+but
.+test5\.cwl:7:9: item\s+is\s+invalid\s+because
\s+is\s+not\s+a\s+dict.\s+Expected\s+a\s+WorkflowStep\s+object.$"""[
1:
]
with pytest.raises(ValidationException, match=match):
Expand Down
6 changes: 4 additions & 2 deletions schema_salad/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def validate_ex(
raise ValidationException(
"the value {} is not a valid {}, expected {}{}".format(
vpformat(datum),
expected_schema.name,
friendly(expected_schema.name),
"one of " if len(expected_schema.symbols) > 1 else "",
"'" + "', '".join(expected_schema.symbols) + "'",
)
Expand Down Expand Up @@ -299,7 +299,9 @@ def validate_ex(
if isinstance(expected_schema, avro.schema.RecordSchema):
if not isinstance(datum, MutableMapping):
if raise_ex:
raise ValidationException("is not a dict")
raise ValidationException(
f"is not a dict. Expected a {friendly(expected_schema.name)} object."
)
return False

classmatch = None
Expand Down

0 comments on commit c3c3e60

Please sign in to comment.