[pypy-svn] rev 2440 - in pypy/trunk/src/pypy/objspace/std: . test

jacob at codespeak.net jacob at codespeak.net
Wed Dec 17 14:54:45 CET 2003


Author: jacob
Date: Wed Dec 17 14:54:44 2003
New Revision: 2440

Modified:
   pypy/trunk/src/pypy/objspace/std/floatobject.py
   pypy/trunk/src/pypy/objspace/std/intobject.py
   pypy/trunk/src/pypy/objspace/std/test/test_floatobject.py
   pypy/trunk/src/pypy/objspace/std/test/test_intobject.py
Log:
Added tests for pow.

Modified: pypy/trunk/src/pypy/objspace/std/floatobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/floatobject.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/floatobject.py	Wed Dec 17 14:54:44 2003
@@ -1,4 +1,5 @@
 from pypy.objspace.std.objspace import *
+from noneobject import W_NoneObject
 from floattype import W_FloatType
 
 ##############################################################
@@ -182,7 +183,7 @@
 
 def pow__Float_Float_ANY(space, w_float1, w_float2, thirdArg):
     if thirdArg is not space.w_None:
-        raise FailedToImplement(space.w_TypeError,space.wrap("pow() 3rd argument not allowed unless all arguments are integers"))
+        raise FailedToImplement(space.w_TypeError, space.wrap("pow() 3rd argument not allowed unless all arguments are integers"))
     x = w_float1.floatval
     y = w_float2.floatval
     try:

Modified: pypy/trunk/src/pypy/objspace/std/intobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/intobject.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/intobject.py	Wed Dec 17 14:54:44 2003
@@ -252,14 +252,17 @@
     return W_IntObject(space, ret)
 """
 
-def pow__Int_Int_ANY(space, w_int1, w_int2, w_int3):
+def pow__Int_Int_Int(space, w_int1, w_int2, w_int3):
     x = w_int1.intval
     y = w_int2.intval
-    if w_int3 is space.w_None:
-        ret = _impl_int_int_pow(space, x, y)
-    else:
-        z = w_int3.intval
-        ret = _impl_int_int_pow(space, x, y, z)
+    z = w_int3.intval
+    ret = _impl_int_int_pow(space, x, y, z)
+    return W_IntObject(space, ret)
+
+def pow__Int_Int_None(space, w_int1, w_int2, w_int3):
+    x = w_int1.intval
+    y = w_int2.intval
+    ret = _impl_int_int_pow(space, x, y)
     return W_IntObject(space, ret)
 
 def neg__Int(space, w_int1):

Modified: pypy/trunk/src/pypy/objspace/std/test/test_floatobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/test/test_floatobject.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/test/test_floatobject.py	Wed Dec 17 14:54:44 2003
@@ -1,7 +1,43 @@
 import autopath
+from pypy.objspace.std import floatobject as fobj
+from pypy.objspace.std.objspace import FailedToImplement
 from pypy.tool import test
 
-class FloatTestCase(test.AppTestCase):
+class TestW_FloatObject(test.TestCase):
+
+    def setUp(self):
+        self.space = test.objspace('std')
+
+    def tearDown(self):
+        pass
+    
+    def _unwrap_nonimpl(self, func, *args, **kwds):
+        """ make sure that the expected exception occurs, and unwrap it """
+        try:
+            res = func(*args, **kwds)
+            raise Exception, "should have failed but returned '%s'!" %repr(res)
+        except FailedToImplement, arg:
+            return arg[0]
+
+    def test_pow_fff(self):
+        x = 10.0
+        y = 2.0
+        z = 13.0
+        f1 = fobj.W_FloatObject(self.space, x)
+        f2 = fobj.W_FloatObject(self.space, y)
+        f3 = fobj.W_FloatObject(self.space, z)
+        self.assertEquals(self.space.w_TypeError,
+                          self._unwrap_nonimpl(fobj.pow__Float_Float_ANY, self.space, f1, f2, f3))
+
+    def test_pow_ffn(self):
+        x = 10.0
+        y = 2.0
+        f1 = fobj.W_FloatObject(self.space, x)
+        f2 = fobj.W_FloatObject(self.space, y)
+        v = fobj.pow__Float_Float_ANY(self.space, f1, f2, self.space.w_None)
+        self.assertEquals(v.floatval, x ** y)
+
+class AppFloatTest(test.AppTestCase):
     def setUp(self):
         self.space = test.objspace('std')
 

Modified: pypy/trunk/src/pypy/objspace/std/test/test_intobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/test/test_intobject.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/test/test_intobject.py	Wed Dec 17 14:54:44 2003
@@ -149,15 +149,15 @@
         f1 = iobj.W_IntObject(self.space, x)
         f2 = iobj.W_IntObject(self.space, y)
         f3 = iobj.W_IntObject(self.space, z)
-        v = iobj.pow__Int_Int_ANY(self.space, f1, f2, f3)
+        v = iobj.pow__Int_Int_Int(self.space, f1, f2, f3)
         self.assertEquals(v.intval, pow(x, y, z))
         f1, f2, f3 = [iobj.W_IntObject(self.space, i) for i in (10, -1, 42)]
         self.assertRaises_w(self.space.w_TypeError,
-                            iobj.pow__Int_Int_ANY,
+                            iobj.pow__Int_Int_Int,
                             self.space, f1, f2, f3)
         f1, f2, f3 = [iobj.W_IntObject(self.space, i) for i in (10, 5, 0)]
         self.assertRaises_w(self.space.w_ValueError,
-                            iobj.pow__Int_Int_ANY,
+                            iobj.pow__Int_Int_Int,
                             self.space, f1, f2, f3)
 
     def test_pow_iin(self):
@@ -165,14 +165,14 @@
         y = 2
         f1 = iobj.W_IntObject(self.space, x)
         f2 = iobj.W_IntObject(self.space, y)
-        v = iobj.pow__Int_Int_ANY(self.space, f1, f2, self.space.w_None)
+        v = iobj.pow__Int_Int_None(self.space, f1, f2, self.space.w_None)
         self.assertEquals(v.intval, x ** y)
         f1, f2 = [iobj.W_IntObject(self.space, i) for i in (10, 20)]
         self.assertEquals(self.space.w_OverflowError,
-                          self._unwrap_nonimpl(iobj.pow__Int_Int_ANY, self.space, f1, f2, self.space.w_None))
+                          self._unwrap_nonimpl(iobj.pow__Int_Int_None, self.space, f1, f2, self.space.w_None))
         f1, f2 = [iobj.W_IntObject(self.space, i) for i in (10, -1)]
         self.assertEquals(self.space.w_ValueError,
-                          self._unwrap_nonimpl(iobj.pow__Int_Int_ANY, self.space, f1, f2, self.space.w_None))
+                          self._unwrap_nonimpl(iobj.pow__Int_Int_None, self.space, f1, f2, self.space.w_None))
 
     def test_neg(self):
         x = 42


More information about the Pypy-commit mailing list