diff options
-rw-r--r-- | tests/coveragetest.py | 6 | ||||
-rw-r--r-- | tests/test_testing.py | 51 |
2 files changed, 54 insertions, 3 deletions
diff --git a/tests/coveragetest.py b/tests/coveragetest.py index 9b7fe167..3363fa89 100644 --- a/tests/coveragetest.py +++ b/tests/coveragetest.py @@ -55,7 +55,7 @@ class CoverageTest( # Temp dirs go to $TMPDIR/coverage_test/* temp_dir_prefix = "coverage_test/" - if os.getenv('COVERAGE_ENV_ID'): + if os.getenv('COVERAGE_ENV_ID'): # pragma: debugging temp_dir_prefix += "{}/".format(os.getenv('COVERAGE_ENV_ID')) # Keep the temp directories if the env says to. @@ -115,8 +115,8 @@ class CoverageTest( s1 = arcs_to_arcz_repr(a1) s2 = arcs_to_arcz_repr(a2) if s1 != s2: - lines1 = s1.splitlines(keepends=True) - lines2 = s2.splitlines(keepends=True) + lines1 = s1.splitlines(True) + lines2 = s2.splitlines(True) diff = "".join(difflib.ndiff(lines1, lines2)) return "\n" + arc_type + " arcs differ: minus is expected, plus is actual\n" + diff else: diff --git a/tests/test_testing.py b/tests/test_testing.py index 67ec8dff..f5d9f942 100644 --- a/tests/test_testing.py +++ b/tests/test_testing.py @@ -245,6 +245,57 @@ class CheckUniqueFilenamesTest(CoverageTest): stub.method("file1") +class CheckCoverageTest(CoverageTest): + """Tests of the failure assertions in check_coverage.""" + + CODE = """\ + a, b = 1, 1 + def oops(x): + if x % 2: + raise Exception("odd") + try: + a = 6 + oops(1) + a = 8 + except: + b = 10 + assert a == 6 and b == 10 + """ + ARCZ = ".1 12 -23 34 3-2 4-2 25 56 67 78 8B 9A AB B." + ARCZ_MISSING = "3-2 78 8B" + ARCZ_UNPREDICTED = "79" + + def test_check_coverage_possible(self): + msg = r"(?s)Possible arcs differ: .*- \(6, 3\).*\+ \(6, 7\)" + with pytest.raises(AssertionError, match=msg): + self.check_coverage( + self.CODE, + arcz=self.ARCZ.replace("7", "3"), + arcz_missing=self.ARCZ_MISSING, + arcz_unpredicted=self.ARCZ_UNPREDICTED, + ) + + def test_check_coverage_missing(self): + msg = r"(?s)Missing arcs differ: .*- \(3, 8\).*\+ \(7, 8\)" + with pytest.raises(AssertionError, match=msg): + self.check_coverage( + self.CODE, + arcz=self.ARCZ, + arcz_missing=self.ARCZ_MISSING.replace("7", "3"), + arcz_unpredicted=self.ARCZ_UNPREDICTED, + ) + + def test_check_coverage_unpredicted(self): + msg = r"(?s)Unpredicted arcs differ: .*- \(3, 9\).*\+ \(7, 9\)" + with pytest.raises(AssertionError, match=msg): + self.check_coverage( + self.CODE, + arcz=self.ARCZ, + arcz_missing=self.ARCZ_MISSING, + arcz_unpredicted=self.ARCZ_UNPREDICTED.replace("7", "3") + ) + + @pytest.mark.parametrize("text, pat, result", [ ("line1\nline2\nline3\n", "line", "line1\nline2\nline3\n"), ("line1\nline2\nline3\n", "[13]", "line1\nline3\n"), |