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 | e1b2f88ede6938da498a765144f96a3e1156abb9 (patch) | |
tree | 080d0bd73cb6b476a7588ae4333a66ff0cd4a554 /test/test_coverage.py | |
parent | 6c3f3297a65a14dc7afbb1d18257c400f0b70042 (diff) | |
download | python-coveragepy-e1b2f88ede6938da498a765144f96a3e1156abb9.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 093065f..e8f5c74 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.""" |