File: gcmemtest.py

package info (click to toggle)
python-enable 4.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 7,220 kB
  • sloc: cpp: 57,417; python: 28,437; makefile: 314; sh: 43
file content (44 lines) | stat: -rwxr-xr-x 1,062 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""
Test for memory leak in the wx image backend.
"""

import unittest, sys
import gc as garbagecollector

from kiva.image import GraphicsContext, GraphicsContextSystem
from etsdevtools.debug.memusage import get_mem_usage

class test_agg(unittest.TestCase):
    def check_agg_mem_leak(self):
        pre = get_mem_usage()
        gc = GraphicsContext((500,500))
        del gc
        garbagecollector.collect()
        post = get_mem_usage()
        assert (pre == post)

    def check_wx_mem_leak(self):
        pre = get_mem_usage()
        gc = GraphicsContextSystem((500,500))
        del gc
        garbagecollector.collect()
        post = get_mem_usage()
        assert (pre == post)



def test_suite(level=1):
    suites = []
    if level > 0:
        suites.append( unittest.makeSuite(test_agg,'check_') )
    total_suite = unittest.TestSuite(suites)
    return total_suite

def test(level=10):
    all_tests = test_suite(level)
    runner = unittest.TextTestRunner()
    runner.run(all_tests)
    return runner

if __name__ == "__main__":
    test()