diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2023-01-05 08:07:17 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2023-01-05 12:55:18 -0500 |
commit | d4339ee90c3146f370d572cbb1b9ab9907daafad (patch) | |
tree | 8f543dcd9577c3b3b7b78ff85c055c228e5ee704 /tests/test_goldtest.py | |
parent | 8ff3c6dfe6207dc79ed7be5105675d2f08725b76 (diff) | |
download | python-coveragepy-git-d4339ee90c3146f370d572cbb1b9ab9907daafad.tar.gz |
mypy: test_goldtest.py test_json.py test_lcov.py test_mixins.py test_numbits.py test_oddball.py
Diffstat (limited to 'tests/test_goldtest.py')
-rw-r--r-- | tests/test_goldtest.py | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/tests/test_goldtest.py b/tests/test_goldtest.py index 4462d5ab..def5ee90 100644 --- a/tests/test_goldtest.py +++ b/tests/test_goldtest.py @@ -3,6 +3,8 @@ """Tests of the helpers in goldtest.py""" +from __future__ import annotations + import os.path import re @@ -33,7 +35,7 @@ SCRUBS = [ (r'G\w+', 'Gxxx'), ] -def path_regex(path): +def path_regex(path: str) -> str: """Convert a file path into a regex that will match that path on any OS.""" return re.sub(r"[/\\]", r"[/\\\\]", path.replace(".", "[.]")) @@ -48,16 +50,16 @@ OUT_PATH_RX = path_regex("out/gettysburg.txt") class CompareTest(CoverageTest): """Tests of goldtest.py:compare()""" - def setUp(self): + def setUp(self) -> None: super().setUp() self.addCleanup(remove_tree, ACTUAL_DIR) - def test_good(self): + def test_good(self) -> None: self.make_file("out/gettysburg.txt", GOOD_GETTY) compare(gold_path("testing/getty"), "out", scrubs=SCRUBS) self.assert_doesnt_exist(ACTUAL_GETTY_FILE) - def test_bad(self): + def test_bad(self) -> None: self.make_file("out/gettysburg.txt", BAD_GETTY) # compare() raises an assertion. @@ -78,7 +80,7 @@ class CompareTest(CoverageTest): saved = f.read() assert saved == BAD_GETTY - def test_good_needs_scrubs(self): + def test_good_needs_scrubs(self) -> None: # Comparing the "good" result without scrubbing the variable parts will fail. self.make_file("out/gettysburg.txt", GOOD_GETTY) @@ -91,7 +93,7 @@ class CompareTest(CoverageTest): assert "- 11/19/1863, Gettysburg, Pennsylvania" in stdout assert "+ 11/19/9999, Gettysburg, Pennsylvania" in stdout - def test_actual_extra(self): + def test_actual_extra(self) -> None: self.make_file("out/gettysburg.txt", GOOD_GETTY) self.make_file("out/another.more", "hi") @@ -107,7 +109,7 @@ class CompareTest(CoverageTest): # But only the files matching the file_pattern are considered. compare(gold_path("testing/getty"), "out", file_pattern="*.txt", scrubs=SCRUBS) - def test_xml_good(self): + def test_xml_good(self) -> None: self.make_file("out/output.xml", """\ <?xml version="1.0" ?> <the_root c="three" b="222" a="one"> @@ -118,7 +120,7 @@ class CompareTest(CoverageTest): """) compare(gold_path("testing/xml"), "out", scrubs=SCRUBS) - def test_xml_bad(self): + def test_xml_bad(self) -> None: self.make_file("out/output.xml", """\ <?xml version="1.0" ?> <the_root c="nine" b="2" a="one"> @@ -147,25 +149,25 @@ class ContainsTest(CoverageTest): run_in_temp_dir = False - def test_contains(self): + def test_contains(self) -> None: contains(GOLD_GETTY_FILE, "Four", "fathers", "dedicated") msg = rf"Missing content in {GOLD_GETTY_FILE_RX}: 'xyzzy'" with pytest.raises(AssertionError, match=msg): contains(GOLD_GETTY_FILE, "Four", "fathers", "xyzzy", "dedicated") - def test_contains_rx(self): + def test_contains_rx(self) -> None: contains_rx(GOLD_GETTY_FILE, r"Fo.r", r"f[abc]thers", "dedi[cdef]ated") msg = rf"Missing regex in {GOLD_GETTY_FILE_RX}: r'm\[opq\]thers'" with pytest.raises(AssertionError, match=msg): contains_rx(GOLD_GETTY_FILE, r"Fo.r", r"m[opq]thers") - def test_contains_any(self): + def test_contains_any(self) -> None: contains_any(GOLD_GETTY_FILE, "Five", "Four", "Three") msg = rf"Missing content in {GOLD_GETTY_FILE_RX}: 'One' \[1 of 3\]" with pytest.raises(AssertionError, match=msg): contains_any(GOLD_GETTY_FILE, "One", "Two", "Three") - def test_doesnt_contain(self): + def test_doesnt_contain(self) -> None: doesnt_contain(GOLD_GETTY_FILE, "One", "Two", "Three") msg = rf"Forbidden content in {GOLD_GETTY_FILE_RX}: 'Four'" with pytest.raises(AssertionError, match=msg): |