some basic gcutils tests

This commit is contained in:
Mahmoud Hashemi 2015-05-18 21:02:24 -07:00
parent 69e2209109
commit 4e253fa631
1 changed files with 34 additions and 0 deletions

34
tests/test_gcutils.py Normal file
View File

@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
import sys
import time
if '__pypy__' not in sys.builtin_module_names:
# pypy's gc really is different
from boltons.gcutils import get_all, toggle_gc_postcollect
def test_get_all():
class TestType(object):
pass
tt = TestType()
assert len(get_all(TestType)) == 1
assert len(get_all(bool)) == 0
return
def test_toggle_gc_postcollect():
COUNT = int(1e6)
start = time.time()
with toggle_gc_postcollect:
x = [{} for x in range(COUNT)]
no_gc_time = time.time() - start
start = time.time()
x = [{} for x in range(COUNT)]
with_gc_time = time.time() - start
assert no_gc_time < with_gc_time