diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2010-11-06 16:49:23 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2010-11-06 16:49:23 -0400 |
commit | 3f1b714b7e767573b99fa167e62fa291738bf4e4 (patch) | |
tree | 10240229c367701d67053d93332e703a59e07367 /test/test_oddball.py | |
parent | bd9091d4b1217d6ad5271e1c6540045e22e33d21 (diff) | |
download | python-coveragepy-git-3f1b714b7e767573b99fa167e62fa291738bf4e4.tar.gz |
Detect when our trace function is yanked out from under us, and warn the user. Finishes, but does not fix, issue #93.
Diffstat (limited to 'test/test_oddball.py')
-rw-r--r-- | test/test_oddball.py | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/test/test_oddball.py b/test/test_oddball.py index 3d5bf097..e94e2bad 100644 --- a/test/test_oddball.py +++ b/test/test_oddball.py @@ -63,8 +63,9 @@ class RecursionTest(CoverageTest): return recur(n-1)+1 recur(495) # We can get at least this many stack frames. + i = 8 # and this line will be traced """, - [1,2,3,5,7], "") + [1,2,3,5,7,8], "") def test_long_recursion(self): # We can't finish a very deep recursion, but we don't crash. @@ -80,6 +81,52 @@ class RecursionTest(CoverageTest): """, [1,2,3,5,7], "") + def test_long_recursion_recovery(self): + # Test the core of bug 93: http://bitbucket.org/ned/coveragepy/issue/93 + # When recovering from a stack overflow, the Python trace function is + # disabled, but the C trace function is not. So if we're using a + # Python trace function, we won't trace anything after the stack + # overflow, and there should be a warning about it. If we're using + # the C trace function, only line 3 will be missing, and all else + # will be traced. + + self.make_file("recur.py", """\ + def recur(n): + if n == 0: + return 0 # never hit + else: + return recur(n-1)+1 + + try: + recur(100000) # This is definitely too many frames. + except RuntimeError: + i = 10 + i = 11 + """) + + cov = coverage.coverage() + cov.start() + self.import_local_file("recur") + cov.stop() + + pytrace = (cov.collector.tracer_name() == "PyTracer") + expected_missing = [3] + if pytrace: + expected_missing += [9,10,11] + + _, statements, missing, _ = cov.analysis("recur.py") + self.assertEqual(statements, [1,2,3,5,7,8,9,10,11]) + self.assertEqual(missing, expected_missing) + + # We can get a warning about the stackoverflow effect on the tracing + # function only if we have sys.gettrace + if pytrace and hasattr(sys, "gettrace"): + self.assertEqual(cov._warnings, + ["Trace function changed, measurement is likely wrong: None"] + ) + else: + self.assertEqual(cov._warnings, []) + class MemoryLeakTest(CoverageTest): """Attempt the impossible: test that memory doesn't leak.""" |