summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBen Finney <ben@benfinney.id.au>2011-07-27 13:08:39 +1000
committerBen Finney <ben@benfinney.id.au>2011-07-27 13:08:39 +1000
commitd9318b840bec37c116d5ef95ac1a618149f625da (patch)
tree305c374ca027499889a059f1809beb60dabdbdd6 /test
parentca7a10dff148fdb68f577f09e1f572f8350491b3 (diff)
parent0f1b0d30e306ad35b1e29912e0613e9bf2618c47 (diff)
downloadpython-coveragepy-d9318b840bec37c116d5ef95ac1a618149f625da.tar.gz
Refactor handling of static report files to a separate function.
Diffstat (limited to 'test')
-rw-r--r--test/coveragetest.py3
-rw-r--r--test/farm/html/run_b_branch.py6
-rw-r--r--test/farm/html/src/b.py19
-rw-r--r--test/test_arcs.py19
4 files changed, 33 insertions, 14 deletions
diff --git a/test/coveragetest.py b/test/coveragetest.py
index a94f512..3242e52 100644
--- a/test/coveragetest.py
+++ b/test/coveragetest.py
@@ -32,6 +32,9 @@ class CoverageTest(TestCase):
run_in_temp_dir = True
def setUp(self):
+ # Tell newer unittest implementations to print long helpful messages.
+ self.longMessage = True
+
# tearDown will restore the original sys.path
self.old_syspath = sys.path[:]
diff --git a/test/farm/html/run_b_branch.py b/test/farm/html/run_b_branch.py
index f129e43..3154339 100644
--- a/test/farm/html/run_b_branch.py
+++ b/test/farm/html/run_b_branch.py
@@ -15,14 +15,14 @@ compare("gold_b_branch", "html_b_branch", size_within=10, file_pattern="*.html")
contains("html_b_branch/b.html",
"<span class='key'>if</span> <span class='nam'>x</span> <span class='op'>&lt;</span> <span class='num'>2</span>",
"&nbsp; &nbsp; <span class='nam'>a</span> <span class='op'>=</span> <span class='num'>3</span>",
- "<span class='pc_cov'>76%</span>",
+ "<span class='pc_cov'>70%</span>",
"<span class='annotate' title='no jump to this line number'>8</span>",
"<span class='annotate' title='no jump to this line number'>exit</span>",
- "<span class='annotate' title='no jumps to these line numbers'>25&nbsp;&nbsp; 26</span>",
+ "<span class='annotate' title='no jumps to these line numbers'>23&nbsp;&nbsp; 25</span>",
)
contains("html_b_branch/index.html",
"<a href='b.html'>b</a>",
- "<span class='pc_cov'>76%</span>"
+ "<span class='pc_cov'>70%</span>"
)
clean("html_b_branch")
diff --git a/test/farm/html/src/b.py b/test/farm/html/src/b.py
index dffdd50..3bf73a9 100644
--- a/test/farm/html/src/b.py
+++ b/test/farm/html/src/b.py
@@ -16,13 +16,14 @@ def two(x):
two(1)
-def three_way():
- # for-else can be a three-way branch.
- for i in range(10):
- if i == 3:
- break
- else:
- return 23
- return 17
+def three():
+ try:
+ # This if has two branches, *neither* one taken.
+ if name_error_this_variable_doesnt_exist:
+ a = 1
+ else:
+ a = 2
+ except:
+ pass
-three_way()
+three()
diff --git a/test/test_arcs.py b/test/test_arcs.py
index 0c16929..2c98317 100644
--- a/test/test_arcs.py
+++ b/test/test_arcs.py
@@ -213,12 +213,12 @@ class LoopArcTest(CoverageTest):
i += 1
assert a == 4 and i == 3
""",
- arcz=".1 12 23 27 34 45 36 63 57 7.",
+ arcz=".1 12 23 34 45 36 63 57 7.",
)
# With "while True", 2.x thinks it's computation, 3.x thinks it's
# constant.
if sys.version_info >= (3, 0):
- arcz = ".1 12 23 27 34 45 36 63 57 7."
+ arcz = ".1 12 23 34 45 36 63 57 7."
else:
arcz = ".1 12 23 27 34 45 36 62 57 7."
self.check_coverage("""\
@@ -260,6 +260,21 @@ class LoopArcTest(CoverageTest):
arcz_missing="26 6."
)
+ def test_for_else(self):
+ self.check_coverage("""\
+ def forelse(seq):
+ for n in seq:
+ if n > 5:
+ break
+ else:
+ print('None of the values were greater than 5')
+ print('Done')
+ forelse([1,2])
+ forelse([1,6])
+ """,
+ arcz=".1 .2 23 32 34 47 26 67 7. 18 89 9."
+ )
+
class ExceptionArcTest(CoverageTest):
"""Arc-measuring tests involving exception handling."""