Python sys.gettotalrefcount() Examples

The following are code examples for showing how to use sys.gettotalrefcount(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the ones you don't like. You can also save this page to your account.

Example 1
Project: deb-python-functools32   Author: openstack   File: test_functools32.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    test_classes = (
        TestPartial,
        TestPartialSubclass,
        TestPythonPartial,
        TestUpdateWrapper,
        TestTotalOrdering,
        TestCmpToKey,
        TestWraps,
        TestReduce,
        TestLRU,
        TestOrderedDict,
    )
    support.run_unittest(*test_classes)

    # verify reference counting
    if verbose and hasattr(sys, "gettotalrefcount"):
        import gc
        counts = [None] * 5
        for i in range(len(counts)):
            support.run_unittest(*test_classes)
            gc.collect()
            counts[i] = sys.gettotalrefcount()
        print(counts) 
Example 2
Project: purelove   Author: hucmosin   File: pywin32_testutil.py    (license) View Source Project 6 votes vote down vote up
def _do_leak_tests(self, result = None):
        try:
            gtrc = sys.gettotalrefcount
        except AttributeError:
            return # can't do leak tests in this build
        # Assume already called once, to prime any caches etc
        gc.collect()
        trc = gtrc()
        for i in range(self.num_leak_iters):
            self.real_test(result)
            if result.shouldStop:
                break
        del i # created after we remembered the refcount!
        # int division here means one or 2 stray references won't force 
        # failure, but one per loop
        gc.collect()
        lost = (gtrc() - trc) // self.num_leak_iters
        if lost < 0:
            msg = "LeakTest: %s appeared to gain %d references!!" % (self.real_test, -lost)
            result.addFailure(self.real_test, (AssertionError, msg, None))
        if lost > 0:
            msg = "LeakTest: %s lost %d references" % (self.real_test, lost)
            exc = AssertionError(msg)
            result.addFailure(self.real_test, (exc.__class__, exc, None)) 
Example 3
Project: OSPTF   Author: xSploited   File: testPippo.py    (license) View Source Project 6 votes vote down vote up
def testLeaks(self):
        try:
            gtrc = sys.gettotalrefcount
        except AttributeError:
            print "Please run this with python_d for leak tests"
            gtrc = lambda: 0
        # note creating self.object() should have consumed our "one time" leaks
        self.object.Method1()
        start = gtrc()
        for i in range(1000):
            object = Dispatch("Python.Test.Pippo")
            object.Method1()
        object = None
        end = gtrc()
        if end-start > 5:
            self.fail("We lost %d references!" % (end-start,)) 
Example 4
Project: OSPTF   Author: xSploited   File: testPippo.py    (license) View Source Project 6 votes vote down vote up
def testLeaksGencache(self):
        try:
            gtrc = sys.gettotalrefcount
        except AttributeError:
            print "Please run this with python_d for leak tests"
            gtrc = lambda: 0
        # note creating self.object() should have consumed our "one time" leaks
        object = EnsureDispatch("Python.Test.Pippo")
        start = gtrc()
        for i in range(1000):
            object = EnsureDispatch("Python.Test.Pippo")
            object.Method1()
        object = None
        end = gtrc()
        if end-start > 10:
            self.fail("We lost %d references!" % (end-start,)) 
Example 5
Project: pupy   Author: ru-faraon   File: testPippo.py    (license) View Source Project 6 votes vote down vote up
def testLeaks(self):
        try:
            gtrc = sys.gettotalrefcount
        except AttributeError:
            print "Please run this with python_d for leak tests"
            gtrc = lambda: 0
        # note creating self.object() should have consumed our "one time" leaks
        self.object.Method1()
        start = gtrc()
        for i in range(1000):
            object = Dispatch("Python.Test.Pippo")
            object.Method1()
        object = None
        end = gtrc()
        if end-start > 5:
            self.fail("We lost %d references!" % (end-start,)) 
Example 6
Project: pupy   Author: ru-faraon   File: testPippo.py    (license) View Source Project 6 votes vote down vote up
def testLeaksGencache(self):
        try:
            gtrc = sys.gettotalrefcount
        except AttributeError:
            print "Please run this with python_d for leak tests"
            gtrc = lambda: 0
        # note creating self.object() should have consumed our "one time" leaks
        object = EnsureDispatch("Python.Test.Pippo")
        start = gtrc()
        for i in range(1000):
            object = EnsureDispatch("Python.Test.Pippo")
            object.Method1()
        object = None
        end = gtrc()
        if end-start > 10:
            self.fail("We lost %d references!" % (end-start,)) 
Example 7
Project: zippy   Author: securesystemslab   File: test_operator.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    import sys
    test_classes = (
        OperatorTestCase,
    )

    support.run_unittest(*test_classes)

    # verify reference counting
    if verbose and hasattr(sys, "gettotalrefcount"):
        import gc
        counts = [None] * 5
        for i in range(len(counts)):
            support.run_unittest(*test_classes)
            gc.collect()
            counts[i] = sys.gettotalrefcount()
        print(counts) 
Example 8
Project: zippy   Author: securesystemslab   File: test_sort.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    test_classes = (
        TestBase,
        TestDecorateSortUndecorate,
        TestBugs,
    )

    support.run_unittest(*test_classes)

    # verify reference counting
    if verbose and hasattr(sys, "gettotalrefcount"):
        import gc
        counts = [None] * 5
        for i in range(len(counts)):
            support.run_unittest(*test_classes)
            gc.collect()
            counts[i] = sys.gettotalrefcount()
        print(counts) 
Example 9
Project: zippy   Author: securesystemslab   File: test_functools.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    test_classes = (
        TestPartial,
        TestPartialSubclass,
        TestPythonPartial,
        TestUpdateWrapper,
        TestTotalOrdering,
        TestCmpToKey,
        TestWraps,
        TestReduce,
        TestLRU,
    )
    support.run_unittest(*test_classes)

    # verify reference counting
    if verbose and hasattr(sys, "gettotalrefcount"):
        import gc
        counts = [None] * 5
        for i in range(len(counts)):
            support.run_unittest(*test_classes)
            gc.collect()
            counts[i] = sys.gettotalrefcount()
        print(counts) 
Example 10
Project: zippy   Author: securesystemslab   File: test_sys.py    (license) View Source Project 6 votes vote down vote up
def setUp(self):
        self.c = len(struct.pack('c', b' '))
        self.H = len(struct.pack('H', 0))
        self.i = len(struct.pack('i', 0))
        self.l = len(struct.pack('l', 0))
        self.P = len(struct.pack('P', 0))
        # due to missing size_t information from struct, it is assumed that
        # sizeof(Py_ssize_t) = sizeof(void*)
        self.header = 'PP'
        self.vheader = self.header + 'P'
        if hasattr(sys, "gettotalrefcount"):
            self.header += '2P'
            self.vheader += '2P'
        self.longdigit = sys.int_info.sizeof_digit
        import _testcapi
        self.gc_headsize = _testcapi.SIZEOF_PYGC_HEAD
        self.file = open(test.support.TESTFN, 'wb') 
Example 11
Project: zippy   Author: securesystemslab   File: test_deque.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    import sys
    test_classes = (
        TestBasic,
        TestVariousIteratorArgs,
        TestSubclass,
        TestSubclassWithKwargs,
    )

    support.run_unittest(*test_classes)

    # verify reference counting
    if verbose and hasattr(sys, "gettotalrefcount"):
        import gc
        counts = [None] * 5
        for i in range(len(counts)):
            support.run_unittest(*test_classes)
            gc.collect()
            counts[i] = sys.gettotalrefcount()
        print(counts)

    # doctests
    from test import test_deque
    support.run_doctest(test_deque, verbose) 
Example 12
Project: zippy   Author: securesystemslab   File: test_itertools.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    test_classes = (TestBasicOps, TestVariousIteratorArgs, TestGC,
                    RegressionTests, LengthTransparency,
                    SubclassWithKwargsTest, TestExamples)
    support.run_unittest(*test_classes)

    # verify reference counting
    if verbose and hasattr(sys, "gettotalrefcount"):
        import gc
        counts = [None] * 5
        for i in range(len(counts)):
            support.run_unittest(*test_classes)
            gc.collect()
            counts[i] = sys.gettotalrefcount()
        print(counts)

    # doctest the examples in the library reference
    support.run_doctest(sys.modules[__name__], verbose) 
Example 13
Project: zippy   Author: securesystemslab   File: test_bisect.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    from test import test_bisect

    test_classes = [TestBisectPython, TestBisectC,
                    TestInsortPython, TestInsortC,
                    TestErrorHandlingPython, TestErrorHandlingC]

    support.run_unittest(*test_classes)
    support.run_doctest(test_bisect, verbose)

    # verify reference counting
    if verbose and hasattr(sys, "gettotalrefcount"):
        import gc
        counts = [None] * 5
        for i in range(len(counts)):
            support.run_unittest(*test_classes)
            gc.collect()
            counts[i] = sys.gettotalrefcount()
        print(counts) 
Example 14
Project: oil   Author: oilshell   File: test_operator.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    import sys
    test_classes = (
        OperatorTestCase,
    )

    test_support.run_unittest(*test_classes)

    # verify reference counting
    if verbose and hasattr(sys, "gettotalrefcount"):
        import gc
        counts = [None] * 5
        for i in xrange(len(counts)):
            test_support.run_unittest(*test_classes)
            gc.collect()
            counts[i] = sys.gettotalrefcount()
        print counts 
Example 15
Project: oil   Author: oilshell   File: test_peepholer.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    import sys
    from test import test_support
    test_classes = (TestTranforms,)

    with test_support.check_py3k_warnings(
            ("backquote not supported", SyntaxWarning)):
        test_support.run_unittest(*test_classes)

        # verify reference counting
        if verbose and hasattr(sys, "gettotalrefcount"):
            import gc
            counts = [None] * 5
            for i in xrange(len(counts)):
                test_support.run_unittest(*test_classes)
                gc.collect()
                counts[i] = sys.gettotalrefcount()
            print counts 
Example 16
Project: oil   Author: oilshell   File: test_sort.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    test_classes = (
        TestBase,
        TestDecorateSortUndecorate,
        TestBugs,
    )

    with test_support.check_py3k_warnings(
            ("the cmp argument is not supported", DeprecationWarning)):
        test_support.run_unittest(*test_classes)

        # verify reference counting
        if verbose and hasattr(sys, "gettotalrefcount"):
            import gc
            counts = [None] * 5
            for i in xrange(len(counts)):
                test_support.run_unittest(*test_classes)
                gc.collect()
                counts[i] = sys.gettotalrefcount()
            print counts 
Example 17
Project: oil   Author: oilshell   File: test_functools.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    test_classes = (
        TestPartial,
        TestPartialSubclass,
        TestPythonPartial,
        TestUpdateWrapper,
        TestTotalOrdering,
        TestWraps,
        TestReduce,
    )
    test_support.run_unittest(*test_classes)

    # verify reference counting
    if verbose and hasattr(sys, "gettotalrefcount"):
        import gc
        counts = [None] * 5
        for i in xrange(len(counts)):
            test_support.run_unittest(*test_classes)
            gc.collect()
            counts[i] = sys.gettotalrefcount()
        print counts 
Example 18
Project: oil   Author: oilshell   File: test_random.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    testclasses =    [WichmannHill_TestBasicOps,
                      MersenneTwister_TestBasicOps,
                      TestDistributions,
                      TestModule]

    try:
        random.SystemRandom().random()
    except NotImplementedError:
        pass
    else:
        testclasses.append(SystemRandom_TestBasicOps)

    test_support.run_unittest(*testclasses)

    # verify reference counting
    import sys
    if verbose and hasattr(sys, "gettotalrefcount"):
        counts = [None] * 5
        for i in xrange(len(counts)):
            test_support.run_unittest(*testclasses)
            counts[i] = sys.gettotalrefcount()
        print counts 
Example 19
Project: oil   Author: oilshell   File: test_itertools.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    test_classes = (TestBasicOps, TestVariousIteratorArgs, TestGC,
                    RegressionTests, LengthTransparency,
                    SubclassWithKwargsTest, TestExamples)
    test_support.run_unittest(*test_classes)

    # verify reference counting
    if verbose and hasattr(sys, "gettotalrefcount"):
        import gc
        counts = [None] * 5
        for i in xrange(len(counts)):
            test_support.run_unittest(*test_classes)
            gc.collect()
            counts[i] = sys.gettotalrefcount()
        print counts

    # doctest the examples in the library reference
    test_support.run_doctest(sys.modules[__name__], verbose) 
Example 20
Project: oil   Author: oilshell   File: test_builtin.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    global numruns
    if not numruns:
        with check_py3k_warnings(
                (".+ not supported in 3.x", DeprecationWarning)):
            run_unittest(TestExecFile)
    numruns += 1
    test_classes = (BuiltinTest, TestSorted, TestType)

    _run_unittest(*test_classes)

    # verify reference counting
    if verbose and hasattr(sys, "gettotalrefcount"):
        import gc
        counts = [None] * 5
        for i in xrange(len(counts)):
            _run_unittest(*test_classes)
            gc.collect()
            counts[i] = sys.gettotalrefcount()
        print counts 
Example 21
Project: python2-tracer   Author: extremecoders-re   File: test_operator.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    import sys
    test_classes = (
        OperatorTestCase,
    )

    test_support.run_unittest(*test_classes)

    # verify reference counting
    if verbose and hasattr(sys, "gettotalrefcount"):
        import gc
        counts = [None] * 5
        for i in xrange(len(counts)):
            test_support.run_unittest(*test_classes)
            gc.collect()
            counts[i] = sys.gettotalrefcount()
        print counts 
Example 22
Project: python2-tracer   Author: extremecoders-re   File: test_peepholer.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    import sys
    from test import test_support
    test_classes = (TestTranforms,)

    with test_support.check_py3k_warnings(
            ("backquote not supported", SyntaxWarning)):
        test_support.run_unittest(*test_classes)

        # verify reference counting
        if verbose and hasattr(sys, "gettotalrefcount"):
            import gc
            counts = [None] * 5
            for i in xrange(len(counts)):
                test_support.run_unittest(*test_classes)
                gc.collect()
                counts[i] = sys.gettotalrefcount()
            print counts 
Example 23
Project: python2-tracer   Author: extremecoders-re   File: test_sort.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    test_classes = (
        TestBase,
        TestDecorateSortUndecorate,
        TestBugs,
    )

    with test_support.check_py3k_warnings(
            ("the cmp argument is not supported", DeprecationWarning)):
        test_support.run_unittest(*test_classes)

        # verify reference counting
        if verbose and hasattr(sys, "gettotalrefcount"):
            import gc
            counts = [None] * 5
            for i in xrange(len(counts)):
                test_support.run_unittest(*test_classes)
                gc.collect()
                counts[i] = sys.gettotalrefcount()
            print counts 
Example 24
Project: python2-tracer   Author: extremecoders-re   File: test_functools.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    test_classes = (
        TestPartial,
        TestPartialSubclass,
        TestPythonPartial,
        TestUpdateWrapper,
        TestTotalOrdering,
        TestWraps,
        TestReduce,
    )
    test_support.run_unittest(*test_classes)

    # verify reference counting
    if verbose and hasattr(sys, "gettotalrefcount"):
        import gc
        counts = [None] * 5
        for i in xrange(len(counts)):
            test_support.run_unittest(*test_classes)
            gc.collect()
            counts[i] = sys.gettotalrefcount()
        print counts 
Example 25
Project: python2-tracer   Author: extremecoders-re   File: test_random.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    testclasses =    [WichmannHill_TestBasicOps,
                      MersenneTwister_TestBasicOps,
                      TestDistributions,
                      TestModule]

    try:
        random.SystemRandom().random()
    except NotImplementedError:
        pass
    else:
        testclasses.append(SystemRandom_TestBasicOps)

    test_support.run_unittest(*testclasses)

    # verify reference counting
    import sys
    if verbose and hasattr(sys, "gettotalrefcount"):
        counts = [None] * 5
        for i in xrange(len(counts)):
            test_support.run_unittest(*testclasses)
            counts[i] = sys.gettotalrefcount()
        print counts 
Example 26
Project: python2-tracer   Author: extremecoders-re   File: test_itertools.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    test_classes = (TestBasicOps, TestVariousIteratorArgs, TestGC,
                    RegressionTests, LengthTransparency,
                    SubclassWithKwargsTest, TestExamples)
    test_support.run_unittest(*test_classes)

    # verify reference counting
    if verbose and hasattr(sys, "gettotalrefcount"):
        import gc
        counts = [None] * 5
        for i in xrange(len(counts)):
            test_support.run_unittest(*test_classes)
            gc.collect()
            counts[i] = sys.gettotalrefcount()
        print counts

    # doctest the examples in the library reference
    test_support.run_doctest(sys.modules[__name__], verbose) 
Example 27
Project: python2-tracer   Author: extremecoders-re   File: test_builtin.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    global numruns
    if not numruns:
        with check_py3k_warnings(
                (".+ not supported in 3.x", DeprecationWarning)):
            run_unittest(TestExecFile)
    numruns += 1
    test_classes = (BuiltinTest, TestSorted, TestType)

    _run_unittest(*test_classes)

    # verify reference counting
    if verbose and hasattr(sys, "gettotalrefcount"):
        import gc
        counts = [None] * 5
        for i in xrange(len(counts)):
            _run_unittest(*test_classes)
            gc.collect()
            counts[i] = sys.gettotalrefcount()
        print counts 
Example 28
Project: web_ctp   Author: molebot   File: test_operator.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    import sys
    test_classes = (
        OperatorTestCase,
    )

    support.run_unittest(*test_classes)

    # verify reference counting
    if verbose and hasattr(sys, "gettotalrefcount"):
        import gc
        counts = [None] * 5
        for i in range(len(counts)):
            support.run_unittest(*test_classes)
            gc.collect()
            counts[i] = sys.gettotalrefcount()
        print(counts) 
Example 29
Project: web_ctp   Author: molebot   File: test_sort.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    test_classes = (
        TestBase,
        TestDecorateSortUndecorate,
        TestBugs,
    )

    support.run_unittest(*test_classes)

    # verify reference counting
    if verbose and hasattr(sys, "gettotalrefcount"):
        import gc
        counts = [None] * 5
        for i in range(len(counts)):
            support.run_unittest(*test_classes)
            gc.collect()
            counts[i] = sys.gettotalrefcount()
        print(counts) 
Example 30
Project: web_ctp   Author: molebot   File: test_deque.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    import sys
    test_classes = (
        TestBasic,
        TestVariousIteratorArgs,
        TestSubclass,
        TestSubclassWithKwargs,
    )

    support.run_unittest(*test_classes)

    # verify reference counting
    if verbose and hasattr(sys, "gettotalrefcount"):
        import gc
        counts = [None] * 5
        for i in range(len(counts)):
            support.run_unittest(*test_classes)
            gc.collect()
            counts[i] = sys.gettotalrefcount()
        print(counts)

    # doctests
    from test import test_deque
    support.run_doctest(test_deque, verbose) 
Example 31
Project: web_ctp   Author: molebot   File: test_itertools.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    test_classes = (TestBasicOps, TestVariousIteratorArgs, TestGC,
                    RegressionTests, LengthTransparency,
                    SubclassWithKwargsTest, TestExamples)
    support.run_unittest(*test_classes)

    # verify reference counting
    if verbose and hasattr(sys, "gettotalrefcount"):
        import gc
        counts = [None] * 5
        for i in range(len(counts)):
            support.run_unittest(*test_classes)
            gc.collect()
            counts[i] = sys.gettotalrefcount()
        print(counts)

    # doctest the examples in the library reference
    support.run_doctest(sys.modules[__name__], verbose) 
Example 32
Project: web_ctp   Author: molebot   File: test_csv.py    (license) View Source Project 6 votes vote down vote up
def test_write(self):
            delta = 0
            rows = [[1,2,3]]*5
            s = NUL()
            lastrc = sys.gettotalrefcount()
            for i in range(20):
                gc.collect()
                self.assertEqual(gc.garbage, [])
                rc = sys.gettotalrefcount()
                writer = csv.writer(s)
                for row in rows:
                    writer.writerow(row)
                delta = rc-lastrc
                lastrc = rc
            # if writer leaks during write, last delta should be 5 or more
            self.assertEqual(delta < 5, True) 
Example 33
Project: remoteControlPPT   Author: htwenning   File: pywin32_testutil.py    (license) View Source Project 6 votes vote down vote up
def _do_leak_tests(self, result = None):
        try:
            gtrc = sys.gettotalrefcount
        except AttributeError:
            return # can't do leak tests in this build
        # Assume already called once, to prime any caches etc
        gc.collect()
        trc = gtrc()
        for i in range(self.num_leak_iters):
            self.real_test(result)
            if result.shouldStop:
                break
        del i # created after we remembered the refcount!
        # int division here means one or 2 stray references won't force 
        # failure, but one per loop
        gc.collect()
        lost = (gtrc() - trc) // self.num_leak_iters
        if lost < 0:
            msg = "LeakTest: %s appeared to gain %d references!!" % (self.real_test, -lost)
            result.addFailure(self.real_test, (AssertionError, msg, None))
        if lost > 0:
            msg = "LeakTest: %s lost %d references" % (self.real_test, lost)
            exc = AssertionError(msg)
            result.addFailure(self.real_test, (exc.__class__, exc, None)) 
Example 34
Project: remoteControlPPT   Author: htwenning   File: testPippo.py    (license) View Source Project 6 votes vote down vote up
def testLeaks(self):
        try:
            gtrc = sys.gettotalrefcount
        except AttributeError:
            print "Please run this with python_d for leak tests"
            gtrc = lambda: 0
        # note creating self.object() should have consumed our "one time" leaks
        self.object.Method1()
        start = gtrc()
        for i in range(1000):
            object = Dispatch("Python.Test.Pippo")
            object.Method1()
        object = None
        end = gtrc()
        if end-start > 5:
            self.fail("We lost %d references!" % (end-start,)) 
Example 35
Project: remoteControlPPT   Author: htwenning   File: testPippo.py    (license) View Source Project 6 votes vote down vote up
def testLeaksGencache(self):
        try:
            gtrc = sys.gettotalrefcount
        except AttributeError:
            print "Please run this with python_d for leak tests"
            gtrc = lambda: 0
        # note creating self.object() should have consumed our "one time" leaks
        object = EnsureDispatch("Python.Test.Pippo")
        start = gtrc()
        for i in range(1000):
            object = EnsureDispatch("Python.Test.Pippo")
            object.Method1()
        object = None
        end = gtrc()
        if end-start > 10:
            self.fail("We lost %d references!" % (end-start,)) 
Example 36
Project: CodeReader   Author: jasonrbr   File: pywin32_testutil.py    (license) View Source Project 6 votes vote down vote up
def _do_leak_tests(self, result = None):
        try:
            gtrc = sys.gettotalrefcount
        except AttributeError:
            return # can't do leak tests in this build
        # Assume already called once, to prime any caches etc
        gc.collect()
        trc = gtrc()
        for i in range(self.num_leak_iters):
            self.real_test(result)
            if result.shouldStop:
                break
        del i # created after we remembered the refcount!
        # int division here means one or 2 stray references won't force 
        # failure, but one per loop
        gc.collect()
        lost = (gtrc() - trc) // self.num_leak_iters
        if lost < 0:
            msg = "LeakTest: %s appeared to gain %d references!!" % (self.real_test, -lost)
            result.addFailure(self.real_test, (AssertionError, msg, None))
        if lost > 0:
            msg = "LeakTest: %s lost %d references" % (self.real_test, lost)
            exc = AssertionError(msg)
            result.addFailure(self.real_test, (exc.__class__, exc, None)) 
Example 37
Project: CodeReader   Author: jasonrbr   File: testPippo.py    (license) View Source Project 6 votes vote down vote up
def testLeaks(self):
        try:
            gtrc = sys.gettotalrefcount
        except AttributeError:
            print("Please run this with python_d for leak tests")
            gtrc = lambda: 0
        # note creating self.object() should have consumed our "one time" leaks
        self.object.Method1()
        start = gtrc()
        for i in range(1000):
            object = Dispatch("Python.Test.Pippo")
            object.Method1()
        object = None
        end = gtrc()
        if end-start > 5:
            self.fail("We lost %d references!" % (end-start,)) 
Example 38
Project: CodeReader   Author: jasonrbr   File: testPippo.py    (license) View Source Project 6 votes vote down vote up
def testLeaksGencache(self):
        try:
            gtrc = sys.gettotalrefcount
        except AttributeError:
            print("Please run this with python_d for leak tests")
            gtrc = lambda: 0
        # note creating self.object() should have consumed our "one time" leaks
        object = EnsureDispatch("Python.Test.Pippo")
        start = gtrc()
        for i in range(1000):
            object = EnsureDispatch("Python.Test.Pippo")
            object.Method1()
        object = None
        end = gtrc()
        if end-start > 10:
            self.fail("We lost %d references!" % (end-start,)) 
Example 39
Project: pefile.pypy   Author: cloudtracer   File: test_operator.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    import sys
    test_classes = (
        OperatorTestCase,
    )

    test_support.run_unittest(*test_classes)

    # verify reference counting
    if verbose and hasattr(sys, "gettotalrefcount"):
        import gc
        counts = [None] * 5
        for i in xrange(len(counts)):
            test_support.run_unittest(*test_classes)
            gc.collect()
            counts[i] = sys.gettotalrefcount()
        print counts 
Example 40
Project: pefile.pypy   Author: cloudtracer   File: test_peepholer.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    import sys
    from test import test_support
    test_classes = (TestTranforms,)

    with test_support.check_py3k_warnings(
            ("backquote not supported", SyntaxWarning)):
        test_support.run_unittest(*test_classes)

        # verify reference counting
        if verbose and hasattr(sys, "gettotalrefcount"):
            import gc
            counts = [None] * 5
            for i in xrange(len(counts)):
                test_support.run_unittest(*test_classes)
                gc.collect()
                counts[i] = sys.gettotalrefcount()
            print counts 
Example 41
Project: pefile.pypy   Author: cloudtracer   File: test_sort.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    test_classes = (
        TestBase,
        TestDecorateSortUndecorate,
        TestBugs,
    )

    with test_support.check_py3k_warnings(
            ("the cmp argument is not supported", DeprecationWarning)):
        test_support.run_unittest(*test_classes)

        # verify reference counting
        if verbose and hasattr(sys, "gettotalrefcount"):
            import gc
            counts = [None] * 5
            for i in xrange(len(counts)):
                test_support.run_unittest(*test_classes)
                gc.collect()
                counts[i] = sys.gettotalrefcount()
            print counts 
Example 42
Project: pefile.pypy   Author: cloudtracer   File: test_functools.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    test_classes = (
        TestPartial,
        TestPartialSubclass,
        TestPythonPartial,
        TestUpdateWrapper,
        TestTotalOrdering,
        TestWraps,
        TestReduce,
    )
    test_support.run_unittest(*test_classes)

    # verify reference counting
    if verbose and hasattr(sys, "gettotalrefcount"):
        import gc
        counts = [None] * 5
        for i in xrange(len(counts)):
            test_support.run_unittest(*test_classes)
            gc.collect()
            counts[i] = sys.gettotalrefcount()
        print counts 
Example 43
Project: pefile.pypy   Author: cloudtracer   File: test_random.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    testclasses =    [WichmannHill_TestBasicOps,
                      MersenneTwister_TestBasicOps,
                      TestDistributions,
                      TestModule]

    try:
        random.SystemRandom().random()
    except NotImplementedError:
        pass
    else:
        testclasses.append(SystemRandom_TestBasicOps)

    test_support.run_unittest(*testclasses)

    # verify reference counting
    import sys
    if verbose and hasattr(sys, "gettotalrefcount"):
        counts = [None] * 5
        for i in xrange(len(counts)):
            test_support.run_unittest(*testclasses)
            counts[i] = sys.gettotalrefcount()
        print counts 
Example 44
Project: pefile.pypy   Author: cloudtracer   File: test_itertools.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    test_classes = (TestBasicOps, TestVariousIteratorArgs, TestGC,
                    RegressionTests, LengthTransparency,
                    SubclassWithKwargsTest, TestExamples)
    test_support.run_unittest(*test_classes)

    # verify reference counting
    if verbose and hasattr(sys, "gettotalrefcount"):
        import gc
        counts = [None] * 5
        for i in xrange(len(counts)):
            test_support.run_unittest(*test_classes)
            gc.collect()
            counts[i] = sys.gettotalrefcount()
        print counts

    # doctest the examples in the library reference
    test_support.run_doctest(sys.modules[__name__], verbose) 
Example 45
Project: pefile.pypy   Author: cloudtracer   File: test_builtin.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    global numruns
    if not numruns:
        with check_py3k_warnings(
                (".+ not supported in 3.x", DeprecationWarning)):
            run_unittest(TestExecFile)
    numruns += 1
    test_classes = (BuiltinTest, TestSorted)

    _run_unittest(*test_classes)

    # verify reference counting
    if verbose and hasattr(sys, "gettotalrefcount"):
        import gc
        counts = [None] * 5
        for i in xrange(len(counts)):
            _run_unittest(*test_classes)
            gc.collect()
            counts[i] = sys.gettotalrefcount()
        print counts 
Example 46
Project: ouroboros   Author: pybee   File: test_sort.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    test_classes = (
        TestBase,
        TestDecorateSortUndecorate,
        TestBugs,
    )

    support.run_unittest(*test_classes)

    # verify reference counting
    if verbose and hasattr(sys, "gettotalrefcount"):
        import gc
        counts = [None] * 5
        for i in range(len(counts)):
            support.run_unittest(*test_classes)
            gc.collect()
            counts[i] = sys.gettotalrefcount()
        print(counts) 
Example 47
Project: ouroboros   Author: pybee   File: test_deque.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    import sys
    test_classes = (
        TestBasic,
        TestVariousIteratorArgs,
        TestSubclass,
        TestSubclassWithKwargs,
    )

    support.run_unittest(*test_classes)

    # verify reference counting
    if verbose and hasattr(sys, "gettotalrefcount"):
        import gc
        counts = [None] * 5
        for i in range(len(counts)):
            support.run_unittest(*test_classes)
            gc.collect()
            counts[i] = sys.gettotalrefcount()
        print(counts)

    # doctests
    from test import test_deque
    support.run_doctest(test_deque, verbose) 
Example 48
Project: ouroboros   Author: pybee   File: test_itertools.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    test_classes = (TestBasicOps, TestVariousIteratorArgs, TestGC,
                    RegressionTests, LengthTransparency,
                    SubclassWithKwargsTest, TestExamples,
                    SizeofTest)
    support.run_unittest(*test_classes)

    # verify reference counting
    if verbose and hasattr(sys, "gettotalrefcount"):
        import gc
        counts = [None] * 5
        for i in range(len(counts)):
            support.run_unittest(*test_classes)
            gc.collect()
            counts[i] = sys.gettotalrefcount()
        print(counts)

    # doctest the examples in the library reference
    support.run_doctest(sys.modules[__name__], verbose) 
Example 49
Project: ouroboros   Author: pybee   File: test_csv.py    (license) View Source Project 6 votes vote down vote up
def test_write(self):
        delta = 0
        rows = [[1,2,3]]*5
        s = NUL()
        lastrc = sys.gettotalrefcount()
        for i in range(20):
            gc.collect()
            self.assertEqual(gc.garbage, [])
            rc = sys.gettotalrefcount()
            writer = csv.writer(s)
            for row in rows:
                writer.writerow(row)
            delta = rc-lastrc
            lastrc = rc
        # if writer leaks during write, last delta should be 5 or more
        self.assertEqual(delta < 5, True) 
Example 50
Project: ndk-python   Author: gittor   File: test_operator.py    (license) View Source Project 6 votes vote down vote up
def test_main(verbose=None):
    import sys
    test_classes = (
        OperatorTestCase,
    )

    test_support.run_unittest(*test_classes)

    # verify reference counting
    if verbose and hasattr(sys, "gettotalrefcount"):
        import gc
        counts = [None] * 5
        for i in xrange(len(counts)):
            test_support.run_unittest(*test_classes)
            gc.collect()
            counts[i] = sys.gettotalrefcount()
        print counts