diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2011-03-15 18:10:07 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2011-03-15 18:10:07 -0400 |
commit | d7048938a9234e91cb9b2fac69652f38e9b0ec95 (patch) | |
tree | 64e96120b179a3cd64692a7b1b8e592a5a55a0ed | |
parent | d1feae87031c974cdd6c7d202c289804909911e7 (diff) | |
parent | bdd144d86aacc204d7808cb9392a7a06aaeb624a (diff) | |
download | python-coveragepy-git-d7048938a9234e91cb9b2fac69652f38e9b0ec95.tar.gz |
Automated merge with ssh://bitbucket.org/ned/coveragepy
-rw-r--r-- | test/test_coverage.py | 82 |
1 files changed, 51 insertions, 31 deletions
diff --git a/test/test_coverage.py b/test/test_coverage.py index 31f3aa17..5c35e12c 100644 --- a/test/test_coverage.py +++ b/test/test_coverage.py @@ -140,12 +140,33 @@ class SimpleStatementTest(CoverageTest): """Testing simple single-line statements.""" def test_expression(self): + # Bare expressions as statements are tricky: some implementations + # optimize some of them away. All implementations seem to count + # the implicit return at the end as executable. + self.check_coverage("""\ + 12 + 23 + """, + ([1,2],[2]), "") + self.check_coverage("""\ + 12 + 23 + a = 3 + """, + ([1,2,3],[3]), "") self.check_coverage("""\ 1 + 2 1 + \\ 2 """, - [1,2], "") + ([1,2], [2]), "") + self.check_coverage("""\ + 1 + 2 + 1 + \\ + 2 + a = 4 + """, + ([1,2,4], [4]), "") def test_assert(self): self.check_coverage("""\ @@ -382,35 +403,34 @@ class SimpleStatementTest(CoverageTest): """, [1,2,3,4,5], "4") - if 0: - # Peephole optimization of jumps to jumps can mean that some statements - # never hit the line tracer. The behavior is different in different - # versions of Python, so don't run this test: - def test_strange_unexecuted_continue(self): - self.check_coverage("""\ - a = b = c = 0 - for n in range(100): - if n % 2: - if n % 4: - a += 1 - continue # <-- This line may not be hit. - else: - b += 1 - c += 1 - assert a == 50 and b == 50 and c == 50 - - a = b = c = 0 - for n in range(100): - if n % 2: - if n % 3: - a += 1 - continue # <-- This line is always hit. - else: - b += 1 - c += 1 - assert a == 33 and b == 50 and c == 50 - """, - [1,2,3,4,5,6,8,9,10, 12,13,14,15,16,17,19,20,21], "") + # Peephole optimization of jumps to jumps can mean that some statements + # never hit the line tracer. The behavior is different in different + # versions of Python, so don't run this test: + def test_strange_unexecuted_continue(self): + self.check_coverage("""\ + a = b = c = 0 + for n in range(100): + if n % 2: + if n % 4: + a += 1 + continue # <-- This line may not be hit. + else: + b += 1 + c += 1 + assert a == 50 and b == 50 and c == 50 + + a = b = c = 0 + for n in range(100): + if n % 2: + if n % 3: + a += 1 + continue # <-- This line is always hit. + else: + b += 1 + c += 1 + assert a == 33 and b == 50 and c == 50 + """, + [1,2,3,4,5,6,8,9,10, 12,13,14,15,16,17,19,20,21], "") def test_import(self): self.check_coverage("""\ @@ -560,7 +580,7 @@ class SimpleStatementTest(CoverageTest): c = 6 assert (a,b,c) == (1,3,6) """, - ([1,3,5,6,7], [1,3,4,5,6,7]), "") + ([1,3,6,7], [1,3,5,6,7], [1,3,4,5,6,7]), "") class CompoundStatementTest(CoverageTest): |