[pypy-svn] r71722 - in pypy/branch/micronumpy/pypy/module/micronumpy: . test

dan at codespeak.net dan at codespeak.net
Thu Mar 4 08:34:06 CET 2010


Author: dan
Date: Thu Mar  4 08:34:04 2010
New Revision: 71722

Modified:
   pypy/branch/micronumpy/pypy/module/micronumpy/sdarray.py
   pypy/branch/micronumpy/pypy/module/micronumpy/test/test_numpy.py
Log:
Another two tests.

Modified: pypy/branch/micronumpy/pypy/module/micronumpy/sdarray.py
==============================================================================
--- pypy/branch/micronumpy/pypy/module/micronumpy/sdarray.py	(original)
+++ pypy/branch/micronumpy/pypy/module/micronumpy/sdarray.py	Thu Mar  4 08:34:04 2010
@@ -11,8 +11,6 @@
 
 from pypy.module.micronumpy.dtype import unwrap_int, coerce_int
 from pypy.module.micronumpy.dtype import unwrap_float, coerce_float
-from pypy.module.micronumpy.dtype import\
-                            unwrap_float32, coerce_float32, float32
 from pypy.module.micronumpy.dtype import result_mapping, iterable_type
 
 from pypy.module.micronumpy.dtype import create_factory
@@ -278,7 +276,6 @@
 
 IntArray = create_sdarray(int, unwrap_int, coerce_int)
 FloatArray = create_sdarray(float, unwrap_float, coerce_float)
-Float32Array = create_sdarray(float32, unwrap_float32, coerce_float32)
 GenericArray = None
 
 sdresult = create_factory({'i': IntArray, 'd': FloatArray})

Modified: pypy/branch/micronumpy/pypy/module/micronumpy/test/test_numpy.py
==============================================================================
--- pypy/branch/micronumpy/pypy/module/micronumpy/test/test_numpy.py	(original)
+++ pypy/branch/micronumpy/pypy/module/micronumpy/test/test_numpy.py	Thu Mar  4 08:34:04 2010
@@ -1,6 +1,43 @@
 
 from pypy.conftest import gettestobjspace
 
+class TestSDArray(object):
+    def test_unwrap(self, space):
+        w_int = space.wrap(1)
+        w_float = space.wrap(1.0)
+
+        from pypy.interpreter.error import OperationError
+        def interp_raises(exceptions, f, *args, **kwargs):
+            try:
+                f(*args, **kwargs)
+            except OperationError, e:
+                for ex in exceptions:
+                    if e.match(space, ex):
+                        return
+                raise
+            else:
+                raise AssertionError("Expected one of %s to be raised" % str(exceptions))
+
+        from pypy.module.micronumpy.dtype import unwrap_int
+        assert 1 ==  unwrap_int(space, w_int)
+        interp_raises((space.w_TypeError,), unwrap_int, space, w_float)
+
+        from pypy.module.micronumpy.dtype import unwrap_float
+        assert 1.0 == unwrap_float(space, w_float)
+        #interp_raises((space.w_TypeError,), unwrap_float, space, w_int) #er, shouldn't this raise?
+
+    def test_coerce(self, space):
+        w_int = space.wrap(1)
+        w_float = space.wrap(1.0)
+
+        from pypy.module.micronumpy.dtype import coerce_int
+        assert 1 == coerce_int(space, w_int)
+        assert 1 == coerce_int(space, w_float)
+
+        from pypy.module.micronumpy.dtype import coerce_float
+        assert 1.0 == coerce_float(space, w_int)
+        assert 1.0 == coerce_float(space, w_float)
+
 class AppTestSDArray(object):
     def setup_class(cls):
         cls.space = gettestobjspace(usemodules=('micronumpy',))



More information about the Pypy-commit mailing list