diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2009-11-22 19:51:55 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2009-11-22 19:51:55 -0500 |
commit | d8775b5f8dfbc4f47c78ac50f0947bafe4b77744 (patch) | |
tree | 6b08d551993b7cfc1e854e27c80674165dc4cf59 /test/test_coverage.py | |
parent | 411d1943e5cb901a3d65dbb263f26ed606942c25 (diff) | |
download | python-coveragepy-git-d8775b5f8dfbc4f47c78ac50f0947bafe4b77744.tar.gz |
Add a test for leaking memory in the C extension. Windows only for now, kind of experimental.
Diffstat (limited to 'test/test_coverage.py')
-rw-r--r-- | test/test_coverage.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/test_coverage.py b/test/test_coverage.py index 093065f8..e8f5c745 100644 --- a/test/test_coverage.py +++ b/test/test_coverage.py @@ -9,6 +9,7 @@ coverage.use_cache(0) sys.path.insert(0, os.path.split(__file__)[0]) # Force relative import for Py3k from coveragetest import CoverageTest +import osinfo class BasicCoverageTest(CoverageTest): @@ -1730,6 +1731,36 @@ class RecursionTest(CoverageTest): [1,2,3,5,7], "") +class MemoryLeakTest(CoverageTest): + """Attempt the impossible: test that memory doesn't leak.""" + + def test_for_leaks(self): + lines = list(range(301, 315)) + lines.remove(306) + baseline_ram = osinfo.process_ram() + # Ugly string mumbo jumbo to get 300 blank lines at the beginning.. + self.check_coverage("""\ + # blank line\n""" * 300 + """\ + def once(x): + if x % 100 == 0: + raise Exception("100!") + elif x % 2: + return 10 + else: + return 11 + i = 0 # Portable loop without alloc'ing memory. + while i < 10000: + try: + once(i) + except: + pass + i += 1 + """, + lines, "") + ram_growth = osinfo.process_ram() - baseline_ram + self.assert_(ram_growth < 100000, "RAM grew by %d" % (ram_growth)) + + class PyexpatTest(CoverageTest): """Pyexpat screws up tracing. Make sure we've counter-defended properly.""" |