[pypy-svn] r28590 - in pypy/dist/pypy: rpython/lltypesystem/test translator/c/test
arigo at codespeak.net
arigo at codespeak.net
Fri Jun 9 16:26:45 CEST 2006
Author: arigo
Date: Fri Jun 9 16:26:43 2006
New Revision: 28590
Modified:
pypy/dist/pypy/rpython/lltypesystem/test/test_rcpyclass.py
pypy/dist/pypy/translator/c/test/test_genc.py
Log:
A passing test about rcpy.py.
Modified: pypy/dist/pypy/rpython/lltypesystem/test/test_rcpyclass.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/test/test_rcpyclass.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/test/test_rcpyclass.py Fri Jun 9 16:26:43 2006
@@ -19,8 +19,8 @@
w = W_MyTest(21)
return cpy_export(mytest, w)
- fn = compile(f, [], expected_extra_mallocs=1)
- res = fn()
+ fn = compile(f, [])
+ res = fn(expected_extra_mallocs=1)
assert type(res).__name__ == 'mytest'
@@ -60,8 +60,38 @@
w = cpy_import(W_MyTest, obj)
return w.a.x
- fn = compile(g, [], backendopt=False)
+ fn = compile(g, [])
res = fn()
# the A() should have been deallocated too, otherwise the number
# of mallocs doesn't match the number of frees
assert res == 4
+
+
+def test_subclass_from_cpython():
+ class mytest(object):
+ pass
+
+ def f(input):
+ current = total = 0
+ if input:
+ w = cpy_import(W_MyTest, input)
+ current, total = w.stuff
+ w = W_MyTest(21)
+ current += 1
+ total += current
+ w.stuff = current, total
+ return cpy_export(mytest, w), total
+
+ fn = compile(f, [object])
+ obj, total = fn(None, expected_extra_mallocs=2) # 1 W_MyTest (with 1 tuple)
+ assert total == 1
+ obj, total = fn(obj, expected_extra_mallocs=4) # 2 W_MyTests alive
+ assert total == 3
+ obj, total = fn(obj, expected_extra_mallocs=4) # 2 W_MyTests alive
+ assert total == 6
+ obj, total = fn(obj, expected_extra_mallocs=4) # etc
+ assert total == 10
+ obj, total = fn(obj, expected_extra_mallocs=4)
+ assert total == 15
+ obj, total = fn(obj, expected_extra_mallocs=4)
+ assert total == 21
Modified: pypy/dist/pypy/translator/c/test/test_genc.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_genc.py (original)
+++ pypy/dist/pypy/translator/c/test/test_genc.py Fri Jun 9 16:26:43 2006
@@ -31,7 +31,7 @@
return m
def compile(fn, argtypes, view=False, gcpolicy=None, backendopt=True,
- annotatorpolicy=None, expected_extra_mallocs=0):
+ annotatorpolicy=None):
t = TranslationContext()
a = t.buildannotator(policy=annotatorpolicy)
a.build_types(fn, argtypes)
@@ -46,6 +46,10 @@
t.view()
compiled_fn = getattr(module, entrypoint)
def checking_fn(*args, **kwds):
+ if 'expected_extra_mallocs' in kwds:
+ expected_extra_mallocs = kwds.pop('expected_extra_mallocs')
+ else:
+ expected_extra_mallocs = 0
try:
return compiled_fn(*args, **kwds)
finally:
More information about the Pypy-commit
mailing list