summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2021-03-11 06:11:55 -0500
committerNed Batchelder <ned@nedbatchelder.com>2021-03-11 06:38:43 -0500
commit5f6fd5aa9e4b08ac4cbc4a85ee566245c26967b5 (patch)
treec9d59850ed3b200d257ae0d8c096c77ebfb71dde
parent29310f4bb634a8fccb5ff0453ae6686bbebcca17 (diff)
downloadpython-coveragepy-git-5f6fd5aa9e4b08ac4cbc4a85ee566245c26967b5.tar.gz
refactor: move tests into classes
Now that we don't inherit from TestCase, pytest can parametrize methods.
-rw-r--r--tests/test_testing.py117
1 files changed, 63 insertions, 54 deletions
diff --git a/tests/test_testing.py b/tests/test_testing.py
index e3053e96..ad26bada 100644
--- a/tests/test_testing.py
+++ b/tests/test_testing.py
@@ -284,35 +284,40 @@ class CheckCoverageTest(CoverageTest):
)
-@pytest.mark.parametrize("text, pat, result", [
- ("line1\nline2\nline3\n", "line", "line1\nline2\nline3\n"),
- ("line1\nline2\nline3\n", "[13]", "line1\nline3\n"),
- ("line1\nline2\nline3\n", "X", ""),
-])
-def test_re_lines(text, pat, result):
- assert re_lines(text, pat) == result
-
-@pytest.mark.parametrize("text, pat, result", [
- ("line1\nline2\nline3\n", "line", ""),
- ("line1\nline2\nline3\n", "[13]", "line2\n"),
- ("line1\nline2\nline3\n", "X", "line1\nline2\nline3\n"),
-])
-def test_re_lines_inverted(text, pat, result):
- assert re_lines(text, pat, match=False) == result
-
-@pytest.mark.parametrize("text, pat, result", [
- ("line1\nline2\nline3\n", "2", "line2"),
-])
-def test_re_line(text, pat, result):
- assert re_line(text, pat) == result
-
-@pytest.mark.parametrize("text, pat", [
- ("line1\nline2\nline3\n", "line"), # too many matches
- ("line1\nline2\nline3\n", "X"), # no matches
-])
-def test_re_line_bad(text, pat):
- with pytest.raises(AssertionError):
- re_line(text, pat)
+class ReLinesTest(CoverageTest):
+ """Tests of `re_lines`."""
+
+ run_in_temp_dir = False
+
+ @pytest.mark.parametrize("text, pat, result", [
+ ("line1\nline2\nline3\n", "line", "line1\nline2\nline3\n"),
+ ("line1\nline2\nline3\n", "[13]", "line1\nline3\n"),
+ ("line1\nline2\nline3\n", "X", ""),
+ ])
+ def test_re_lines(self, text, pat, result):
+ assert re_lines(text, pat) == result
+
+ @pytest.mark.parametrize("text, pat, result", [
+ ("line1\nline2\nline3\n", "line", ""),
+ ("line1\nline2\nline3\n", "[13]", "line2\n"),
+ ("line1\nline2\nline3\n", "X", "line1\nline2\nline3\n"),
+ ])
+ def test_re_lines_inverted(self, text, pat, result):
+ assert re_lines(text, pat, match=False) == result
+
+ @pytest.mark.parametrize("text, pat, result", [
+ ("line1\nline2\nline3\n", "2", "line2"),
+ ])
+ def test_re_line(self, text, pat, result):
+ assert re_line(text, pat) == result
+
+ @pytest.mark.parametrize("text, pat", [
+ ("line1\nline2\nline3\n", "line"), # too many matches
+ ("line1\nline2\nline3\n", "X"), # no matches
+ ])
+ def test_re_line_bad(self, text, pat):
+ with pytest.raises(AssertionError):
+ re_line(text, pat)
def test_convert_skip_exceptions():
@@ -379,28 +384,32 @@ def test_without_module():
assert toml2 is None
-@pytest.mark.parametrize("arcz, arcs", [
- (".1 12 2.", [(-1, 1), (1, 2), (2, -1)]),
- ("-11 12 2-5", [(-1, 1), (1, 2), (2, -5)]),
- ("-QA CB IT Z-A", [(-26, 10), (12, 11), (18, 29), (35, -10)]),
-])
-def test_arcz_to_arcs(arcz, arcs):
- assert arcz_to_arcs(arcz) == arcs
-
-
-@pytest.mark.parametrize("arcs, arcz_repr", [
- ([(-1, 1), (1, 2), (2, -1)], "(-1, 1) # .1\n(1, 2) # 12\n(2, -1) # 2.\n"),
- ([(-1, 1), (1, 2), (2, -5)], "(-1, 1) # .1\n(1, 2) # 12\n(2, -5) # 2-5\n"),
- ([(-26, 10), (12, 11), (18, 29), (35, -10), (1, 33), (100, 7)],
- (
- "(-26, 10) # -QA\n"
- "(12, 11) # CB\n"
- "(18, 29) # IT\n"
- "(35, -10) # Z-A\n"
- "(1, 33) # 1X\n"
- "(100, 7) # ?7\n"
- )
- ),
-])
-def test_arcs_to_arcz_repr(arcs, arcz_repr):
- assert arcs_to_arcz_repr(arcs) == arcz_repr
+class ArczTest(CoverageTest):
+ """Tests of arcz/arcs helpers."""
+
+ run_in_temp_dir = False
+
+ @pytest.mark.parametrize("arcz, arcs", [
+ (".1 12 2.", [(-1, 1), (1, 2), (2, -1)]),
+ ("-11 12 2-5", [(-1, 1), (1, 2), (2, -5)]),
+ ("-QA CB IT Z-A", [(-26, 10), (12, 11), (18, 29), (35, -10)]),
+ ])
+ def test_arcz_to_arcs(self, arcz, arcs):
+ assert arcz_to_arcs(arcz) == arcs
+
+ @pytest.mark.parametrize("arcs, arcz_repr", [
+ ([(-1, 1), (1, 2), (2, -1)], "(-1, 1) # .1\n(1, 2) # 12\n(2, -1) # 2.\n"),
+ ([(-1, 1), (1, 2), (2, -5)], "(-1, 1) # .1\n(1, 2) # 12\n(2, -5) # 2-5\n"),
+ ([(-26, 10), (12, 11), (18, 29), (35, -10), (1, 33), (100, 7)],
+ (
+ "(-26, 10) # -QA\n"
+ "(12, 11) # CB\n"
+ "(18, 29) # IT\n"
+ "(35, -10) # Z-A\n"
+ "(1, 33) # 1X\n"
+ "(100, 7) # ?7\n"
+ )
+ ),
+ ])
+ def test_arcs_to_arcz_repr(self, arcs, arcz_repr):
+ assert arcs_to_arcz_repr(arcs) == arcz_repr