[pypy-commit] pypy numpy-refactor: fix all the tests to pass with -A on numpy 1.8

fijal noreply at buildbot.pypy.org
Thu Aug 30 19:45:23 CEST 2012


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: numpy-refactor
Changeset: r57029:de963cac06e1
Date: 2012-08-30 19:44 +0200
http://bitbucket.org/pypy/pypy/changeset/de963cac06e1/

Log:	fix all the tests to pass with -A on numpy 1.8

diff --git a/pypy/module/micronumpy/test/test_compile.py b/pypy/module/micronumpy/test/test_compile.py
--- a/pypy/module/micronumpy/test/test_compile.py
+++ b/pypy/module/micronumpy/test/test_compile.py
@@ -1,4 +1,5 @@
 import py
+py.test.skip("this is going away")
 
 from pypy.module.micronumpy.compile import (numpy_compile, Assignment,
     ArrayConstant, FloatConstant, Operator, Variable, RangeConstant, Execute,
diff --git a/pypy/module/micronumpy/test/test_dtypes.py b/pypy/module/micronumpy/test/test_dtypes.py
--- a/pypy/module/micronumpy/test/test_dtypes.py
+++ b/pypy/module/micronumpy/test/test_dtypes.py
@@ -1,4 +1,4 @@
-import py
+import py, sys
 from pypy.conftest import option
 from pypy.module.micronumpy.test.test_base import BaseNumpyAppTest
 from pypy.interpreter.gateway import interp2app
@@ -508,13 +508,6 @@
         from _numpypy import dtype
         assert dtype('i4').alignment == 4
 
-    def test_typeinfo(self):
-        from _numpypy import typeinfo, void, number, int64, bool_
-        assert typeinfo['Number'] == number
-        assert typeinfo['LONGLONG'] == ('q', 9, 64, 8, 9223372036854775807L, -9223372036854775808L, int64)
-        assert typeinfo['VOID'] == ('V', 20, 0, 1, void)
-        assert typeinfo['BOOL'] == ('?', 0, 8, 1, 1, 0, bool_)
-
 class AppTestStrUnicodeDtypes(BaseNumpyAppTest):
     def test_str_unicode(self):
         from _numpypy import str_, unicode_, character, flexible, generic
@@ -602,3 +595,15 @@
         assert (a + a)[1] == 4
         self.check_non_native(a, array([1, 2, 3], 'i2'))
 
+class AppTestPyPyOnly(BaseNumpyAppTest):
+    def setup_class(cls):
+        if option.runappdirect and '__pypy__' not in sys.builtin_module_names:
+            py.test.skip("pypy only test")
+        BaseNumpyAppTest.setup_class(cls)
+
+    def test_typeinfo(self):
+        from _numpypy import typeinfo, void, number, int64, bool_
+        assert typeinfo['Number'] == number
+        assert typeinfo['LONGLONG'] == ('q', 9, 64, 8, 9223372036854775807L, -9223372036854775808L, int64)
+        assert typeinfo['VOID'] == ('V', 20, 0, 1, void)
+        assert typeinfo['BOOL'] == ('?', 0, 8, 1, 1, 0, bool_)
diff --git a/pypy/module/micronumpy/test/test_outarg.py b/pypy/module/micronumpy/test/test_outarg.py
--- a/pypy/module/micronumpy/test/test_outarg.py
+++ b/pypy/module/micronumpy/test/test_outarg.py
@@ -108,19 +108,6 @@
         d = array([16, 16], dtype=int)
         b = sum(d, out=c)
         assert b == c
-        try:
-            from _numpypy import version
-            v = version.version.split('.')
-        except:
-            v = ['1', '6', '0'] # numpypy is api compatable to what version?
-        if v[0]<'2':
-            b = negative(c, out=a)
-            assert b == a
-            b = add(c, c, out=a)
-            assert b == a
-            b = sum(array([16, 16], dtype=float), out=a)
-            assert b == a
-        else:
-            cast_error = raises(TypeError, negative, c, a)
-            assert str(cast_error.value) == \
-            "Cannot cast ufunc negative output from dtype('float64') to dtype('int64') with casting rule 'same_kind'"
+        cast_error = raises(TypeError, negative, c, a)
+        assert str(cast_error.value) == \
+               "Cannot cast ufunc negative output from dtype('float64') to dtype('int64') with casting rule 'same_kind'"
diff --git a/pypy/module/micronumpy/test/test_ufuncs.py b/pypy/module/micronumpy/test/test_ufuncs.py
--- a/pypy/module/micronumpy/test/test_ufuncs.py
+++ b/pypy/module/micronumpy/test/test_ufuncs.py
@@ -7,7 +7,7 @@
 
         assert isinstance(add, ufunc)
         assert repr(add) == "<ufunc 'add'>"
-        assert repr(ufunc) == "<type 'numpypy.ufunc'>"
+        assert repr(ufunc) == "<type 'numpypy.ufunc'>" or repr(ufunc) == "<type 'numpy.ufunc'>"
 
     def test_ufunc_attrs(self):
         from _numpypy import add, multiply, sin
@@ -144,8 +144,8 @@
         assert (fmax(a, [ninf]*5) == a).all()
         assert (fmax(a, [inf]*5) == [inf]*5).all()
         assert (fmax(a, [1]*5) == [1, 1, 1, 5, inf]).all()
-        assert math.isnan(fmax(nan, 0))
-        assert math.isnan(fmax(0, nan))
+        assert fmax(nan, 0) == 0
+        assert fmax(0, nan) == 0
         assert math.isnan(fmax(nan, nan))
         # The numpy docs specify that the FIRST NaN should be used if both are NaN
         # Since comparisons with nnan and nan all return false,
@@ -164,8 +164,8 @@
         assert (fmin(a, [ninf]*5) == [ninf]*5).all()
         assert (fmin(a, [inf]*5) == a).all()
         assert (fmin(a, [1]*5) == [ninf, -5, 0, 1, 1]).all()
-        assert math.isnan(fmin(nan, 0))
-        assert math.isnan(fmin(0, nan))
+        assert fmin(nan, 0) == 0
+        assert fmin(0, nan) == 0
         assert math.isnan(fmin(nan, nan))
         # The numpy docs specify that the FIRST NaN should be used if both are NaN
         # use copysign on both sides to sidestep bug in nan representaion
@@ -227,11 +227,6 @@
         for i in range(10):
             assert a[i] == ref[i]
 
-        a = sign(array([True, False], dtype=bool))
-        assert a.dtype == dtype("int8")
-        assert a[0] == 1
-        assert a[1] == 0
-
     def test_signbit(self):
         from _numpypy import signbit
 
@@ -345,7 +340,7 @@
             assert b[i] == math.sin(a[i])
 
         a = sin(array([True, False], dtype=bool))
-        assert abs(a[0] - sin(1)) < 1e-7  # a[0] will be less precise
+        assert abs(a[0] - sin(1)) < 1e-3  # a[0] will be very imprecise
         assert a[1] == 0.0
 
     def test_cos(self):
@@ -557,7 +552,7 @@
         from _numpypy import sin, add
 
         raises(ValueError, sin.reduce, [1, 2, 3])
-        raises((ValueError, TypeError), add.reduce, 1)
+        assert add.reduce(1) == 1
 
     def test_reduce_1d(self):
         from _numpypy import add, maximum, less
@@ -631,15 +626,6 @@
             ]:
                 assert ufunc(a, b) == func(a, b)
 
-    def test_count_reduce_items(self):
-        from _numpypy import count_reduce_items, arange
-        a = arange(24).reshape(2, 3, 4)
-        assert count_reduce_items(a) == 24
-        assert count_reduce_items(a, 1) == 3
-        assert count_reduce_items(a, (1, 2)) == 3 * 4
-        raises(ValueError, count_reduce_items, a, -4)
-        raises(ValueError, count_reduce_items, a, (0, 2, -4))
-
     def test_count_nonzero(self):
         from _numpypy import where, count_nonzero, arange
         a = arange(10)
diff --git a/pypy/module/micronumpy/test/test_zjit.py b/pypy/module/micronumpy/test/test_zjit.py
--- a/pypy/module/micronumpy/test/test_zjit.py
+++ b/pypy/module/micronumpy/test/test_zjit.py
@@ -4,6 +4,7 @@
 """
 
 import py
+py.test.skip("this is going away")
 
 from pypy.jit.metainterp import pyjitpl
 from pypy.jit.metainterp.test.support import LLJitMixin
diff --git a/pypy/module/micronumpy/test/test_ztranslation.py b/pypy/module/micronumpy/test/test_ztranslation.py
--- a/pypy/module/micronumpy/test/test_ztranslation.py
+++ b/pypy/module/micronumpy/test/test_ztranslation.py
@@ -1,8 +1,4 @@
-from pypy.module.micronumpy import signature
 from pypy.objspace.fake.checkmodule import checkmodule
 
 def test_numpy_translates():
-    # XXX: If there are signatures floating around this might explode. This fix
-    # is ugly.
-    signature.known_sigs.clear()
     checkmodule('micronumpy')


More information about the pypy-commit mailing list