[pypy-svn] r45405 - in pypy/dist/pypy/translator: cli/test oosupport/test_template

antocuni at codespeak.net antocuni at codespeak.net
Fri Jul 27 15:16:18 CEST 2007


Author: antocuni
Date: Fri Jul 27 15:16:18 2007
New Revision: 45405

Added:
   pypy/dist/pypy/translator/oosupport/test_template/cast.py   (contents, props changed)
Modified:
   pypy/dist/pypy/translator/cli/test/runtest.py
   pypy/dist/pypy/translator/cli/test/test_cast.py
Log:
move test_cast to oosupport. cli.test.runtest.check is no longer
needed now.



Modified: pypy/dist/pypy/translator/cli/test/runtest.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/runtest.py	(original)
+++ pypy/dist/pypy/translator/cli/test/runtest.py	Fri Jul 27 15:16:18 2007
@@ -25,16 +25,6 @@
 
 FLOAT_PRECISION = 8
 
-def check(func, annotation, args):
-    mono = compile_function(func, annotation)
-    res1 = func(*args)
-    res2 = mono(*args)
-
-    if type(res1) is float:
-        assert round(res1, FLOAT_PRECISION) == round(res2, FLOAT_PRECISION)
-    else:
-        assert res1 == res2
-
 def format_object(TYPE, cts, ilasm):
     if TYPE is ootype.Void:
         ilasm.opcode('ldstr "None"')

Modified: pypy/dist/pypy/translator/cli/test/test_cast.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/test_cast.py	(original)
+++ pypy/dist/pypy/translator/cli/test/test_cast.py	Fri Jul 27 15:16:18 2007
@@ -1,49 +1,5 @@
-import sys
+from pypy.translator.cli.test.runtest import CliTest
+from pypy.translator.oosupport.test_template.cast import BaseTestCast
 
-from pypy.translator.cli.test.runtest import check
-from pypy.rlib.rarithmetic import r_uint, r_ulonglong, r_longlong, intmask
-
-def to_int(x):
-    return int(x)
-
-def to_uint(x):
-    return r_uint(x)
-
-def to_float(x):
-    return float(x)
-
-def to_longlong(x):
-    return r_longlong(x)
-
-
-def test_bool_to_int():
-    check(to_int, [bool], (True,))
-    check(to_int, [bool], (False,))    
-
-def test_bool_to_uint():
-    check(to_uint, [bool], (True,))
-    check(to_uint, [bool], (False,))
-
-def test_bool_to_float():
-    check(to_float, [bool], (True,))
-    check(to_float, [bool], (False,))
-
-def test_int_to_uint():
-    check(to_uint, [int], (42,))
-
-def test_int_to_float():
-    check(to_float, [int], (42,))
-
-def test_int_to_longlong():
-    check(to_longlong, [int], (42,))
-
-def test_uint_to_int():
-    def uint_to_int(x):
-        return intmask(x)
-    check(uint_to_int, [r_uint], (sys.maxint+1,))
-
-def test_float_to_int():
-    check(to_int, [float], (42.5,))
-
-def test_uint_to_float():
-    check(to_float, [r_uint], (sys.maxint+1,))
+class TestCast(BaseTestCast, CliTest):
+    pass

Added: pypy/dist/pypy/translator/oosupport/test_template/cast.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/oosupport/test_template/cast.py	Fri Jul 27 15:16:18 2007
@@ -0,0 +1,54 @@
+import sys
+from pypy.rlib.rarithmetic import r_uint, r_ulonglong, r_longlong, intmask
+
+def to_int(x):
+    return int(x)
+
+def to_uint(x):
+    return r_uint(x)
+
+def to_float(x):
+    return float(x)
+
+def to_longlong(x):
+    return r_longlong(x)
+
+def uint_to_int(x):
+    return intmask(x)
+
+class BaseTestCast:
+
+    def check(self, fn, args):
+        res1 = self.interpret(fn, args)
+        res2 = fn(*args)
+        assert res1 == res2
+
+    def test_bool_to_int(self):
+        self.check(to_int, [True])
+        self.check(to_int, [False])
+
+    def test_bool_to_uint(self):
+        self.check(to_uint, [True])
+        self.check(to_uint, [False])
+
+    def test_bool_to_float(self):
+        self.check(to_float, [True])
+        self.check(to_float, [False])
+
+    def test_int_to_uint(self):
+        self.check(to_uint, [42])
+
+    def test_int_to_float(self):
+        self.check(to_float, [42])
+
+    def test_int_to_longlong(self):
+        self.check(to_longlong, [42])
+
+    def test_uint_to_int(self):
+        self.check(uint_to_int, [r_uint(sys.maxint+1)])
+
+    def test_float_to_int(self):
+        self.check(to_int, [42.5])
+
+    def test_uint_to_float(self):
+        self.check(to_float, [r_uint(sys.maxint+1)])



More information about the Pypy-commit mailing list