Skip to content

Commit

Permalink
Improve test failure error message
Browse files Browse the repository at this point in the history
Sometimes this test fails with 4 conversion failurs instead of
3 and we do not know why because there is no useful output.
This change adds the output from the conversions on failure
and adjusts the test to compare the okay and failed count
at the same time by using a tuple.
  • Loading branch information
timj committed Feb 22, 2024
1 parent 2b8a8e2 commit 7eb96f4
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions tests/test_translate_header.py
Expand Up @@ -84,17 +84,25 @@ def test_translate_header_fails(self):
[TESTDATA], r"^.*yaml$", 0, False, outstream=out, errstream=err, output_mode="none"
)

lines = self._readlines(out)
self.assertEqual(len(lines), len(failed))
self.assertTrue(lines[0].startswith("Failure processing"), f"Line: '{lines[0]}'")
self.assertIn("not a mapping", lines[0], f"Line: '{lines[0]}'")

lines = self._readlines(err)
self.assertEqual(len(lines), 13)
self.assertTrue(lines[0].startswith("Analyzing"), f"Line: '{lines[0]}'")

self.assertEqual(len(okay), 10)
self.assertEqual(len(failed), 3)
out_lines = self._readlines(out)
self.assertEqual(len(out_lines), len(failed))
self.assertTrue(out_lines[0].startswith("Failure processing"), f"Line: '{out_lines[0]}'")
self.assertIn("not a mapping", out_lines[0], f"Line: '{out_lines[0]}'")

err_lines = self._readlines(err)
self.assertEqual(len(err_lines), 13) # The number of files analyzed
self.assertTrue(err_lines[0].startswith("Analyzing"), f"Line: '{err_lines[0]}'")

# Form message to issue if the test fails.
newline = "\n" # f-string can not accept \ in string.
msg = f"""Converted successfully:
{newline.join(okay)}
Failed conversions:
{newline.join(failed)}
Standard output:
{newline.join(out_lines)}
"""
self.assertEqual((len(okay), len(failed)), (10, 3), msg=msg)

def test_translate_header_traceback(self):
"""Translate some header files that fail and trigger traceback."""
Expand Down

0 comments on commit 7eb96f4

Please sign in to comment.