[pypy-svn] r37660 - in pypy/dist/pypy: rpython/test translator/js/test
arigo at codespeak.net
arigo at codespeak.net
Wed Jan 31 12:24:45 CET 2007
Author: arigo
Date: Wed Jan 31 12:24:43 2007
New Revision: 37660
Modified:
pypy/dist/pypy/rpython/test/test_rpbc.py
pypy/dist/pypy/rpython/test/tool.py
pypy/dist/pypy/translator/js/test/runtest.py
pypy/dist/pypy/translator/js/test/test_rpbc.py
Log:
Add an ll_unpack_tuple() method on tests that unpacks whatever
low-level representation of the tuple. It just happens to be
the same with LL and OO, but it's different in the JS backend.
This allows test_rpbc to run unmodified in the JS backend.
Modified: pypy/dist/pypy/rpython/test/test_rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rpbc.py (original)
+++ pypy/dist/pypy/rpython/test/test_rpbc.py Wed Jan 31 12:24:43 2007
@@ -1051,10 +1051,11 @@
return x.value, y.value
for i in [0, 5, 10]:
res = self.interpret(f, [i])
- assert type(res.item0) is int # precise
- assert type(res.item1) is float
- assert res.item0 == f(i)[0]
- assert res.item1 == f(i)[1]
+ item0, item1 = self.ll_unpack_tuple(res, 2)
+ assert type(item0) is int # precise
+ assert type(item1) in (float, int) # we get int on JS
+ assert item0 == f(i)[0]
+ assert item1 == f(i)[1]
def test_pbc_getattr_conversion_with_classes(self):
class base: pass
@@ -1080,10 +1081,11 @@
return x.value, y.value
for i in [0, 5, 10]:
res = self.interpret(f, [i])
- assert type(res.item0) is int # precise
- assert type(res.item1) is float
- assert res.item0 == f(i)[0]
- assert res.item1 == f(i)[1]
+ item0, item1 = self.ll_unpack_tuple(res, 2)
+ assert type(item0) is int # precise
+ assert type(item1) in (float, int) # we get int on JS
+ assert item0 == f(i)[0]
+ assert item1 == f(i)[1]
def test_pbc_imprecise_attrfamily(self):
fr1 = Freezing(); fr1.x = 5; fr1.y = [8]
@@ -1533,11 +1535,12 @@
l = []
f1(l, c1)
f1(l, c2)
- return l, f2(c1)(), f3(c2)()
+ return f2(c1)(), f3(c2)()
res = self.interpret(g, [])
- assert self.ll_to_string(res.item1) == "hello"
- assert res.item2 == 623
+ item0, item1 = self.ll_unpack_tuple(res, 2)
+ assert self.ll_to_string(item0) == "hello"
+ assert item1 == 623
class TestLLtype(BaseTestRPBC, LLRtypeMixin):
Modified: pypy/dist/pypy/rpython/test/tool.py
==============================================================================
--- pypy/dist/pypy/rpython/test/tool.py (original)
+++ pypy/dist/pypy/rpython/test/tool.py Wed Jan 31 12:24:43 2007
@@ -41,6 +41,9 @@
r.append(items[i])
return r
+ def ll_unpack_tuple(self, t, length):
+ return tuple([getattr(t, 'item%d' % i) for i in range(length)])
+
def get_callable(self, fnptr):
return fnptr._obj._callable
@@ -75,6 +78,9 @@
def ll_to_list(self, l):
return l._list[:]
+ def ll_unpack_tuple(self, t, length):
+ return tuple([getattr(t, 'item%d' % i) for i in range(length)])
+
def get_callable(self, sm):
return sm._callable
Modified: pypy/dist/pypy/translator/js/test/runtest.py
==============================================================================
--- pypy/dist/pypy/translator/js/test/runtest.py (original)
+++ pypy/dist/pypy/translator/js/test/runtest.py Wed Jan 31 12:24:43 2007
@@ -188,6 +188,10 @@
def ll_to_list(self, l):
return l
+ def ll_unpack_tuple(self, t, length):
+ assert len(t) == length
+ return tuple(t)
+
def class_name(self, value):
return value[:-10].split('_')[-1]
Modified: pypy/dist/pypy/translator/js/test/test_rpbc.py
==============================================================================
--- pypy/dist/pypy/translator/js/test/test_rpbc.py (original)
+++ pypy/dist/pypy/translator/js/test/test_rpbc.py Wed Jan 31 12:24:43 2007
@@ -3,68 +3,11 @@
from pypy.translator.js.test.runtest import JsTest
from pypy.rpython.test.test_rpbc import BaseTestRPBC
-class Freezing:
- def _freeze_(self):
- return True
- def mymethod(self, y):
- return self.x + y
-
class TestJsPBC(JsTest, BaseTestRPBC):
def test_call_memoized_function_with_bools(self):
py.test.skip("WIP")
- def test_pbc_getattr_conversion_with_classes(self):
- class base: pass
- class fr1(base): pass
- class fr2(base): pass
- class fr3(base): pass
- fr1.value = 10
- fr2.value = 5
- fr3.value = 2.5
- def pick12(i):
- if i > 0:
- return fr1
- else:
- return fr2
- def pick23(i):
- if i > 5:
- return fr2
- else:
- return fr3
- def f(i):
- x = pick12(i)
- y = pick23(i)
- return x.value, y.value
- for i in [0, 5, 10]:
- res = self.interpret(f, [i])
- assert res == list(f(i))
-
- def test_pbc_getattr_conversion(self):
- fr1 = Freezing()
- fr2 = Freezing()
- fr3 = Freezing()
- fr1.value = 10
- fr2.value = 5
- fr3.value = 2.5
- def pick12(i):
- if i > 0:
- return fr1
- else:
- return fr2
- def pick23(i):
- if i > 5:
- return fr2
- else:
- return fr3
- def f(i):
- x = pick12(i)
- y = pick23(i)
- return x.value, y.value
- for i in [0, 5, 10]:
- res = self.interpret(f, [i])
- assert res == list(f(i))
-
def test_conv_from_None(self):
py.test.skip("WIP")
More information about the Pypy-commit
mailing list