summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2016-01-01 16:29:01 -0500
committerNed Batchelder <ned@nedbatchelder.com>2016-01-01 16:29:01 -0500
commit6f69dc8997ba560a7d8e7b820d692d452b5d24e7 (patch)
tree6eff2ca004dc6906280beb3e792f339f24ff1863
parentf1e583f91035983237d248b417b8ca9831ceac39 (diff)
downloadpython-coveragepy-git-6f69dc8997ba560a7d8e7b820d692d452b5d24e7.tar.gz
Clean up after making arcz_missing and arcz_unpredicted default to empty.
--HG-- branch : ast-branch
-rw-r--r--tests/coveragetest.py40
-rw-r--r--tests/test_arcs.py80
2 files changed, 57 insertions, 63 deletions
diff --git a/tests/coveragetest.py b/tests/coveragetest.py
index 28d6616b..9d2ae1a2 100644
--- a/tests/coveragetest.py
+++ b/tests/coveragetest.py
@@ -163,7 +163,7 @@ class CoverageTest(
def check_coverage(
self, text, lines=None, missing="", report="",
excludes=None, partials="",
- arcz=None, arcz_missing=None, arcz_unpredicted=None,
+ arcz=None, arcz_missing="", arcz_unpredicted="",
arcs=None, arcs_missing=None, arcs_unpredicted=None,
):
"""Check the coverage measurement of `text`.
@@ -175,10 +175,11 @@ class CoverageTest(
of the measurement report.
For arc measurement, `arcz` is a string that can be decoded into arcs
- in the code (see `arcz_to_arcs` for the encoding scheme),
+ in the code (see `arcz_to_arcs` for the encoding scheme).
`arcz_missing` are the arcs that are not executed, and
- `arcs_unpredicted` are the arcs executed in the code, but not deducible
- from the code.
+ `arcz_unpredicted` are the arcs executed in the code, but not deducible
+ from the code. These last two default to "", meaning we explicitly
+ check that there are no missing or unpredicted arcs.
Returns the Coverage object, in case you want to poke at it some more.
@@ -191,14 +192,13 @@ class CoverageTest(
if arcs is None and arcz is not None:
arcs = self.arcz_to_arcs(arcz)
- if arcs_missing is None:# and arcz_missing is not None:
- arcs_missing = self.arcz_to_arcs(arcz_missing or "")
- if arcs_unpredicted is None:# and arcz_unpredicted is not None:
- arcs_unpredicted = self.arcz_to_arcs(arcz_unpredicted or "")
- branch = any(x is not None for x in [arcs, arcs_missing, arcs_unpredicted])
+ if arcs_missing is None:
+ arcs_missing = self.arcz_to_arcs(arcz_missing)
+ if arcs_unpredicted is None:
+ arcs_unpredicted = self.arcz_to_arcs(arcz_unpredicted)
# Start up coverage.py.
- cov = coverage.Coverage(branch=branch)
+ cov = coverage.Coverage(branch=True)
cov.erase()
for exc in excludes or []:
cov.exclude(exc)
@@ -240,17 +240,15 @@ class CoverageTest(
if arcs is not None:
self.assert_equal_args(analysis.arc_possibilities(), arcs, "Possible arcs differ")
- if arcs_missing is not None:
- self.assert_equal_args(
- analysis.arcs_missing(), arcs_missing,
- "Missing arcs differ"
- )
-
- if arcs_unpredicted is not None:
- self.assert_equal_args(
- analysis.arcs_unpredicted(), arcs_unpredicted,
- "Unpredicted arcs differ"
- )
+ self.assert_equal_args(
+ analysis.arcs_missing(), arcs_missing,
+ "Missing arcs differ"
+ )
+
+ self.assert_equal_args(
+ analysis.arcs_unpredicted(), arcs_unpredicted,
+ "Unpredicted arcs differ"
+ )
if report:
frep = StringIO()
diff --git a/tests/test_arcs.py b/tests/test_arcs.py
index 1f1bdd1d..a55b5d39 100644
--- a/tests/test_arcs.py
+++ b/tests/test_arcs.py
@@ -87,7 +87,8 @@ class SimpleArcTest(CoverageTest):
if len([]) == 0: a = 2
assert a == 2
""",
- arcz=".1 12 23 3.", arcz_missing="")
+ arcz=".1 12 23 3.",
+ )
self.check_coverage("""\
def fn(x):
if x % 2: return True
@@ -106,7 +107,8 @@ class SimpleArcTest(CoverageTest):
b = \\
6
""",
- arcz=".1 15 5-2", arcz_missing="")
+ arcz=".1 15 5-2",
+ )
def test_if_return(self):
self.check_coverage("""\
@@ -118,8 +120,8 @@ class SimpleArcTest(CoverageTest):
x = if_ret(0) + if_ret(1)
assert x == 8
""",
- arcz=".1 16 67 7. .2 23 24 3. 45 5.", arcz_missing=""
- )
+ arcz=".1 16 67 7. .2 23 24 3. 45 5.",
+ )
def test_dont_confuse_exit_and_else(self):
self.check_coverage("""\
@@ -192,7 +194,8 @@ class LoopArcTest(CoverageTest):
a = i
assert a == 9
""",
- arcz=".1 12 21 13 3.", arcz_missing="")
+ arcz=".1 12 21 13 3.",
+ )
self.check_coverage("""\
a = -1
for i in range(0):
@@ -208,7 +211,8 @@ class LoopArcTest(CoverageTest):
a = i + j
assert a == 4
""",
- arcz=".1 12 23 32 21 14 4.", arcz_missing="")
+ arcz=".1 12 23 32 21 14 4.",
+ )
def test_break(self):
self.check_coverage("""\
@@ -271,8 +275,7 @@ class LoopArcTest(CoverageTest):
assert a == 4 and i == 3
""",
arcz=arcz,
- arcz_missing="",
- )
+ )
def test_for_if_else_for(self):
self.check_coverage("""\
@@ -329,7 +332,8 @@ class LoopArcTest(CoverageTest):
x = tup[0]
y = tup[1]
""",
- arcz=arcz, arcz_missing="", arcz_unpredicted="")
+ arcz=arcz,
+ )
if env.PY3:
arcz = ".1 12 .2 2-2 23 34 42 2."
else:
@@ -340,7 +344,8 @@ class LoopArcTest(CoverageTest):
x = tup[0]
y = tup[1]
""",
- arcz=arcz, arcz_missing="", arcz_unpredicted="")
+ arcz=arcz,
+ )
def test_generator_expression(self):
# Generator expression:
@@ -352,7 +357,6 @@ class LoopArcTest(CoverageTest):
y = tup[1]
""",
arcz=".1 .2 2-2 12 23 34 45 53 3.",
- arcz_missing="", arcz_unpredicted=""
)
def test_other_comprehensions(self):
@@ -367,7 +371,6 @@ class LoopArcTest(CoverageTest):
y = tup[1]
""",
arcz=".1 .2 2-2 12 23 34 45 53 3.",
- arcz_missing="", arcz_unpredicted=""
)
# Dict comprehension:
self.check_coverage("""\
@@ -378,7 +381,6 @@ class LoopArcTest(CoverageTest):
y = tup[1]
""",
arcz=".1 .2 2-2 12 23 34 45 53 3.",
- arcz_missing="", arcz_unpredicted=""
)
@@ -445,8 +447,8 @@ class ExceptionArcTest(CoverageTest):
assert try_it(1) == 7 # D
""",
arcz=".1 12 .3 34 3-2 4-2 25 5D DE E. .6 67 78 89 9C AB BC C-5",
- arcz_missing="",
- arcz_unpredicted="8A")
+ arcz_unpredicted="8A",
+ )
def test_try_finally(self):
self.check_coverage("""\
@@ -457,7 +459,8 @@ class ExceptionArcTest(CoverageTest):
c = 5
assert a == 3 and c == 5
""",
- arcz=".1 12 23 35 56 6.", arcz_missing="")
+ arcz=".1 12 23 35 56 6.",
+ )
self.check_coverage("""\
a, c, d = 1, 1, 1
try:
@@ -470,7 +473,8 @@ class ExceptionArcTest(CoverageTest):
assert a == 4 and c == 6 and d == 1 # 9
""",
arcz=".1 12 23 34 46 78 89 69 9.",
- arcz_missing="78 89", arcz_unpredicted="")
+ arcz_missing="78 89",
+ )
self.check_coverage("""\
a, c, d = 1, 1, 1
try:
@@ -485,7 +489,8 @@ class ExceptionArcTest(CoverageTest):
assert a == 4 and c == 8 and d == 10 # B
""",
arcz=".1 12 23 34 45 58 68 89 8B 9A AB B.",
- arcz_missing="68 8B", arcz_unpredicted="")
+ arcz_missing="68 8B",
+ )
def test_finally_in_loop(self):
self.check_coverage("""\
@@ -522,7 +527,7 @@ class ExceptionArcTest(CoverageTest):
assert a == 8 and c == 10 and d == 1 # D
""",
arcz=".1 12 23 34 3D 45 56 67 68 7A 8A A3 AB BC CD D.",
- arcz_missing="67 7A AB BC CD", arcz_unpredicted="",
+ arcz_missing="67 7A AB BC CD",
)
@@ -543,12 +548,9 @@ class ExceptionArcTest(CoverageTest):
assert a == 5 and c == 10 and d == 1 # D
""",
arcz=".1 12 23 34 3D 45 56 67 68 7A 8A A3 AD BC CD D.",
- arcz_missing="3D BC CD", arcz_unpredicted="",
+ arcz_missing="3D BC CD",
)
- # TODO: shouldn't arcz_unpredicted always be empty?
- # NO: it has arcs due to exceptions.
-
def test_finally_in_loop_bug_92(self):
self.check_coverage("""\
for i in range(5):
@@ -560,7 +562,7 @@ class ExceptionArcTest(CoverageTest):
h = 7
""",
arcz=".1 12 23 35 56 61 17 7.",
- arcz_missing="", arcz_unpredicted="")
+ )
# "except Exception as e" is crucial here.
def test_bug_212(self):
@@ -688,8 +690,7 @@ class YieldTest(CoverageTest):
list(gen([1,2,3]))
""",
arcz=".1 .2 23 2. 32 15 5.",
- arcz_missing="",
- arcz_unpredicted="")
+ )
def test_padded_yield_in_loop(self):
self.check_coverage("""\
@@ -704,8 +705,7 @@ class YieldTest(CoverageTest):
list(gen([1,2,3]))
""",
arcz=".1 19 9. .2 23 34 45 56 63 37 7.",
- arcz_missing="",
- arcz_unpredicted="")
+ )
def test_bug_308(self):
self.check_coverage("""\
@@ -717,8 +717,7 @@ class YieldTest(CoverageTest):
print(f())
""",
arcz=".1 15 56 65 5. .2 23 32 2. .3 3-3",
- arcz_missing="",
- arcz_unpredicted="")
+ )
self.check_coverage("""\
def run():
@@ -730,8 +729,7 @@ class YieldTest(CoverageTest):
print(f())
""",
arcz=".1 16 67 76 6. .2 23 34 43 3. 2-2 .4 4-4",
- arcz_missing="",
- arcz_unpredicted="")
+ )
self.check_coverage("""\
def run():
@@ -741,8 +739,7 @@ class YieldTest(CoverageTest):
print(f())
""",
arcz=".1 14 45 54 4. .2 2. 2-2",
- arcz_missing="",
- arcz_unpredicted="")
+ )
def test_bug_324(self):
# This code is tricky: the list() call pulls all the values from gen(),
@@ -760,7 +757,7 @@ class YieldTest(CoverageTest):
".2 23 32 2. " # The gen() function
".3 3-3", # The generator expression
arcz_missing=".3 3-3",
- arcz_unpredicted="")
+ )
def test_coroutines(self):
self.check_coverage("""\
@@ -780,7 +777,7 @@ class YieldTest(CoverageTest):
".1 17 78 89 9A AB B. "
".2 23 34 45 52 2.",
arcz_missing="2.",
- arcz_unpredicted="")
+ )
self.assertEqual(self.stdout(), "20\n12\n")
def test_yield_from(self):
@@ -798,8 +795,7 @@ class YieldTest(CoverageTest):
list(gen([1,2,3]))
""",
arcz=".1 19 9. .2 23 34 45 56 5. 63 37 7.",
- arcz_missing="",
- arcz_unpredicted="")
+ )
class MiscArcTest(CoverageTest):
@@ -888,7 +884,6 @@ class AsyncTest(CoverageTest):
".1 13 38 8C CD DE E. "
".4 45 56 6-3 "
".9 9A A-8",
- arcz_missing="",
)
self.assertEqual(self.stdout(), "Compute 1 + 2 ...\n1 + 2 = 3\n")
@@ -925,7 +920,6 @@ class AsyncTest(CoverageTest):
".5 5-4 " # __init__
".8 8-7 " # __aiter__
".B BC C-A DE E-A ", # __anext__
- arcz_missing="",
arcz_unpredicted="CD",
)
self.assertEqual(self.stdout(), "a\nb\nc\n.\n")
@@ -1053,7 +1047,8 @@ class ExcludeTest(CoverageTest):
f = 9
""",
[1,2,3,4,5,6,7,8,9],
- arcz=".1 12 23 24 34 45 56 57 67 78 89 9. 8.", arcz_missing="")
+ arcz=".1 12 23 24 34 45 56 57 67 78 89 9. 8.",
+ )
def test_custom_pragmas(self):
self.check_coverage("""\
@@ -1065,7 +1060,8 @@ class ExcludeTest(CoverageTest):
""",
[1,2,3,4,5],
partials=["only some"],
- arcz=".1 12 23 34 45 25 5.", arcz_missing="")
+ arcz=".1 12 23 34 45 25 5.",
+ )
class LineDataTest(CoverageTest):