From ccde8e2129403f0e277bf55fcb7b005e5320400a Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 8 Dec 2021 16:00:13 +0100 Subject: [PATCH] Add checking of results text against embedded failure info. Implementation is a bit ad-hoc Fixes #49 --- tests/test_all.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/test_all.py b/tests/test_all.py index d15d8cb..0d31fdb 100644 --- a/tests/test_all.py +++ b/tests/test_all.py @@ -1,4 +1,5 @@ """Test suite.""" +import ast import glob import os.path from os.path import join @@ -61,6 +62,20 @@ def test_expected_failures(modpath, expected_failure): needle = ": %s " % code assert needle in out + with open(os.path.join(modpath, expected_failure)) as f: + doc = ast.get_docstring( + ast.parse(f.read(), expected_failure), + clean=True, + ) + + # keep "literal" lines, skip shell lines + result_check = "".join( + line + "\n" for line in doc.splitlines() if line.startswith(" RST") + ) + if result_check: + modpath = os.path.join(modpath, "") + assert out.replace(modpath, " ") == result_check + def test_expected_successes(modpath): """Verify the positive test cases (expected successes)."""