Skip to content

Commit 2280a40

Browse files
committed
Add a test for new error formatting
1 parent 39e8a67 commit 2280a40

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/unit/test_reporters.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pytest
55
from jsonschema import Draft7Validator
66

7+
from check_jsonschema.parsers import ParseError
78
from check_jsonschema.reporter import JsonReporter, TextReporter
89
from check_jsonschema.result import CheckResult
910

@@ -240,3 +241,30 @@ def test_json_format_validation_error_nested(capsys, pretty_json, verbosity):
240241
assert "{'baz': 'buzz'} is not of type 'string'" in [
241242
item["message"] for item in bar_errors
242243
]
244+
245+
246+
def test_text_print_parse_error_with_cause(capsys):
247+
cause = json.JSONDecodeError("a bad thing happened", "{,}", 1)
248+
error = ParseError("whoopsie during parsing")
249+
error.__cause__ = cause
250+
251+
result = CheckResult()
252+
result.record_parse_error("foo.json", error)
253+
254+
text_reporter = TextReporter(verbosity=1)
255+
text_reporter.report_result(result)
256+
captured = capsys.readouterr()
257+
258+
# nothing to stderr
259+
assert captured.err == ""
260+
# stdout contains a nicely formatted error
261+
assert (
262+
textwrap.dedent(
263+
"""\
264+
Several files failed to parse.
265+
whoopsie during parsing
266+
JSONDecodeError: a bad thing happened: line 1 column 2 (char 1)
267+
"""
268+
)
269+
in captured.out
270+
)

0 commit comments

Comments
 (0)