Here are the examples of the python api sys.gettotalrefcount taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
62 Examples
0
Example 51
def test_main(verbose=None):
from test import test_bisect
from types import BuiltinFunctionType
import sys
test_classes = [TestBisect, TestInsort]
if isinstance(bisect_left, BuiltinFunctionType):
test_classes.append(TestErrorHandling)
test_support.run_unittest(*test_classes)
test_support.run_doctest(test_bisect, verbose)
# 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
0
Example 52
def test_main(verbose=None):
import sys
test_classes = (
TestPartial,
TestPartialSubclass,
TestPythonPartial,
TestUpdateWrapper,
TestWraps
)
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
0
Example 53
Project: babble Source File: test_random.py
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
0
Example 54
def test_main(verbose=None):
test_classes = (
TestDecorateSortUndecorate,
TestBugs,
)
# In the following test cases, class obj, which has function that changes
# the data upon which sort is invoked, is passed for "key" argument.
# It can not be checked if that function changes data as long as it is
# invoked(e.g. __del__ in SortKiller). so these are currently commented out.
del TestDecorateSortUndecorate.test_key_with_mutating_del
del TestDecorateSortUndecorate.test_key_with_mutating_del_and_exception
#
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
0
Example 55
Project: WAPT Source File: pywin32_testutil.py
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))
0
Example 56
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)
0
Example 57
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)
0
Example 58
Project: blist Source File: unittest.py
def run_(self, result, memcheck):
if result is None: result = self.defaultTestResult()
if memcheck and not hasattr(sys, 'gettotalrefcount'):
return
result.startTest(self)
testMethod = getattr(self, self._testMethodName)
try:
import gc
total_start = 0
total_finish = 0
ok = True
gc.collect()
ob_start = set(id(x) for x in gc.get_objects())
try:
total_start = sys.gettotalrefcount()
except AttributeError:
pass
try:
self.setUp()
except KeyboardInterrupt:
raise
except:
result.addError(self, self._exc_info())
return
ok = False
try:
testMethod()
ok = True
except self.failureException:
result.addFailure(self, self._exc_info())
except KeyboardInterrupt:
raise
except:
result.addError(self, self._exc_info())
try:
self.tearDown()
if ok and memcheck:
gc.collect()
gc.collect()
total_finish = sys.gettotalrefcount()
ob_finish = gc.get_objects()
if len(ob_start) != len(ob_finish):
#for ob in ob_finish:
# if id(ob) not in ob_start and ob is not ob_start:
# print ob
raise ReferenceLeak('more objects', len(ob_finish)-len(ob_start))
if total_finish != total_start:
print(total_start, total_finish)
raise ReferenceLeak('more references', total_finish - total_start)
except KeyboardInterrupt:
raise
except:
result.addError(self, self._exc_info())
ok = False
if ok: result.addSuccess(self)
finally:
result.stopTest(self)
0
Example 59
def run(args = []):
""" Run tests and return True on failure, False otherwise """
try:
opts, args = getopt.getopt(args, "rqvu:")
except getopt.error:
return usage()
verbosity = 1
search_leaks = False
for flag, value in opts:
if flag == "-q":
verbosity -= 1
elif flag == "-v":
verbosity += 1
elif flag == "-r":
try:
sys.gettotalrefcount
except AttributeError:
print >> sys.stderr, "-r flag requires Python debug build"
return -1
search_leaks = True
elif flag == "-u":
use_resources.extend(value.split(","))
mask = "test_*.py*"
if args:
mask = args[0]
import comtypes.test
return run_tests(comtypes.test, mask, verbosity, search_leaks)
0
Example 60
Project: karl Source File: scripting.py
def _count_object_refs(): #pragma NO COVERAGE
"""
This function is used for debugging leaking references between business
function calls in the run_daemon function. It relies on a cPython built
with Py_TRACE_REFS. In the absence of such a Python (the standard case)
this function does not called and we don't do this expensive object
counting.
On Ubuntu I was able to get a debug version of python installed by doing:
apt-get install python2.5-dbg
Your mileage may vary on other platforms. I had terrible problems trying
to build Python from source with the Py_TRACE_REFS call and do not
recommend trying that on Ubuntu.
"""
gc.collect()
ref_counts = {}
# Count all of the objects
for obj in sys.getobjects(sys.gettotalrefcount()):
kind = type(obj)
if kind in ref_counts:
ref_counts[kind]['count'] += 1
else:
ref_counts[kind] = dict(kind=kind, count=1, delta=0)
global _ref_counts
if _ref_counts == None:
# first time
_ref_counts = ref_counts
return
# Calculate how many were created since last time
for kind, record in ref_counts.items():
if kind in _ref_counts:
record['delta'] = record['count'] - _ref_counts[kind]['count']
else:
record['delta'] = record['count']
_ref_counts = ref_counts
# Print the top N new objects
N = 20
records = list(ref_counts.values())
records.sort(key=lambda x: (x['delta'], x['count']), reverse=True)
for record in records[:N]:
print "DEBUG: created %d new instances of %s (Total: %d)" % (
record['delta'], str(record['kind']), record['count'],
)
if gc.garbage:
print "DEBUG: GARBAGE: %d/%d" % (
len(gc.garbage), len(gc.get_objects()))
0
Example 61
Project: mpi4py Source File: runtests.py
def test_refleaks(options, args):
from sys import gettotalrefcount
from gc import collect
testsuite = load_tests(options, args)
testsuite._cleanup = False
for case in testsuite:
case._cleanup = False
class EmptyIO(object):
def write(self, *args):
pass
runner = unittest.TextTestRunner(stream=EmptyIO(), verbosity=0)
rank, name = getprocessorinfo()
r1 = r2 = 0
repeats = options.repeats
while repeats:
collect()
r1 = gettotalrefcount()
run_tests(options, testsuite, runner)
collect()
r2 = gettotalrefcount()
leaks = r2-r1
if leaks and repeats < options.repeats:
writeln('[%d@%s] refleaks: (%d - %d) --> %d'
% (rank, name, r2, r1, leaks))
repeats -= 1
0
Example 62
def test_main(verbose=None):
test_classes = (
TestDecorateSortUndecorate,
TestBugs,
)
# In the following test cases, class obj, which has function that changes
# the data upon which sort is invoked, is passed for "key" argument.
# It can not be checked if that function changes data as long as it is
# invoked(e.g. __del__ in SortKiller). so these are currently commented out.
del TestDecorateSortUndecorate.test_key_with_mutating_del
del TestDecorateSortUndecorate.test_key_with_mutating_del_and_exception
#
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