Author: Alex Gaynor <alex.gay...@gmail.com>
Branch: kill-someobject
Changeset: r57880:0e6f30e1005b
Date: 2012-10-08 10:18 +0200
http://bitbucket.org/pypy/pypy/changeset/0e6f30e1005b/

Log:    Cleaned up test_newgc

diff --git a/pypy/translator/c/test/test_newgc.py 
b/pypy/translator/c/test/test_newgc.py
--- a/pypy/translator/c/test/test_newgc.py
+++ b/pypy/translator/c/test/test_newgc.py
@@ -1,17 +1,20 @@
+import gc
+import inspect
+import os
+import sys
+
 import py
-import sys, os, inspect
 
-from pypy.objspace.flow.model import summary
-from pypy.rpython.lltypesystem import lltype, llmemory
+from pypy import conftest
+from pypy.rlib import rgc
+from pypy.rlib.objectmodel import keepalive_until_here, compute_hash, 
compute_identity_hash
+from pypy.rlib.rstring import StringBuilder
+from pypy.rpython.lltypesystem import lltype, llmemory, rffi
 from pypy.rpython.lltypesystem.lloperation import llop
 from pypy.rpython.memory.test import snippet
-from pypy.rlib import rgc
-from pypy.rlib.objectmodel import keepalive_until_here
-from pypy.rlib.rstring import StringBuilder, UnicodeBuilder
 from pypy.tool.udir import udir
 from pypy.translator.interactive import Translation
-from pypy.annotation import policy as annpolicy
-from pypy import conftest
+
 
 class TestUsingFramework(object):
     gcpolicy = "marksweep"
@@ -57,7 +60,6 @@
 
         return run
 
-
     def setup_class(cls):
         funcs0 = []
         funcs1 = []
@@ -74,12 +76,12 @@
             prefix, name = fullname.split('_', 1)
             definefunc = getattr(cls, fullname)
             func = definefunc.im_func(cls)
-            func.func_name = 'f_'+name
+            func.func_name = 'f_' + name
             if prefix == 'definestr':
                 funcsstr.append(func)
                 funcs0.append(None)
                 funcs1.append(None)
-            else:            
+            else:
                 numargs = len(inspect.getargspec(func)[0])
                 funcsstr.append(None)
                 if numargs == 0:
@@ -91,6 +93,7 @@
                     funcs1.append(func)
             assert name not in name_to_func
             name_to_func[name] = len(name_to_func)
+
         def allfuncs(name, arg):
             num = name_to_func[name]
             func0 = funcs0[num]
@@ -236,10 +239,10 @@
                     a[j] = lltype.malloc(T)
                     a[j].y = i
                     a[j].s = lltype.malloc(S)
-                    a[j].s.x = 2*i
+                    a[j].s.x = 2 * i
                     r += a[j].y + a[j].s.x
                     a[j].s = lltype.malloc(S)
-                    a[j].s.x = 3*i
+                    a[j].s.x = 3 * i
                     r -= a[j].s.x
                 for j in range(i):
                     r += a[j].y
@@ -269,7 +272,7 @@
     def test_framework_using_lists(self):
         N = 1000
         res = self.run('framework_using_lists')
-        assert res == N*(N - 1)/2
+        assert res == N * (N - 1) / 2
 
     def define_framework_static_roots(cls):
         class A(object):
@@ -318,10 +321,9 @@
         res = self.run('framework_void_array')
         assert res == 44
 
-
     def define_framework_malloc_failure(cls):
         def f():
-            a = [1] * (sys.maxint//2)
+            a = [1] * (sys.maxint // 2)
             return len(a) + a[0]
         return f
 
@@ -397,7 +399,6 @@
         assert res == 6
 
     def define_del_catches(cls):
-        import os
         def g():
             pass
         class A(object):
@@ -442,7 +443,6 @@
 
     def define_custom_trace(cls):
         from pypy.rpython.annlowlevel import llhelper
-        from pypy.rpython.lltypesystem import llmemory
         #
         S = lltype.GcStruct('S', ('x', llmemory.Address), rtti=True)
         offset_of_x = llmemory.offsetof(S, 'x')
@@ -530,9 +530,9 @@
                 a = refs[i]()
                 rgc.collect()
                 if a is None:
-                    result += (i+1)
+                    result += (i + 1)
                 else:
-                    result += a.hello * (i+1)
+                    result += a.hello * (i + 1)
             return result
         return fn
 
@@ -624,7 +624,7 @@
         res = self.run('object_alignment')
         from pypy.rpython.tool import rffi_platform
         expected_alignment = rffi_platform.memory_alignment()
-        assert (res & (expected_alignment-1)) == 0
+        assert (res & (expected_alignment - 1)) == 0
 
     def define_void_list(cls):
         class E:
@@ -664,8 +664,6 @@
     def define_callback_with_collect(cls):
         from pypy.rlib.clibffi import ffi_type_pointer, cast_type_to_ffitype,\
              CDLL, ffi_type_void, CallbackFuncPtr, ffi_type_sint
-        from pypy.rpython.lltypesystem import rffi, ll2ctypes
-        import gc
         ffi_size_t = cast_type_to_ffitype(rffi.SIZE_T)
 
         from pypy.rlib.clibffi import get_libc_name
@@ -702,7 +700,7 @@
             qsort.push_arg(rffi.cast(rffi.SIZE_T, rffi.sizeof(lltype.Signed)))
             qsort.push_arg(rffi.cast(rffi.VOIDP, ptr.ll_closure))
             qsort.call(lltype.Void)
-            result = [to_sort[i] for i in range(4)] == [1,2,3,4]
+            result = [to_sort[i] for i in range(4)] == [1, 2, 3, 4]
             lltype.free(to_sort, flavor='raw')
             keepalive_until_here(ptr)
             return int(result)
@@ -732,7 +730,7 @@
                     assert not rgc.can_move(a)
                     return 1
                 return 0
-            except Exception, e:
+            except Exception:
                 return 2
 
         return func
@@ -767,9 +765,6 @@
         assert res == expected
 
     def define_hash_preservation(cls):
-        from pypy.rlib.objectmodel import compute_hash
-        from pypy.rlib.objectmodel import compute_identity_hash
-        from pypy.rlib.objectmodel import current_object_addr_as_int
         class C:
             pass
         class D(C):
@@ -784,17 +779,23 @@
         h_s = compute_identity_hash(s)   # varsized: hash not saved/restored
         #
         def f():
-            if compute_hash(c) != compute_identity_hash(c): return 12
-            if compute_hash(d) != h_d: return 13
-            if compute_hash(("Hi", None, (7.5, 2, d))) != h_t: return 14
+            if compute_hash(c) != compute_identity_hash(c):
+                return 12
+            if compute_hash(d) != h_d:
+                return 13
+            if compute_hash(("Hi", None, (7.5, 2, d))) != h_t:
+                return 14
             c2 = C()
             h_c2 = compute_hash(c2)
-            if compute_hash(c2) != h_c2: return 15
-            if compute_identity_hash(s) == h_s: return 16   # unlikely
+            if compute_hash(c2) != h_c2:
+                return 15
+            if compute_identity_hash(s) == h_s:
+                return 16   # unlikely
             i = 0
             while i < 6:
                 rgc.collect()
-                if compute_hash(c2) != h_c2: return i
+                if compute_hash(c2) != h_c2:
+                    return i
                 i += 1
             return 42
         return f
@@ -804,7 +805,6 @@
         assert res == 42
 
     def define_hash_overflow(self):
-        from pypy.rlib.objectmodel import compute_identity_hash
         class X(object):
             pass
 
@@ -848,16 +848,16 @@
             build(x1, n)       # can collect!
             check(x1, n, 1)
             build(x3, 3)
-            x2 = g(n//2)       # allocate more and try again
-            build(x2, n//2)
+            x2 = g(n // 2)       # allocate more and try again
+            build(x2, n // 2)
             check(x1, n, 11)
-            check(x2, n//2, 12)
+            check(x2, n // 2, 12)
             build(x4, 3)
             check(x3, 3, 13)   # check these old objects too
             check(x4, 3, 14)   # check these old objects too
             rgc.collect()
             check(x1, n, 21)
-            check(x2, n//2, 22)
+            check(x2, n // 2, 22)
             check(x3, 3, 23)
             check(x4, 3, 24)
 
@@ -890,7 +890,6 @@
         res = self.run('hash_varsized')
         assert res != 0
 
-
     def define_arraycopy_writebarrier_int(cls):
         TP = lltype.GcArray(lltype.Signed)
         S = lltype.GcStruct('S')
@@ -1062,10 +1061,10 @@
             assert 8 <= int1 <= 32
             gcref2 = lltype.cast_opaque_ptr(llmemory.GCREF, s.u)
             int2 = rgc.get_rpy_memory_usage(gcref2)
-            assert 4*9 <= int2 <= 8*12
+            assert 4 * 9 <= int2 <= 8 * 12
             gcref3 = lltype.cast_opaque_ptr(llmemory.GCREF, a)
             int3 = rgc.get_rpy_memory_usage(gcref3)
-            assert 4*1001 <= int3 <= 8*1010
+            assert 4 * 1001 <= int3 <= 8 * 1010
             return 0
 
         return fn
@@ -1234,7 +1233,7 @@
             # the semispace size starts at 8MB for now, so setting a
             # smaller limit has no effect
             # set to more than 32MB -- which should be rounded down to 32MB
-            rgc.set_max_heap_size(32*1024*1024 + 20000)
+            rgc.set_max_heap_size(32 * 1024 * 1024 + 20000)
             s1 = s2 = s3 = None
             try:
                 s1 = g(400000)      # ~ 400 KB
@@ -1299,7 +1298,6 @@
         assert res == "aabcbdddd"
 
     def definestr_string_builder_over_allocation(cls):
-        import gc
         def fn(_):
             s = StringBuilder(4)
             s.append("abcd")
@@ -1318,7 +1316,6 @@
         assert res[1000] == 'y'
 
     def definestr_string_builder_multiple_builds(cls):
-        import gc
         def fn(_):
             s = StringBuilder(4)
             got = []
@@ -1335,7 +1332,6 @@
                                 for length in range(1, 51)])
 
     def define_nursery_hash_base(cls):
-        from pypy.rlib.objectmodel import compute_identity_hash
         class A:
             pass
         def fn():
@@ -1362,6 +1358,7 @@
     gcpolicy = "generation"
     should_be_moving = True
 
+
 class TestHybridGC(TestGenerationalGC):
     gcpolicy = "hybrid"
     should_be_moving = True
@@ -1371,7 +1368,6 @@
         py.test.skip("not implemented")
 
 
-
 class TestHybridGCRemoveTypePtr(TestHybridGC):
     removetypeptr = True
 
@@ -1436,6 +1432,7 @@
         res = self.run("adding_a_hash")
         assert res == 0
 
+
 class TestMiniMarkGC(TestSemiSpaceGC):
     gcpolicy = "minimark"
     should_be_moving = True
@@ -1466,7 +1463,7 @@
                 am3 = am2
                 am2 = am1
                 am1 = A(i * 4)
-                am1.buf[0] = rffi.cast(rffi.INT, i-50000)
+                am1.buf[0] = rffi.cast(rffi.INT, i - 50000)
             return res
         return f
 
@@ -1477,7 +1474,6 @@
     def define_nongc_opaque_attached_to_gc(cls):
         from pypy.module._hashlib.interp_hashlib import HASH_MALLOC_SIZE
         from pypy.rlib import rgc, ropenssl
-        from pypy.rpython.lltypesystem import rffi
 
         class A:
             def __init__(self):
@@ -1594,8 +1590,10 @@
 class TestHybridTaggedPointers(TaggedPointersTest, TestHybridGC):
     pass
 
+
 class TestMarkCompactGCMostCompact(TaggedPointersTest, TestMarkCompactGC):
     removetypeptr = True
 
+
 class TestMiniMarkGCMostCompact(TaggedPointersTest, TestMiniMarkGC):
     removetypeptr = True
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to