[pypy-svn] r36626 - in pypy/dist/pypy/translator/js: . test

fijal at codespeak.net fijal at codespeak.net
Fri Jan 12 22:45:11 CET 2007


Author: fijal
Date: Fri Jan 12 22:44:12 2007
New Revision: 36626

Added:
   pypy/dist/pypy/translator/js/test/test_rlist.py
   pypy/dist/pypy/translator/js/test/test_rpbc.py
Modified:
   pypy/dist/pypy/translator/js/database.py
   pypy/dist/pypy/translator/js/test/runtest.py
   pypy/dist/pypy/translator/js/test/test_rclass.py
Log:
Wack Wack Wack. More and more tests passes now :)


Modified: pypy/dist/pypy/translator/js/database.py
==============================================================================
--- pypy/dist/pypy/translator/js/database.py	(original)
+++ pypy/dist/pypy/translator/js/database.py	Fri Jan 12 22:44:12 2007
@@ -290,7 +290,6 @@
     def record_fields(self):
         if not self.obj:
             return
-            import pdb;pdb.set_trace()
         INSTANCE = self.obj._TYPE
         #while INSTANCE:
         for i, (_type, val) in INSTANCE._allfields().items():
@@ -392,11 +391,14 @@
         return self.const._str
 
     def init(self, ilasm):
-        s = self.const._str
+        if self.const:
+            s = self.const._str
         # do some escaping
         #s = s.replace("\n", "\\n").replace('"', '\"')
         #s = repr(s).replace("\"", "\\\"")
-        ilasm.load_str("%s" % repr(s))
+            ilasm.load_str("%s" % repr(s))
+        else:
+            ilasm.load_str("undefined")
     
     def init_fields(self, ilasm, const_var, name):
         pass

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	Fri Jan 12 22:44:12 2007
@@ -131,37 +131,28 @@
         else:
             try:
                 res = float(s)
+                if float(int(res)) == res:
+                    return int(res)
             except ValueError:
                 res = str(s)
         return res
     reinterpret = classmethod(reinterpret)
 
 class JsTest(BaseRtypingTest, OORtypeMixin):
-    #def __init__(self):
-    #    self._func = None
-    #    self._ann = None
-    #    self._cli_func = None
-
-    def _compile(self, fn, args):
-        #ann = [lltype_to_annotation(typeOf(x)) for x in args]
-        #if self._func is fn and self._ann == ann:
-        #    return self._cli_func
-        #else:
-        #    self._func = fn
-        #    self._ann = ann
-        #    self._cli_func = compile_function(fn, ann)
-        #   return self._cli_func
+    def _compile(self, _fn, args):
+        argnames = _fn.func_code.co_varnames[:_fn.func_code.co_argcount]
         source = py.code.Source("""
         def %s():
             from pypy.rlib.nonconst import NonConstant
-            res = fn(%s)
+            res = _fn(%s)
             if isinstance(res, type(None)):
                 return None
             else:
                 return str(res)"""
-        % (fn.func_name, ",".join(["NonConstant(%s)" % i for i in args])))
+        % (_fn.func_name, ",".join(["%s=NonConstant(%s)" % (name,i) for
+                                   name, i in zip(argnames, args)])))
         exec source.compile() in locals()
-        return compile_function(locals()[fn.func_name], [])
+        return compile_function(locals()[_fn.func_name], [])
     
     def interpret(self, fn, args):
         #def f(args):
@@ -198,15 +189,14 @@
         return l
 
     def class_name(self, value):
-        return value.class_name.split(".")[-1] 
+        return value[:-10].split('_')[-1]
 
     def is_of_instance_type(self, val):
         m = re.match("^<.* instance>$", val)
         return bool(m)
 
     def read_attr(self, obj, name):
-        pass
-        #py.test.skip('read_attr not supported on gencli tests')
+        py.test.skip('read_attr not supported on gencli tests')
 
 def check_source_contains(compiled_function, pattern):
     import re

Modified: pypy/dist/pypy/translator/js/test/test_rclass.py
==============================================================================
--- pypy/dist/pypy/translator/js/test/test_rclass.py	(original)
+++ pypy/dist/pypy/translator/js/test/test_rclass.py	Fri Jan 12 22:44:12 2007
@@ -2,8 +2,6 @@
 from pypy.translator.js.test.runtest import JsTest
 from pypy.rpython.test.test_exception import BaseTestException
 from pypy.rpython.test.test_rclass import BaseTestRclass
-from pypy.rpython.test.test_rlist import BaseTestRlist
-from pypy.rpython.test.test_rpbc import BaseTestRPBC
 from pypy.rpython.test.test_rtuple import BaseTestRtuple
 from pypy.rpython.test.test_rstr import BaseTestRstr
 
@@ -64,7 +62,7 @@
             return v0, v1, v2
 
         res = self.interpret(f, [])
-        assert isinstance(res[0], float)
+        assert isinstance(res[0], int)
 
     def test_hash_preservation(self):
         py.test.skip("WIP")
@@ -75,10 +73,6 @@
     def test_isinstance(self):
         py.test.skip("WIP")
 
-#class TestJsList(JsTest, BaseTestRlist):
-#    def test_insert_bug(self):
-#        py.test.skip("in progress")
-##    
 #class TestJsPBC(JsTest, BaseTestRPBC):
 #    pass
 ##

Added: pypy/dist/pypy/translator/js/test/test_rlist.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/js/test/test_rlist.py	Fri Jan 12 22:44:12 2007
@@ -0,0 +1,78 @@
+
+import py
+from pypy.rpython.test.test_rlist import BaseTestRlist
+from pypy.translator.js.test.runtest import JsTest
+
+class TestJsList(JsTest, BaseTestRlist):
+    def test_append(self):
+        def dummyfn():
+            l = []
+            l.append(50)
+            l.append(60)
+            l.append(70)
+            l.append(80)
+            l.append(90)
+            return len(l), l[0], l[-1]
+        res = self.interpret(dummyfn, [])
+        assert res == [5, 50, 90]
+
+    def test_slice(self):
+        py.test.skip("Imperfect testing machinery")
+        def dummyfn():
+            l = [5, 6, 7, 8, 9]
+            return l[:2], l[1:4], l[3:]
+        res = self.interpret(dummyfn, [])
+
+        def dummyfn():
+            l = [5, 6, 7, 8]
+            l.append(9)
+            return l[:2], l[1:4], l[3:]
+        res = self.interpret(dummyfn, [])
+        assert res == ([5, 6], [6, 7, 8], [8, 9])
+
+    def test_setslice(self):
+        def dummyfn():
+            l = [10, 9, 8, 7]
+            l[:2] = [6, 5]
+            return l[0], l[1], l[2], l[3]
+        res = self.interpret(dummyfn, ())
+        assert res == [6, 5, 8, 7]
+
+    def test_insert_bug(self):
+        def dummyfn(n):
+            l = [1]
+            l = l[:]
+            l.pop(0)
+            if n < 0:
+                l.insert(0, 42)
+            else:
+                l.insert(n, 42)
+            return l
+        res = self.interpret(dummyfn, [0])
+        assert len(res) == 1
+        assert res[0] == 42
+        res = self.interpret(dummyfn, [-1])
+        assert len(res) == 1
+        assert res[0] == 42
+
+    def test_list_str(self):
+        pass
+
+    def test_inst_list(self):
+        py.test.skip("WIP")
+        def fn():
+            l = [None]
+            l[0] = Foo()
+            l.append(Bar())
+            l2 = [l[1], l[0], l[0]]
+            l.extend(l2)
+            for x in l2:
+                l.append(x)
+            x = l.pop()
+            x = l.pop()
+            x = l.pop()
+            x = l2.pop()
+            return str(x)+";"+str(l)
+        res = self.ll_to_string(self.interpret(fn, []))
+        res = res.replace('pypy.rpython.test.test_rlist.', '')
+        assert res == '<Foo object>;[<Foo object>, <Bar object>, <Bar object>, <Foo object>, <Foo object>]'

Added: pypy/dist/pypy/translator/js/test/test_rpbc.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/js/test/test_rpbc.py	Fri Jan 12 22:44:12 2007
@@ -0,0 +1,72 @@
+
+import py
+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