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

antocuni at codespeak.net antocuni at codespeak.net
Fri Jul 27 14:57:32 CEST 2007


Author: antocuni
Date: Fri Jul 27 14:57:32 2007
New Revision: 45403

Added:
   pypy/dist/pypy/translator/oosupport/test_template/overflow.py   (contents, props changed)
Modified:
   pypy/dist/pypy/translator/cli/test/test_overflow.py
Log:
refactor cli/test/test_overflow to use the "new" 1.5 years old testing
framework, so it can be easily reused by genjvm



Modified: pypy/dist/pypy/translator/cli/test/test_overflow.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/test_overflow.py	(original)
+++ pypy/dist/pypy/translator/cli/test/test_overflow.py	Fri Jul 27 14:57:32 2007
@@ -1,41 +1,5 @@
-from pypy.translator.cli.test.runtest import check
-from pypy.rlib.rarithmetic import ovfcheck
+from pypy.translator.cli.test.runtest import CliTest
+from pypy.translator.oosupport.test_template.overflow import BaseTestOverflow
 
-import sys
-
-def op_add(x, y):
-    try:
-        return ovfcheck(x+y)
-    except OverflowError:
-        return 42
-
-def op_sub(x, y):
-    try:
-        return ovfcheck(x-y)
-    except OverflowError:
-        return 42
-
-def op_mul(x, y):
-    try:
-        return ovfcheck(x*y)
-    except OverflowError:
-        return 42
-
-def op_lshift(x, y):
-    try:
-        return ovfcheck(x<<y)
-    except OverflowError:
-        return 42
-
-def op_neg(x):
-    try:
-        return ovfcheck(-x)
-    except OverflowError:
-        return 42
-
-def test_overflow():
-    yield check, op_add, [int, int], (sys.maxint, 1)
-    yield check, op_sub, [int, int], (-sys.maxint, 1)
-    yield check, op_mul, [int, int], (sys.maxint/2 + 1, 2)
-    yield check, op_lshift, [int, int], (2, 30)
-    yield check, op_neg, [int], (-sys.maxint-1,)
+class TestOverflow(BaseTestOverflow, CliTest):
+    pass

Added: pypy/dist/pypy/translator/oosupport/test_template/overflow.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/oosupport/test_template/overflow.py	Fri Jul 27 14:57:32 2007
@@ -0,0 +1,50 @@
+import sys
+from pypy.rlib.rarithmetic import ovfcheck
+
+class BaseTestOverflow:
+
+    def check(self, fn, args):
+        res1 = self.interpret(fn, args)
+        res2 = fn(*args)
+        assert res1 == res2
+
+    def test_add(self):
+        def fn(x, y):
+            try:
+                return ovfcheck(x+y)
+            except OverflowError:
+                return 42
+        self.check(fn, [sys.maxint, 1])
+
+    def test_sub(self):
+        def fn(x, y):
+            try:
+                return ovfcheck(x-y)
+            except OverflowError:
+                return 42
+        self.check(fn, [-sys.maxint, 2])
+
+    def test_mul(self):
+        def fn(x, y):
+            try:
+                return ovfcheck(x*y)
+            except OverflowError:
+                return 42
+        self.check(fn, [sys.maxint/2 + 1, 2])
+
+    def test_lshift(self):
+        def fn(x, y):
+            try:
+                return ovfcheck(x<<y)
+            except OverflowError:
+                return 42
+        self.check(fn, [2, 30])
+
+
+    def test_neg(self):
+        def fn(x):
+            try:
+                return ovfcheck(-x)
+            except OverflowError:
+                return 42
+        self.check(fn, [-sys.maxint-1])



More information about the Pypy-commit mailing list