Skip to content
Snippets Groups Projects
Verified Commit d8c93bfa authored by Daniel Hornung's avatar Daniel Hornung
Browse files

ENH: Pretty printing of errors.

parent 3d9adf32
No related branches found
No related tags found
2 merge requests!107Release v0.11.0,!103xlsx -> json conversion
Pipeline #50736 passed
...@@ -97,7 +97,9 @@ validate: bool, optional ...@@ -97,7 +97,9 @@ validate: bool, optional
If True, validate the result against the schema. If True, validate the result against the schema.
collect_errors: bool, optional collect_errors: bool, optional
If True, do not fail at the first error, but try to collect as many errors as possible. If True, do not fail at the first error, but try to collect as many errors as possible. After an
Exception is raised, the errors can be collected with ``get_errors()`` and printed with
``get_error_str()``.
Returns Returns
------- -------
...@@ -120,6 +122,15 @@ out: dict ...@@ -120,6 +122,15 @@ out: dict
"""Return a dict with collected errors.""" """Return a dict with collected errors."""
return self._errors return self._errors
def get_error_str(self) -> str:
"""Return a beautiful string with the collected errors."""
result = ""
for loc, value in self._errors.items():
result += f"Sheet: {loc[0]}\tRow: {loc[1] + 1}\n"
for item in value:
result += f"\t\t{item[:-1]}:\t{item[-1]}\n"
return result
def _check_columns(self, fail_fast: bool = False): def _check_columns(self, fail_fast: bool = False):
"""Check if the columns correspond to the schema.""" """Check if the columns correspond to the schema."""
def missing(path): def missing(path):
......
...@@ -142,6 +142,20 @@ def test_faulty_foreign(): ...@@ -142,6 +142,20 @@ def test_faulty_foreign():
['url', None]], ['url', None]],
} }
error_str = converter.get_error_str()
assert error_str == """Sheet: Training.Organisation.Person\tRow: 9
\t\t['name']:\tWorld Training Organization 2
Sheet: Training.Organisation.Person\tRow: 10
\t\t['date']:\t2024-03-21T14:12:00.000Z
\t\t['url']:\twww.getlinkahead.com
Sheet: Training.participant\tRow: 7
\t\t['date']:\t2024-03-21T14:12:00.000Z
\t\t['url']:\tNone
Sheet: Training.participant\tRow: 8
\t\t['date']:\t2024-03-21T14:12:00.000Z
\t\t['url']:\tNone
"""
def test_set_in_nested(): def test_set_in_nested():
"""Test the ``_set_in_nested`` function.""" """Test the ``_set_in_nested`` function."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment