summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2016-01-01 16:10:50 -0500
committerNed Batchelder <ned@nedbatchelder.com>2016-01-01 16:10:50 -0500
commitf1e583f91035983237d248b417b8ca9831ceac39 (patch)
tree0bce77a485184176a494a2ab3345df6303769414
parentc9464bbc696d393799c0989e4ca132987cc2fbb3 (diff)
downloadpython-coveragepy-git-f1e583f91035983237d248b417b8ca9831ceac39.tar.gz
check_coverage now assumes empty missing and unpredicted, and uses branch always
--HG-- branch : ast-branch
-rw-r--r--coverage/parser.py8
-rw-r--r--tests/coveragetest.py8
-rw-r--r--tests/test_arcs.py22
-rw-r--r--tests/test_coverage.py17
4 files changed, 41 insertions, 14 deletions
diff --git a/coverage/parser.py b/coverage/parser.py
index 33480924..2396fb8c 100644
--- a/coverage/parser.py
+++ b/coverage/parser.py
@@ -347,7 +347,7 @@ class AstArcAnalyzer(object):
def line_Dict(self, node):
# Python 3.5 changed how dict literals are made.
- if env.PYVERSION >= (3, 5):
+ if env.PYVERSION >= (3, 5) and node.keys:
return node.keys[0].lineno
return node.lineno
@@ -587,7 +587,7 @@ class AstArcAnalyzer(object):
def handle_default(self, node):
node_name = node.__class__.__name__
if node_name not in ["Assign", "Assert", "AugAssign", "Expr", "Import", "Pass", "Print"]:
- print("*** Unhandled: {}".format(node))
+ print("*** Unhandled: {0}".format(node))
return set([self.line_for_node(node)])
CODE_COMPREHENSIONS = set(["GeneratorExp", "DictComp", "SetComp"])
@@ -1049,6 +1049,10 @@ SKIP_FIELDS = ["ctx"]
def ast_dump(node, depth=0):
indent = " " * depth
+ if not isinstance(node, ast.AST):
+ print("{0}<{1} {2!r}>".format(indent, node.__class__.__name__, node))
+ return
+
lineno = getattr(node, "lineno", None)
if lineno is not None:
linemark = " @ {0}".format(lineno)
diff --git a/tests/coveragetest.py b/tests/coveragetest.py
index 3468b794..28d6616b 100644
--- a/tests/coveragetest.py
+++ b/tests/coveragetest.py
@@ -191,10 +191,10 @@ 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)
- if arcs_unpredicted is None and arcz_unpredicted is not None:
- arcs_unpredicted = self.arcz_to_arcs(arcz_unpredicted)
+ 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])
# Start up coverage.py.
diff --git a/tests/test_arcs.py b/tests/test_arcs.py
index a64ab89e..1f1bdd1d 100644
--- a/tests/test_arcs.py
+++ b/tests/test_arcs.py
@@ -653,7 +653,7 @@ class ExceptionArcTest(CoverageTest):
assert a == 7 and b == 1 and c == 9
""",
arcz=".1 12 23 45 39 59 67 79 9A A.", arcz_missing="39 45 59",
- arcz_unpredicted="34 46",
+ arcz_unpredicted="34 46", # TODO: 46 can be predicted.
)
self.check_coverage("""\
a, b, c = 1, 1, 1
@@ -672,7 +672,7 @@ class ExceptionArcTest(CoverageTest):
""",
arcz=".1 12 23 34 4A 56 6A 78 8A AD BC CD D.",
arcz_missing="4A 56 6A 78 8A AD",
- arcz_unpredicted="45 57 7A AB",
+ arcz_unpredicted="45 57 7A AB", # TODO: 57 7A can be predicted.
)
@@ -783,6 +783,24 @@ class YieldTest(CoverageTest):
arcz_unpredicted="")
self.assertEqual(self.stdout(), "20\n12\n")
+ def test_yield_from(self):
+ if env.PYVERSION < (3, 3):
+ self.skip("Python before 3.3 doesn't have 'yield from'")
+ self.check_coverage("""\
+ def gen(inp):
+ i = 2
+ for n in inp:
+ i = 4
+ yield from range(3)
+ i = 6
+ i = 7
+
+ 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):
"""Miscellaneous arc-measuring tests."""
diff --git a/tests/test_coverage.py b/tests/test_coverage.py
index 9e2a444c..3a27fab3 100644
--- a/tests/test_coverage.py
+++ b/tests/test_coverage.py
@@ -100,7 +100,7 @@ class BasicCoverageTest(CoverageTest):
# Nothing here
d = 6
""",
- [1,2,4,6], report="4 0 100%")
+ [1,2,4,6], report="4 0 0 0 100%")
def test_indentation_wackiness(self):
# Partial final lines are OK.
@@ -617,7 +617,8 @@ class CompoundStatementTest(CoverageTest):
z = 7
assert x == 3
""",
- [1,2,3,4,5,7,8], "4-7", report="7 3 57% 4-7")
+ [1,2,3,4,5,7,8], "4-7", report="7 3 4 1 45% 4-7, 2->4",
+ )
self.check_coverage("""\
a = 1; b = 2; c = 3;
if a != 1:
@@ -628,7 +629,8 @@ class CompoundStatementTest(CoverageTest):
z = 7
assert y == 5
""",
- [1,2,3,4,5,7,8], "3, 7", report="7 2 71% 3, 7")
+ [1,2,3,4,5,7,8], "3, 7", report="7 2 4 2 64% 3, 7, 2->3, 4->7",
+ )
self.check_coverage("""\
a = 1; b = 2; c = 3;
if a != 1:
@@ -639,7 +641,8 @@ class CompoundStatementTest(CoverageTest):
z = 7
assert z == 7
""",
- [1,2,3,4,5,7,8], "3, 5", report="7 2 71% 3, 5")
+ [1,2,3,4,5,7,8], "3, 5", report="7 2 4 2 64% 3, 5, 2->3, 4->5",
+ )
def test_elif_no_else(self):
self.check_coverage("""\
@@ -650,7 +653,8 @@ class CompoundStatementTest(CoverageTest):
y = 5
assert x == 3
""",
- [1,2,3,4,5,6], "4-5", report="6 2 67% 4-5")
+ [1,2,3,4,5,6], "4-5", report="6 2 4 1 50% 4-5, 2->4",
+ )
self.check_coverage("""\
a = 1; b = 2; c = 3;
if a != 1:
@@ -659,7 +663,8 @@ class CompoundStatementTest(CoverageTest):
y = 5
assert y == 5
""",
- [1,2,3,4,5,6], "3", report="6 1 83% 3")
+ [1,2,3,4,5,6], "3", report="6 1 4 2 70% 3, 2->3, 4->6",
+ )
def test_elif_bizarre(self):
self.check_coverage("""\