[pypy-commit] pypy ufuncapi: merge deault into branch

mattip noreply at buildbot.pypy.org
Wed Dec 24 18:00:54 CET 2014


Author: mattip <matti.picus at gmail.com>
Branch: ufuncapi
Changeset: r75106:f649f767bd94
Date: 2014-12-24 18:59 +0200
http://bitbucket.org/pypy/pypy/changeset/f649f767bd94/

Log:	merge deault into branch

diff too long, truncating to 2000 out of 9967 lines

diff --git a/lib-python/2.7/sqlite3/test/dbapi.py b/lib-python/2.7/sqlite3/test/dbapi.py
--- a/lib-python/2.7/sqlite3/test/dbapi.py
+++ b/lib-python/2.7/sqlite3/test/dbapi.py
@@ -478,6 +478,29 @@
         except TypeError:
             pass
 
+    def CheckCurDescription(self):
+        self.cu.execute("select * from test")
+
+        actual = self.cu.description
+        expected = [
+            ('id', None, None, None, None, None, None),
+            ('name', None, None, None, None, None, None),
+            ('income', None, None, None, None, None, None),
+        ]
+        self.assertEqual(expected, actual)
+
+    def CheckCurDescriptionVoidStatement(self):
+        self.cu.execute("insert into test(name) values (?)", ("foo",))
+        self.assertIsNone(self.cu.description)
+
+    def CheckCurDescriptionWithoutStatement(self):
+        cu = self.cx.cursor()
+        try:
+            self.assertIsNone(cu.description)
+        finally:
+            cu.close()
+
+
 @unittest.skipUnless(threading, 'This test requires threading.')
 class ThreadTests(unittest.TestCase):
     def setUp(self):
diff --git a/lib-python/2.7/test/test_collections.py b/lib-python/2.7/test/test_collections.py
--- a/lib-python/2.7/test/test_collections.py
+++ b/lib-python/2.7/test/test_collections.py
@@ -1108,6 +1108,16 @@
             od.popitem()
         self.assertEqual(len(od), 0)
 
+    def test_popitem_first(self):
+        pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
+        shuffle(pairs)
+        od = OrderedDict(pairs)
+        while pairs:
+            self.assertEqual(od.popitem(last=False), pairs.pop(0))
+        with self.assertRaises(KeyError):
+            od.popitem(last=False)
+        self.assertEqual(len(od), 0)
+
     def test_pop(self):
         pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
         shuffle(pairs)
@@ -1179,7 +1189,11 @@
         od = OrderedDict(pairs)
         # yaml.dump(od) -->
         # '!!python/object/apply:__main__.OrderedDict\n- - [a, 1]\n  - [b, 2]\n'
-        self.assertTrue(all(type(pair)==list for pair in od.__reduce__()[1]))
+
+        # PyPy bug fix: added [0] at the end of this line, because the
+        # test is really about the 2-tuples that need to be 2-lists
+        # inside the list of 6 of them
+        self.assertTrue(all(type(pair)==list for pair in od.__reduce__()[1][0]))
 
     def test_reduce_not_too_fat(self):
         # do not save instance dictionary if not needed
@@ -1189,6 +1203,16 @@
         od.x = 10
         self.assertEqual(len(od.__reduce__()), 3)
 
+    def test_reduce_exact_output(self):
+        # PyPy: test that __reduce__() produces the exact same answer as
+        # CPython does, even though in the 'all_ordered_dicts' branch we
+        # have to emulate it.
+        pairs = [['c', 1], ['b', 2], ['d', 4]]
+        od = OrderedDict(pairs)
+        self.assertEqual(od.__reduce__(), (OrderedDict, (pairs,)))
+        od.x = 10
+        self.assertEqual(od.__reduce__(), (OrderedDict, (pairs,), {'x': 10}))
+
     def test_repr(self):
         od = OrderedDict([('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)])
         self.assertEqual(repr(od),
diff --git a/lib-python/2.7/test/test_xml_etree.py b/lib-python/2.7/test/test_xml_etree.py
--- a/lib-python/2.7/test/test_xml_etree.py
+++ b/lib-python/2.7/test/test_xml_etree.py
@@ -225,9 +225,9 @@
     >>> element.remove(subelement)
     >>> serialize(element) # 5
     '<tag key="value" />'
-    >>> element.remove(subelement)
+    >>> element.remove(subelement)    # doctest: +ELLIPSIS
     Traceback (most recent call last):
-    ValueError: list.remove(x): x not in list
+    ValueError: list.remove(x): ...
     >>> serialize(element) # 6
     '<tag key="value" />'
     >>> element[0:0] = [subelement, subelement, subelement]
diff --git a/lib-python/stdlib-upgrade.txt b/lib-python/stdlib-upgrade.txt
--- a/lib-python/stdlib-upgrade.txt
+++ b/lib-python/stdlib-upgrade.txt
@@ -7,7 +7,7 @@
 
 1. check out the branch vendor/stdlib
 2. upgrade the files there
-3. update stdlib-versions.txt with the output of hg -id from the cpython repo
+3. update stdlib-version.txt with the output of hg -id from the cpython repo
 4. commit
 5. update to default/py3k
 6. create a integration branch for the new stdlib
diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py
--- a/lib_pypy/_sqlite3.py
+++ b/lib_pypy/_sqlite3.py
@@ -1175,8 +1175,9 @@
         try:
             return self.__description
         except AttributeError:
-            self.__description = self.__statement._get_description()
-            return self.__description
+            if self.__statement:
+                self.__description = self.__statement._get_description()
+                return self.__description
     description = property(__get_description)
 
     def __get_lastrowid(self):
diff --git a/lib_pypy/readline.py b/lib_pypy/readline.py
--- a/lib_pypy/readline.py
+++ b/lib_pypy/readline.py
@@ -6,4 +6,11 @@
 are only stubs at the moment.
 """
 
-from pyrepl.readline import *
+try:
+    from pyrepl.readline import *
+except ImportError:
+    import sys
+    if sys.platform == 'win32':
+        raise ImportError("the 'readline' module is not available on Windows"
+                          " (on either PyPy or CPython)")
+    raise
diff --git a/pypy/doc/embedding.rst b/pypy/doc/embedding.rst
--- a/pypy/doc/embedding.rst
+++ b/pypy/doc/embedding.rst
@@ -6,6 +6,10 @@
 C. It was developed in collaboration with Roberto De Ioris from the `uwsgi`_
 project. The `PyPy uwsgi plugin`_ is a good example of using the embedding API.
 
+**NOTE**: As of 1st of December, PyPy comes with ``--shared`` by default
+on linux, linux64 and windows. We will make it the default on all platforms
+by the time of the next release.
+
 The first thing that you need is to compile PyPy yourself with the option
 ``--shared``. We plan to make ``--shared`` the default in the future. Consult
 the `how to compile PyPy`_ doc for details. This will result in ``libpypy.so``
diff --git a/pypy/doc/project-ideas.rst b/pypy/doc/project-ideas.rst
--- a/pypy/doc/project-ideas.rst
+++ b/pypy/doc/project-ideas.rst
@@ -35,6 +35,13 @@
 PyPy's bytearray type is very inefficient. It would be an interesting
 task to look into possible optimizations on this.
 
+Implement AF_XXX packet types for PyPy
+--------------------------------------
+
+PyPy is missing AF_XXX types of sockets. Implementing it is easy-to-medium
+task. `bug report`_
+
+.. _`bug report`: https://bitbucket.org/pypy/pypy/issue/1942/support-for-af_xxx-sockets#more
 
 Implement copy-on-write list slicing
 ------------------------------------
diff --git a/pypy/interpreter/pyframe.py b/pypy/interpreter/pyframe.py
--- a/pypy/interpreter/pyframe.py
+++ b/pypy/interpreter/pyframe.py
@@ -125,6 +125,8 @@
         else:
             return self.space.builtin
 
+    _NO_CELLS = []
+
     @jit.unroll_safe
     def initialize_frame_scopes(self, outer_func, code):
         # regular functions always have CO_OPTIMIZED and CO_NEWLOCALS.
@@ -143,7 +145,7 @@
         nfreevars = len(code.co_freevars)
         if not nfreevars:
             if not ncellvars:
-                self.cells = []
+                self.cells = self._NO_CELLS
                 return            # no self.cells needed - fast path
         elif outer_func is None:
             space = self.space
diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py b/pypy/module/_cffi_backend/test/_backend_test_c.py
--- a/pypy/module/_cffi_backend/test/_backend_test_c.py
+++ b/pypy/module/_cffi_backend/test/_backend_test_c.py
@@ -397,7 +397,7 @@
 def test_invalid_indexing():
     p = new_primitive_type("int")
     x = cast(p, 42)
-    py.test.raises(TypeError, "p[0]")
+    py.test.raises(TypeError, "x[0]")
 
 def test_default_str():
     BChar = new_primitive_type("char")
diff --git a/pypy/module/_rawffi/alt/interp_funcptr.py b/pypy/module/_rawffi/alt/interp_funcptr.py
--- a/pypy/module/_rawffi/alt/interp_funcptr.py
+++ b/pypy/module/_rawffi/alt/interp_funcptr.py
@@ -14,6 +14,7 @@
 from rpython.rlib.objectmodel import we_are_translated
 from pypy.module._rawffi.alt.type_converter import FromAppLevelConverter, ToAppLevelConverter
 from pypy.module._rawffi.interp_rawffi import got_libffi_error, wrap_dlopenerror
+from pypy.module._rawffi import lasterror
 
 import os
 if os.name == 'nt':
@@ -201,11 +202,23 @@
         self.func = func
         self.argchain = argchain
 
+    def before(self):
+        lasterror.restore_last_error(self.space)
+
+    def after(self):
+        lasterror.save_last_error(self.space)
+
     def get_longlong(self, w_ffitype):
-        return self.func.call(self.argchain, rffi.LONGLONG)
+        self.before()
+        x = self.func.call(self.argchain, rffi.LONGLONG)
+        self.after()
+        return x
 
     def get_ulonglong(self, w_ffitype):
-        return self.func.call(self.argchain, rffi.ULONGLONG)
+        self.before()
+        x = self.func.call(self.argchain, rffi.ULONGLONG)
+        self.after()
+        return x
 
     def get_signed(self, w_ffitype):
         # if the declared return type of the function is smaller than LONG,
@@ -216,64 +229,94 @@
         # to space.wrap in order to get a nice applevel <int>.
         #
         restype = w_ffitype.get_ffitype()
+        self.before()
         call = self.func.call
         if restype is libffi.types.slong:
-            return call(self.argchain, rffi.LONG)
+            x = call(self.argchain, rffi.LONG)
         elif restype is libffi.types.sint:
-            return rffi.cast(rffi.LONG, call(self.argchain, rffi.INT))
+            x = rffi.cast(rffi.LONG, call(self.argchain, rffi.INT))
         elif restype is libffi.types.sshort:
-            return rffi.cast(rffi.LONG, call(self.argchain, rffi.SHORT))
+            x = rffi.cast(rffi.LONG, call(self.argchain, rffi.SHORT))
         elif restype is libffi.types.schar:
-            return rffi.cast(rffi.LONG, call(self.argchain, rffi.SIGNEDCHAR))
+            x = rffi.cast(rffi.LONG, call(self.argchain, rffi.SIGNEDCHAR))
         else:
-            self.error(w_ffitype)
+            raise self.error(w_ffitype)
+        self.after()
+        return x
 
     def get_unsigned(self, w_ffitype):
-        return self.func.call(self.argchain, rffi.ULONG)
+        self.before()
+        x = self.func.call(self.argchain, rffi.ULONG)
+        self.after()
+        return x
 
     def get_unsigned_which_fits_into_a_signed(self, w_ffitype):
         # the same comment as get_signed apply
         restype = w_ffitype.get_ffitype()
+        self.before()
         call = self.func.call
         if restype is libffi.types.uint:
             assert not libffi.IS_32_BIT
             # on 32bit machines, we should never get here, because it's a case
             # which has already been handled by get_unsigned above.
-            return rffi.cast(rffi.LONG, call(self.argchain, rffi.UINT))
+            x = rffi.cast(rffi.LONG, call(self.argchain, rffi.UINT))
         elif restype is libffi.types.ushort:
-            return rffi.cast(rffi.LONG, call(self.argchain, rffi.USHORT))
+            x = rffi.cast(rffi.LONG, call(self.argchain, rffi.USHORT))
         elif restype is libffi.types.uchar:
-            return rffi.cast(rffi.LONG, call(self.argchain, rffi.UCHAR))
+            x = rffi.cast(rffi.LONG, call(self.argchain, rffi.UCHAR))
         else:
-            self.error(w_ffitype)
+            raise self.error(w_ffitype)
+        self.after()
+        return x
 
 
     def get_pointer(self, w_ffitype):
+        self.before()
         ptrres = self.func.call(self.argchain, rffi.VOIDP)
+        self.after()
         return rffi.cast(rffi.ULONG, ptrres)
 
     def get_char(self, w_ffitype):
-        return self.func.call(self.argchain, rffi.UCHAR)
+        self.before()
+        x = self.func.call(self.argchain, rffi.UCHAR)
+        self.after()
+        return x
 
     def get_unichar(self, w_ffitype):
-        return self.func.call(self.argchain, rffi.WCHAR_T)
+        self.before()
+        x = self.func.call(self.argchain, rffi.WCHAR_T)
+        self.after()
+        return x
 
     def get_float(self, w_ffitype):
-        return self.func.call(self.argchain, rffi.DOUBLE)
+        self.before()
+        x = self.func.call(self.argchain, rffi.DOUBLE)
+        self.after()
+        return x
 
     def get_singlefloat(self, w_ffitype):
-        return self.func.call(self.argchain, rffi.FLOAT)
+        self.before()
+        x = self.func.call(self.argchain, rffi.FLOAT)
+        self.after()
+        return x
 
     def get_struct(self, w_ffitype, w_structdescr):
+        self.before()
         addr = self.func.call(self.argchain, rffi.LONG, is_struct=True)
+        self.after()
         return w_structdescr.fromaddress(self.space, addr)
 
     def get_struct_rawffi(self, w_ffitype, w_structdescr):
+        self.before()
         uintval = self.func.call(self.argchain, rffi.ULONG, is_struct=True)
+        self.after()
         return w_structdescr.fromaddress(self.space, uintval)
 
     def get_void(self, w_ffitype):
-        return self.func.call(self.argchain, lltype.Void)
+        self.before()
+        x = self.func.call(self.argchain, lltype.Void)
+        self.after()
+        return x
 
 
 def unpack_argtypes(space, w_argtypes, w_restype):
diff --git a/pypy/module/_rawffi/interp_rawffi.py b/pypy/module/_rawffi/interp_rawffi.py
--- a/pypy/module/_rawffi/interp_rawffi.py
+++ b/pypy/module/_rawffi/interp_rawffi.py
@@ -18,6 +18,7 @@
 from rpython.rlib.rarithmetic import intmask, r_uint
 from pypy.module._rawffi.buffer import RawFFIBuffer
 from pypy.module._rawffi.tracker import tracker
+from pypy.module._rawffi import lasterror
 
 TYPEMAP = {
     # XXX A mess with unsigned/signed/normal chars :-/
@@ -495,10 +496,14 @@
         try:
             if self.resshape is not None:
                 result = self.resshape.allocate(space, 1, autofree=True)
+                lasterror.restore_last_error(space)
                 self.ptr.call(args_ll, result.ll_buffer)
+                lasterror.save_last_error(space)
                 return space.wrap(result)
             else:
+                lasterror.restore_last_error(space)
                 self.ptr.call(args_ll, lltype.nullptr(rffi.VOIDP.TO))
+                lasterror.save_last_error(space)
                 return space.w_None
         except StackCheckError, e:
             raise OperationError(space.w_ValueError, space.wrap(e.message))
@@ -615,12 +620,10 @@
 
 if sys.platform == 'win32':
     def get_last_error(space):
-        from rpython.rlib.rwin32 import GetLastError
-        return space.wrap(GetLastError())
+        return space.wrap(lasterror.fetch_last_error(space))
     @unwrap_spec(error=int)
     def set_last_error(space, error):
-        from rpython.rlib.rwin32 import SetLastError
-        SetLastError(error)
+        lasterror.store_last_error(space, error)
 else:
     # always have at least a dummy version of these functions
     # (https://bugs.pypy.org/issue1242)
diff --git a/pypy/module/_rawffi/lasterror.py b/pypy/module/_rawffi/lasterror.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/_rawffi/lasterror.py
@@ -0,0 +1,40 @@
+# For Windows only.
+# https://bitbucket.org/pypy/pypy/issue/1944/ctypes-on-windows-getlasterror
+
+import os
+
+_MS_WINDOWS = os.name == "nt"
+
+
+if _MS_WINDOWS:
+    from rpython.rlib import rwin32
+    from pypy.interpreter.executioncontext import ExecutionContext
+
+
+    ExecutionContext._rawffi_last_error = 0
+
+    def fetch_last_error(space):
+        ec = space.getexecutioncontext()
+        return ec._rawffi_last_error
+
+    def store_last_error(space, last_error):
+        ec = space.getexecutioncontext()
+        ec._rawffi_last_error = last_error
+
+    def restore_last_error(space):
+        ec = space.getexecutioncontext()
+        lasterror = ec._rawffi_last_error
+        rwin32.SetLastError(lasterror)
+
+    def save_last_error(space):
+        lasterror = rwin32.GetLastError()
+        ec = space.getexecutioncontext()
+        ec._rawffi_last_error = lasterror
+
+else:
+
+    def restore_last_error(space):
+        pass
+
+    def save_last_error(space):
+        pass
diff --git a/pypy/module/_rawffi/test/test__rawffi.py b/pypy/module/_rawffi/test/test__rawffi.py
--- a/pypy/module/_rawffi/test/test__rawffi.py
+++ b/pypy/module/_rawffi/test/test__rawffi.py
@@ -16,6 +16,7 @@
         #include "src/precommondefs.h"
         #include <stdlib.h>
         #include <stdio.h>
+        #include <errno.h>
 
         struct x
         {
@@ -204,6 +205,24 @@
             return inp;
         }
 
+        RPY_EXPORTED
+        int check_errno(int incoming)
+        {
+            int old_errno = errno;
+            errno = incoming;
+            return old_errno;
+        }
+
+        #ifdef _WIN32
+        #include <Windows.h>
+        RPY_EXPORTED
+        int check_last_error(int incoming)
+        {
+            int old_errno = GetLastError();
+            SetLastError(incoming);
+            return old_errno;
+        }
+        #endif
         '''))
         eci = ExternalCompilationInfo(include_dirs=[cdir])
         return str(platform.compile([c_file], eci, 'x', standalone=False))
@@ -1150,6 +1169,37 @@
         raises(OverflowError, "arg1[0] = 10**900")
         arg1.free()
 
+    def test_errno(self):
+        import _rawffi
+        lib = _rawffi.CDLL(self.lib_name)
+        A = _rawffi.Array('i')
+        f = lib.ptr('check_errno', ['i'], 'i')
+        _rawffi.set_errno(42)
+        arg = A(1)
+        arg[0] = 43
+        res = f(arg)
+        assert res[0] == 42
+        z = _rawffi.get_errno()
+        assert z == 43
+        arg.free()
+
+    def test_last_error(self):
+        import sys
+        if sys.platform != 'win32':
+            skip("Windows test")
+        import _rawffi
+        lib = _rawffi.CDLL(self.lib_name)
+        A = _rawffi.Array('i')
+        f = lib.ptr('check_last_error', ['i'], 'i')
+        _rawffi.set_last_error(42)
+        arg = A(1)
+        arg[0] = 43
+        res = f(arg)
+        assert res[0] == 42
+        z = _rawffi.get_last_error()
+        assert z == 43
+        arg.free()
+
 
 class AppTestAutoFree:
     spaceconfig = dict(usemodules=['_rawffi', 'struct'])
diff --git a/pypy/module/_ssl/interp_ssl.py b/pypy/module/_ssl/interp_ssl.py
--- a/pypy/module/_ssl/interp_ssl.py
+++ b/pypy/module/_ssl/interp_ssl.py
@@ -52,7 +52,8 @@
 
 if not OPENSSL_NO_SSL2:
     constants["PROTOCOL_SSLv2"]  = PY_SSL_VERSION_SSL2
-constants["PROTOCOL_SSLv3"]  = PY_SSL_VERSION_SSL3
+if not OPENSSL_NO_SSL3:
+    constants["PROTOCOL_SSLv3"]  = PY_SSL_VERSION_SSL3
 constants["PROTOCOL_SSLv23"] = PY_SSL_VERSION_SSL23
 constants["PROTOCOL_TLSv1"]  = PY_SSL_VERSION_TLS1
 
@@ -656,7 +657,7 @@
     # set up context
     if protocol == PY_SSL_VERSION_TLS1:
         method = libssl_TLSv1_method()
-    elif protocol == PY_SSL_VERSION_SSL3:
+    elif protocol == PY_SSL_VERSION_SSL3 and not OPENSSL_NO_SSL3:
         method = libssl_SSLv3_method()
     elif protocol == PY_SSL_VERSION_SSL2 and not OPENSSL_NO_SSL2:
         method = libssl_SSLv2_method()
diff --git a/pypy/module/cpyext/frameobject.py b/pypy/module/cpyext/frameobject.py
--- a/pypy/module/cpyext/frameobject.py
+++ b/pypy/module/cpyext/frameobject.py
@@ -58,7 +58,7 @@
     w_globals = from_ref(space, py_frame.c_f_globals)
 
     frame = space.FrameClass(space, code, w_globals, outer_func=None)
-    frame.f_lineno = py_frame.c_f_lineno
+    frame.f_lineno = rffi.getintfield(py_frame, 'c_f_lineno')
     w_obj = space.wrap(frame)
     track_reference(space, py_obj, w_obj)
     return w_obj
diff --git a/pypy/module/gc/__init__.py b/pypy/module/gc/__init__.py
--- a/pypy/module/gc/__init__.py
+++ b/pypy/module/gc/__init__.py
@@ -30,6 +30,7 @@
                 'get_referrers': 'referents.get_referrers',
                 '_dump_rpy_heap': 'referents._dump_rpy_heap',
                 'get_typeids_z': 'referents.get_typeids_z',
+                'get_typeids_list': 'referents.get_typeids_list',
                 'GcRef': 'referents.W_GcRef',
                 })
         MixedModule.__init__(self, space, w_name)
diff --git a/pypy/module/gc/app_referents.py b/pypy/module/gc/app_referents.py
--- a/pypy/module/gc/app_referents.py
+++ b/pypy/module/gc/app_referents.py
@@ -16,7 +16,8 @@
     [0][0][0][-1] inserted after all GC roots, before all non-roots.
 
     If the argument is a filename and the 'zlib' module is available,
-    we also write a 'typeids.txt' in the same directory, if none exists.
+    we also write 'typeids.txt' and 'typeids.lst' in the same directory,
+    if they don't already exist.
     """
     if isinstance(file, str):
         f = open(file, 'wb')
@@ -30,7 +31,13 @@
             filename2 = os.path.join(os.path.dirname(file), 'typeids.txt')
             if not os.path.exists(filename2):
                 data = zlib.decompress(gc.get_typeids_z())
-                f = open(filename2, 'wb')
+                f = open(filename2, 'w')
+                f.write(data)
+                f.close()
+            filename2 = os.path.join(os.path.dirname(file), 'typeids.lst')
+            if not os.path.exists(filename2):
+                data = ''.join(['%d\n' % n for n in gc.get_typeids_list()])
+                f = open(filename2, 'w')
                 f.write(data)
                 f.close()
     else:
diff --git a/pypy/module/gc/referents.py b/pypy/module/gc/referents.py
--- a/pypy/module/gc/referents.py
+++ b/pypy/module/gc/referents.py
@@ -228,3 +228,8 @@
     a = rgc.get_typeids_z()
     s = ''.join([a[i] for i in range(len(a))])
     return space.wrap(s)
+
+def get_typeids_list(space):
+    l = rgc.get_typeids_list()
+    list_w = [space.wrap(l[i]) for i in range(len(l))]
+    return space.newlist(list_w)
diff --git a/pypy/module/micronumpy/boxes.py b/pypy/module/micronumpy/boxes.py
--- a/pypy/module/micronumpy/boxes.py
+++ b/pypy/module/micronumpy/boxes.py
@@ -60,9 +60,9 @@
     _mixin_ = True
 
     def reduce(self, space):
-        numpypy = space.getbuiltinmodule("_numpypy")
-        assert isinstance(numpypy, MixedModule)
-        multiarray = numpypy.get("multiarray")
+        _numpypy = space.getbuiltinmodule("_numpypy")
+        assert isinstance(_numpypy, MixedModule)
+        multiarray = _numpypy.get("multiarray")
         assert isinstance(multiarray, MixedModule)
         scalar = multiarray.get("scalar")
 
diff --git a/pypy/module/micronumpy/compile.py b/pypy/module/micronumpy/compile.py
--- a/pypy/module/micronumpy/compile.py
+++ b/pypy/module/micronumpy/compile.py
@@ -34,8 +34,8 @@
 
 
 SINGLE_ARG_FUNCTIONS = ["sum", "prod", "max", "min", "all", "any",
-                        "unegative", "flat", "tostring","count_nonzero",
-                        "argsort"]
+                        "unegative", "flat", "tostring", "count_nonzero",
+                        "argsort", "cumsum", "logical_xor_reduce"]
 TWO_ARG_FUNCTIONS = ["dot", 'take', 'searchsorted']
 TWO_ARG_FUNCTIONS_OR_NONE = ['view', 'astype']
 THREE_ARG_FUNCTIONS = ['where']
@@ -559,6 +559,11 @@
                 w_res = arr.descr_any(interp.space)
             elif self.name == "all":
                 w_res = arr.descr_all(interp.space)
+            elif self.name == "cumsum":
+                w_res = arr.descr_cumsum(interp.space)
+            elif self.name == "logical_xor_reduce":
+                logical_xor = ufuncs.get(interp.space).logical_xor
+                w_res = logical_xor.reduce(interp.space, arr, None)
             elif self.name == "unegative":
                 neg = ufuncs.get(interp.space).negative
                 w_res = neg.call(interp.space, [arr], None, None, None)
diff --git a/pypy/module/micronumpy/flagsobj.py b/pypy/module/micronumpy/flagsobj.py
--- a/pypy/module/micronumpy/flagsobj.py
+++ b/pypy/module/micronumpy/flagsobj.py
@@ -5,46 +5,26 @@
 from pypy.interpreter.gateway import interp2app
 from pypy.interpreter.typedef import TypeDef, GetSetProperty
 from pypy.module.micronumpy import constants as NPY
-
+from pypy.module.micronumpy.strides import is_c_contiguous, is_f_contiguous
 
 def enable_flags(arr, flags):
     arr.flags |= flags
 
-
 def clear_flags(arr, flags):
     arr.flags &= ~flags
 
-
- at jit.unroll_safe
 def _update_contiguous_flags(arr):
-    shape = arr.shape
-    strides = arr.strides
-
-    is_c_contig = True
-    sd = arr.dtype.elsize
-    for i in range(len(shape) - 1, -1, -1):
-        dim = shape[i]
-        if strides[i] != sd:
-            is_c_contig = False
-            break
-        if dim == 0:
-            break
-        sd *= dim
+    is_c_contig = is_c_contiguous(arr)
     if is_c_contig:
         enable_flags(arr, NPY.ARRAY_C_CONTIGUOUS)
     else:
         clear_flags(arr, NPY.ARRAY_C_CONTIGUOUS)
 
-    sd = arr.dtype.elsize
-    for i in range(len(shape)):
-        dim = shape[i]
-        if strides[i] != sd:
-            clear_flags(arr, NPY.ARRAY_F_CONTIGUOUS)
-            return
-        if dim == 0:
-            break
-        sd *= dim
-    enable_flags(arr, NPY.ARRAY_F_CONTIGUOUS)
+    is_f_contig = is_f_contiguous(arr)
+    if is_f_contig:
+        enable_flags(arr, NPY.ARRAY_F_CONTIGUOUS)
+    else:
+        clear_flags(arr, NPY.ARRAY_F_CONTIGUOUS)
 
 
 class W_FlagsObject(W_Root):
diff --git a/pypy/module/micronumpy/loop.py b/pypy/module/micronumpy/loop.py
--- a/pypy/module/micronumpy/loop.py
+++ b/pypy/module/micronumpy/loop.py
@@ -250,6 +250,7 @@
 def compute_reduce_cumulative(space, obj, out, calc_dtype, func, identity):
     obj_iter, obj_state = obj.create_iter()
     out_iter, out_state = out.create_iter()
+    out_iter.track_index = False
     if identity is None:
         cur_value = obj_iter.getitem(obj_state).convert_to(space, calc_dtype)
         out_iter.setitem(out_state, cur_value)
diff --git a/pypy/module/micronumpy/ndarray.py b/pypy/module/micronumpy/ndarray.py
--- a/pypy/module/micronumpy/ndarray.py
+++ b/pypy/module/micronumpy/ndarray.py
@@ -19,7 +19,7 @@
     order_converter, shape_converter, searchside_converter
 from pypy.module.micronumpy.flagsobj import W_FlagsObject
 from pypy.module.micronumpy.strides import get_shape_from_iterable, \
-    shape_agreement, shape_agreement_multiple
+    shape_agreement, shape_agreement_multiple, is_c_contiguous, is_f_contiguous
 
 
 def _match_dot_shapes(space, left, right):
@@ -824,7 +824,15 @@
                 raise OperationError(space.w_ValueError, space.wrap(
                     "new type not compatible with array."))
         else:
-            if dims == 1 or impl.get_strides()[0] < impl.get_strides()[-1]:
+            if not is_c_contiguous(impl) and not is_f_contiguous(impl):
+                if old_itemsize != new_itemsize:
+                    raise OperationError(space.w_ValueError, space.wrap(
+                        "new type not compatible with array."))
+                # Strides, shape does not change
+                v = impl.astype(space, dtype)
+                return wrap_impl(space, w_type, self, v) 
+            strides = impl.get_strides()
+            if dims == 1 or strides[0] <strides[-1]:
                 # Column-major, resize first dimension
                 if new_shape[0] * old_itemsize % new_itemsize != 0:
                     raise OperationError(space.w_ValueError, space.wrap(
@@ -1131,9 +1139,9 @@
         from pypy.interpreter.mixedmodule import MixedModule
         from pypy.module.micronumpy.concrete import SliceArray
 
-        numpypy = space.getbuiltinmodule("_numpypy")
-        assert isinstance(numpypy, MixedModule)
-        multiarray = numpypy.get("multiarray")
+        _numpypy = space.getbuiltinmodule("_numpypy")
+        assert isinstance(_numpypy, MixedModule)
+        multiarray = _numpypy.get("multiarray")
         assert isinstance(multiarray, MixedModule)
         reconstruct = multiarray.get("_reconstruct")
         parameters = space.newtuple([self.getclass(space), space.newtuple(
diff --git a/pypy/module/micronumpy/strides.py b/pypy/module/micronumpy/strides.py
--- a/pypy/module/micronumpy/strides.py
+++ b/pypy/module/micronumpy/strides.py
@@ -429,3 +429,35 @@
                     n_old_elems_to_use *= old_shape[oldI]
     assert len(new_strides) == len(new_shape)
     return new_strides[:]
+
+ at jit.unroll_safe
+def is_c_contiguous(arr):
+    shape = arr.get_shape()
+    strides = arr.get_strides()
+    ret = True
+    sd = arr.dtype.elsize
+    for i in range(len(shape) - 1, -1, -1):
+        dim = shape[i]
+        if strides[i] != sd:
+            ret = False
+            break
+        if dim == 0:
+            break
+        sd *= dim
+    return ret
+
+ at jit.unroll_safe
+def is_f_contiguous(arr):
+    shape = arr.get_shape()
+    strides = arr.get_strides()
+    ret = True
+    sd = arr.dtype.elsize
+    for i in range(len(shape)):
+        dim = shape[i]
+        if strides[i] != sd:
+            ret = False
+            break
+        if dim == 0:
+            break
+        sd *= dim
+    return ret
diff --git a/pypy/module/micronumpy/test/test_arrayops.py b/pypy/module/micronumpy/test/test_arrayops.py
--- a/pypy/module/micronumpy/test/test_arrayops.py
+++ b/pypy/module/micronumpy/test/test_arrayops.py
@@ -3,13 +3,13 @@
 
 class AppTestNumSupport(BaseNumpyAppTest):
     def test_zeros(self):
-        from numpypy import zeros
+        from numpy import zeros
         a = zeros(3)
         assert len(a) == 3
         assert a[0] == a[1] == a[2] == 0
 
     def test_empty(self):
-        from numpypy import empty
+        from numpy import empty
         import gc
         for i in range(1000):
             a = empty(3)
@@ -26,26 +26,26 @@
                 "empty() returned a zeroed out array every time")
 
     def test_where(self):
-        from numpypy import where, ones, zeros, array
+        from numpy import where, ones, zeros, array
         a = [1, 2, 3, 0, -3]
         a = where(array(a) > 0, ones(5), zeros(5))
         assert (a == [1, 1, 1, 0, 0]).all()
 
     def test_where_differing_dtypes(self):
-        from numpypy import array, ones, zeros, where
+        from numpy import array, ones, zeros, where
         a = [1, 2, 3, 0, -3]
         a = where(array(a) > 0, ones(5, dtype=int), zeros(5, dtype=float))
         assert (a == [1, 1, 1, 0, 0]).all()
 
     def test_where_broadcast(self):
-        from numpypy import array, where
+        from numpy import array, where
         a = where(array([[1, 2, 3], [4, 5, 6]]) > 3, [1, 1, 1], 2)
         assert (a == [[2, 2, 2], [1, 1, 1]]).all()
         a = where(True, [1, 1, 1], 2)
         assert (a == [1, 1, 1]).all()
 
     def test_where_errors(self):
-        from numpypy import where, array
+        from numpy import where, array
         raises(ValueError, "where([1, 2, 3], [3, 4, 5])")
         raises(ValueError, "where([1, 2, 3], [3, 4, 5], [6, 7])")
         assert where(True, 1, 2) == array(1)
@@ -58,14 +58,14 @@
     #    xxx
 
     def test_where_invalidates(self):
-        from numpypy import where, ones, zeros, array
+        from numpy import where, ones, zeros, array
         a = array([1, 2, 3, 0, -3])
         b = where(a > 0, ones(5), zeros(5))
         a[0] = 0
         assert (b == [1, 1, 1, 0, 0]).all()
 
     def test_dot_basic(self):
-        from numpypy import array, dot, arange
+        from numpy import array, dot, arange
         a = array(range(5))
         assert dot(a, a) == 30.0
 
@@ -100,7 +100,7 @@
         assert (dot([[1,2],[3,4]],[5,6]) == [17, 39]).all()
 
     def test_dot_constant(self):
-        from numpypy import array, dot
+        from numpy import array, dot
         a = array(range(5))
         b = a.dot(2.5)
         for i in xrange(5):
@@ -111,7 +111,7 @@
         assert c == 12.0
 
     def test_dot_out(self):
-        from numpypy import arange, dot
+        from numpy import arange, dot
         a = arange(12).reshape(3, 4)
         b = arange(12).reshape(4, 3)
         out = arange(9).reshape(3, 3)
@@ -124,19 +124,19 @@
                                 'right type, nr dimensions, and be a C-Array)')
 
     def test_choose_basic(self):
-        from numpypy import array
+        from numpy import array
         a, b, c = array([1, 2, 3]), array([4, 5, 6]), array([7, 8, 9])
         r = array([2, 1, 0]).choose([a, b, c])
         assert (r == [7, 5, 3]).all()
 
     def test_choose_broadcast(self):
-        from numpypy import array
+        from numpy import array
         a, b, c = array([1, 2, 3]), [4, 5, 6], 13
         r = array([2, 1, 0]).choose([a, b, c])
         assert (r == [13, 5, 3]).all()
 
     def test_choose_out(self):
-        from numpypy import array
+        from numpy import array
         a, b, c = array([1, 2, 3]), [4, 5, 6], 13
         r = array([2, 1, 0]).choose([a, b, c], out=None)
         assert (r == [13, 5, 3]).all()
@@ -146,7 +146,7 @@
         assert (a == [13, 5, 3]).all()
 
     def test_choose_modes(self):
-        from numpypy import array
+        from numpy import array
         a, b, c = array([1, 2, 3]), [4, 5, 6], 13
         raises(ValueError, "array([3, 1, 0]).choose([a, b, c])")
         raises(ValueError, "array([3, 1, 0]).choose([a, b, c], mode='raises')")
@@ -158,20 +158,20 @@
         assert (r == [4, 5, 3]).all()
 
     def test_choose_dtype(self):
-        from numpypy import array
+        from numpy import array
         a, b, c = array([1.2, 2, 3]), [4, 5, 6], 13
         r = array([2, 1, 0]).choose([a, b, c])
         assert r.dtype == float
 
     def test_choose_dtype_out(self):
-        from numpypy import array
+        from numpy import array
         a, b, c = array([1, 2, 3]), [4, 5, 6], 13
         x = array([0, 0, 0], dtype='i2')
         r = array([2, 1, 0]).choose([a, b, c], out=x)
         assert r.dtype == 'i2'
 
     def test_put_basic(self):
-        from numpypy import arange, array
+        from numpy import arange, array
         a = arange(5)
         a.put([0, 2], [-44, -55])
         assert (a == array([-44, 1, -55, 3, 4])).all()
@@ -183,7 +183,7 @@
         assert (a == array([0, 7, 2, 3, 4])).all()
 
     def test_put_modes(self):
-        from numpypy import array, arange
+        from numpy import array, arange
         a = arange(5)
         a.put(22, -5, mode='clip')
         assert (a == array([0, 1, 2, 3, -5])).all()
diff --git a/pypy/module/micronumpy/test/test_base.py b/pypy/module/micronumpy/test/test_base.py
--- a/pypy/module/micronumpy/test/test_base.py
+++ b/pypy/module/micronumpy/test/test_base.py
@@ -14,15 +14,12 @@
             else:
                 from . import dummy_module as numpy
                 sys.modules['numpy'] = numpy
-            sys.modules['numpypy'] = numpy
         else:
             import os
             path = os.path.dirname(__file__) + '/dummy_module.py'
             cls.space.appexec([cls.space.wrap(path)], """(path):
             import imp
-            numpy = imp.load_source('numpy', path)
-            import sys
-            sys.modules['numpypy'] = numpy
+            imp.load_source('numpy', path)
             """)
         cls.w_non_native_prefix = cls.space.wrap(NPY.OPPBYTE)
         cls.w_native_prefix = cls.space.wrap(NPY.NATBYTE)
diff --git a/pypy/module/micronumpy/test/test_complex.py b/pypy/module/micronumpy/test/test_complex.py
--- a/pypy/module/micronumpy/test/test_complex.py
+++ b/pypy/module/micronumpy/test/test_complex.py
@@ -132,13 +132,13 @@
             cls.w_c_pow = cls.space.wrap(interp2app(cls_c_pow))
 
     def test_fabs(self):
-        from numpypy import fabs, dtype
+        from numpy import fabs, dtype
 
         a = dtype('complex128').type(complex(-5., 5.))
         raises(TypeError, fabs, a)
 
     def test_fmax(self):
-        from numpypy import fmax, array
+        from numpy import fmax, array
         nnan, nan, inf, ninf = float('-nan'), float('nan'), float('inf'), float('-inf')
         a = array((complex(ninf, 10), complex(10, ninf),
                    complex( inf, 10), complex(10,  inf),
@@ -165,7 +165,7 @@
         assert (fmax(a, b) == res).all()
 
     def test_fmin(self):
-        from numpypy import fmin, array
+        from numpy import fmin, array
         nnan, nan, inf, ninf = float('-nan'), float('nan'), float('inf'), float('-inf')
         a = array((complex(ninf, 10), complex(10, ninf),
                    complex( inf, 10), complex(10,  inf),
@@ -192,11 +192,11 @@
         assert (fmin(a, b) == res).all()
 
     def test_signbit(self):
-        from numpypy import signbit
+        from numpy import signbit
         raises(TypeError, signbit, complex(1,1))
 
     def test_reciprocal(self):
-        from numpypy import array, reciprocal
+        from numpy import array, reciprocal
         inf = float('inf')
         nan = float('nan')
         #complex
@@ -218,21 +218,21 @@
                 assert (a[0].imag - e.imag) < rel_err
 
     def test_floorceiltrunc(self):
-        from numpypy import array, floor, ceil, trunc
+        from numpy import array, floor, ceil, trunc
         a = array([ complex(-1.4, -1.4), complex(-1.5, -1.5)])
         raises(TypeError, floor, a)
         raises(TypeError, ceil, a)
         raises(TypeError, trunc, a)
 
     def test_copysign(self):
-        from numpypy import copysign, dtype
+        from numpy import copysign, dtype
         complex128 = dtype('complex128').type
         a = complex128(complex(-5., 5.))
         b = complex128(complex(0., 0.))
         raises(TypeError, copysign, a, b)
 
     def test_exp2(self):
-        from numpypy import array, exp2
+        from numpy import array, exp2
         inf = float('inf')
         ninf = -float('inf')
         nan = float('nan')
@@ -268,7 +268,7 @@
 
     def test_expm1(self):
         import math, cmath
-        from numpypy import array, expm1
+        from numpy import array, expm1
         inf = float('inf')
         ninf = -float('inf')
         nan = float('nan')
@@ -307,7 +307,7 @@
                 self.rAlmostEqual(t1, t2, rel_err=rel_err, msg=msg)
 
     def test_not_complex(self):
-        from numpypy import (radians, deg2rad, degrees, rad2deg,
+        from numpy import (radians, deg2rad, degrees, rad2deg,
                   logaddexp, logaddexp2, fmod,
                   arctan2)
         raises(TypeError, radians, complex(90,90))
@@ -320,7 +320,7 @@
         raises (TypeError, fmod, complex(90,90), 3)
 
     def test_isnan_isinf(self):
-        from numpypy import isnan, isinf, array
+        from numpy import isnan, isinf, array
         assert (isnan(array([0.2+2j, complex(float('inf'),0),
                 complex(0,float('inf')), complex(0,float('nan')),
                 complex(float('nan'), 0)], dtype=complex)) == \
@@ -333,7 +333,7 @@
 
 
     def test_square(self):
-        from numpypy import square
+        from numpy import square
         assert square(complex(3, 4)) == complex(3,4) * complex(3, 4)
 
     def test_power_simple(self):
@@ -364,8 +364,8 @@
             self.rAlmostEqual(float(n_r_a[i].imag), float(p_r[i].imag), msg=msg)
 
     def test_conjugate(self):
-        from numpypy import conj, conjugate, dtype
-        import numpypy as np
+        from numpy import conj, conjugate, dtype
+        import numpy as np
 
         c0 = dtype('complex128').type(complex(2.5, 0))
         c1 = dtype('complex64').type(complex(1, 2))
@@ -390,7 +390,7 @@
     def test_logn(self):
         import math, cmath
         # log and log10 are tested in math (1:1 from rcomplex)
-        from numpypy import log2, array, log1p
+        from numpy import log2, array, log1p
         inf = float('inf')
         ninf = -float('inf')
         nan = float('nan')
@@ -447,7 +447,7 @@
                 self.rAlmostEqual(t1, t2, rel_err=rel_err, msg=msg)
 
     def test_logical_ops(self):
-        from numpypy import logical_and, logical_or, logical_xor, logical_not
+        from numpy import logical_and, logical_or, logical_xor, logical_not
 
         c1 = complex(1, 1)
         c3 = complex(3, 0)
@@ -461,7 +461,7 @@
         assert (logical_not([c1, c0]) == [False, True]).all()
 
     def test_minimum(self):
-        from numpypy import array, minimum
+        from numpy import array, minimum
 
         a = array([-5.0+5j, -5.0-5j, -0.0-10j, 1.0+10j])
         b = array([ 3.0+10.0j, 3.0, -2.0+2.0j, -3.0+4.0j])
@@ -470,7 +470,7 @@
             assert c[i] == min(a[i], b[i])
 
     def test_maximum(self):
-        from numpypy import array, maximum
+        from numpy import array, maximum
 
         a = array([-5.0+5j, -5.0-5j, -0.0-10j, 1.0+10j])
         b = array([ 3.0+10.0j, 3.0, -2.0+2.0j, -3.0+4.0j])
@@ -480,10 +480,10 @@
 
     def test_basic(self):
         import sys
-        from numpypy import (dtype, add, array, dtype,
+        from numpy import (dtype, add, array, dtype,
             subtract as sub, multiply, divide, negative, absolute as abs,
             floor_divide, real, imag, sign)
-        from numpypy import (equal, not_equal, greater, greater_equal, less,
+        from numpy import (equal, not_equal, greater, greater_equal, less,
                 less_equal, isnan)
         assert real(4.0) == 4.0
         assert imag(0.0) == 0.0
@@ -579,7 +579,7 @@
             assert repr(abs(inf_c)) == 'inf'
             assert repr(abs(complex(float('nan'), float('nan')))) == 'nan'
             # numpy actually raises an AttributeError,
-            # but numpypy raises a TypeError
+            # but numpy.raises a TypeError
             if '__pypy__' in sys.builtin_module_names:
                 exct, excm = TypeError, 'readonly attribute'
             else:
@@ -592,7 +592,7 @@
             assert(imag(c2) == 4.0)
 
     def test_conj(self):
-        from numpypy import array
+        from numpy import array
 
         a = array([1 + 2j, 1 - 2j])
         assert (a.conj() == [1 - 2j, 1 + 2j]).all()
@@ -603,7 +603,7 @@
         if self.isWindows:
             skip('windows does not support c99 complex')
         import sys
-        import numpypy as np
+        import numpy as np
         rAlmostEqual = self.rAlmostEqual
 
         for t, testcases in (
@@ -658,6 +658,6 @@
             sys.stderr.write('\n')
 
     def test_complexbox_to_pycomplex(self):
-        from numpypy import dtype
+        from numpy import dtype
         x = dtype('complex128').type(3.4j)
         assert complex(x) == 3.4j
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
@@ -23,7 +23,7 @@
             from numpy.core.multiarray import typeinfo
         except ImportError:
             # running on dummy module
-            from numpypy import typeinfo
+            from numpy import typeinfo
         assert typeinfo['Number'] == np.number
         assert typeinfo['LONGLONG'] == ('q', 9, 64, 8, 9223372036854775807L,
                                         -9223372036854775808L, np.longlong)
@@ -39,7 +39,7 @@
                                     np.dtype('int').type)
 
     def test_dtype_basic(self):
-        from numpypy import dtype
+        from numpy import dtype
         import sys
 
         d = dtype('?')
@@ -104,7 +104,7 @@
         assert d.shape == ()
 
     def test_dtype_eq(self):
-        from numpypy import dtype
+        from numpy import dtype
 
         assert dtype("int8") == "int8"
         assert "int8" == dtype("int8")
@@ -112,7 +112,7 @@
         assert dtype(bool) == bool
 
     def test_dtype_aliases(self):
-        from numpypy import dtype
+        from numpy import dtype
         assert dtype('bool8') is dtype('bool')
         assert dtype('byte') is dtype('int8')
         assert dtype('ubyte') is dtype('uint8')
@@ -132,7 +132,7 @@
         assert dtype('clongdouble').num in (15, 16)
 
     def test_dtype_with_types(self):
-        from numpypy import dtype
+        from numpy import dtype
 
         assert dtype(bool).num == 0
         if self.ptr_size == 4:
@@ -156,7 +156,7 @@
         assert dtype('complex').num == 15
 
     def test_array_dtype_attr(self):
-        from numpypy import array, dtype
+        from numpy import array, dtype
 
         a = array(range(5), long)
         assert a.dtype is dtype(long)
@@ -182,7 +182,7 @@
         assert np.dtype('S5').isbuiltin == 0
 
     def test_repr_str(self):
-        from numpypy import dtype
+        from numpy import dtype
         b = dtype(int).newbyteorder().newbyteorder().byteorder
         assert '.dtype' in repr(dtype)
         d = dtype('?')
@@ -208,7 +208,7 @@
         assert str(d) == "|V16"
 
     def test_bool_array(self):
-        from numpypy import array, False_, True_
+        from numpy import array, False_, True_
 
         a = array([0, 1, 2, 2.5], dtype='?')
         assert a[0] is False_
@@ -216,7 +216,7 @@
             assert a[i] is True_
 
     def test_copy_array_with_dtype(self):
-        from numpypy import array, longlong, False_
+        from numpy import array, longlong, False_
 
         a = array([0, 1, 2, 3], dtype=long)
         # int on 64-bit, long in 32-bit
@@ -230,35 +230,35 @@
         assert b[0] is False_
 
     def test_zeros_bool(self):
-        from numpypy import zeros, False_
+        from numpy import zeros, False_
 
         a = zeros(10, dtype=bool)
         for i in range(10):
             assert a[i] is False_
 
     def test_ones_bool(self):
-        from numpypy import ones, True_
+        from numpy import ones, True_
 
         a = ones(10, dtype=bool)
         for i in range(10):
             assert a[i] is True_
 
     def test_zeros_long(self):
-        from numpypy import zeros, longlong
+        from numpy import zeros, longlong
         a = zeros(10, dtype=long)
         for i in range(10):
             assert isinstance(a[i], longlong)
             assert a[1] == 0
 
     def test_ones_long(self):
-        from numpypy import ones, longlong
+        from numpy import ones, longlong
         a = ones(10, dtype=long)
         for i in range(10):
             assert isinstance(a[i], longlong)
             assert a[1] == 1
 
     def test_overflow(self):
-        from numpypy import array, dtype
+        from numpy import array, dtype
         assert array([128], 'b')[0] == -128
         assert array([256], 'B')[0] == 0
         assert array([32768], 'h')[0] == -32768
@@ -273,7 +273,7 @@
         raises(OverflowError, "array([2**64], 'Q')")
 
     def test_bool_binop_types(self):
-        from numpypy import array, dtype
+        from numpy import array, dtype
         types = [
             '?', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd',
             'e'
@@ -285,7 +285,7 @@
             assert (a + array([0], t)).dtype is dtype(t)
 
     def test_binop_types(self):
-        from numpypy import array, dtype
+        from numpy import array, dtype
         tests = [('b','B','h'), ('b','h','h'), ('b','H','i'), ('b','i','i'),
                  ('b','l','l'), ('b','q','q'), ('b','Q','d'), ('B','h','h'),
                  ('B','H','H'), ('B','i','i'), ('B','I','I'), ('B','l','l'),
@@ -309,7 +309,7 @@
             assert (d1, d2) == (d1, d2) and d3 is dtype(dout)
 
     def test_add(self):
-        import numpypy as np
+        import numpy as np
         for dtype in ["int8", "int16", "I"]:
             a = np.array(range(5), dtype=dtype)
             b = a + a
@@ -325,22 +325,22 @@
         assert len(d) == 2
 
     def test_shape(self):
-        from numpypy import dtype
+        from numpy import dtype
         assert dtype(long).shape == ()
 
     def test_cant_subclass(self):
-        from numpypy import dtype
+        from numpy import dtype
         # You can't subclass dtype
         raises(TypeError, type, "Foo", (dtype,), {})
 
     def test_can_subclass(self):
-        import numpypy
-        class xyz(numpypy.void):
+        import numpy
+        class xyz(numpy.void):
             pass
         assert True
 
     def test_index(self):
-        import numpypy as np
+        import numpy as np
         for dtype in [np.int8, np.int16, np.int32, np.int64]:
             a = np.array(range(10), dtype=dtype)
             b = np.array([0] * 10, dtype=dtype)
@@ -348,7 +348,7 @@
                 a[idx] += 1
 
     def test_hash(self):
-        import numpypy as numpy
+        import numpy
         for tp, value in [
             (numpy.int8, 4),
             (numpy.int16, 5),
@@ -395,7 +395,7 @@
 
     def test_pickle(self):
         import numpy as np
-        from numpypy import array, dtype
+        from numpy import array, dtype
         from cPickle import loads, dumps
         a = array([1,2,3])
         if self.ptr_size == 8:
@@ -408,7 +408,7 @@
         assert np.dtype(('<f8', 2)).__reduce__() == (dtype, ('V16', 0, 1), (3, '|', (dtype('float64'), (2,)), None, None, 16, 1, 0))
 
     def test_newbyteorder(self):
-        import numpypy as np
+        import numpy as np
         import sys
         sys_is_le = sys.byteorder == 'little'
         native_code = sys_is_le and '<' or '>'
@@ -480,7 +480,7 @@
 
 class AppTestTypes(BaseAppTestDtypes):
     def test_abstract_types(self):
-        import numpypy as numpy
+        import numpy
 
         raises(TypeError, numpy.generic, 0)
         raises(TypeError, numpy.number, 0)
@@ -526,16 +526,16 @@
         #assert a.dtype is numpy.dtype('|V4')
 
     def test_new(self):
-        import numpypy as np
+        import numpy as np
         assert np.int_(4) == 4
         assert np.float_(3.4) == 3.4
 
     def test_pow(self):
-        from numpypy import int_
+        from numpy import int_
         assert int_(4) ** 2 == 16
 
     def test_bool(self):
-        import numpypy as numpy
+        import numpy
 
         assert numpy.bool_.mro() == [numpy.bool_, numpy.generic, object]
         assert numpy.bool_(3) is numpy.True_
@@ -550,7 +550,7 @@
         assert numpy.bool_("False") is numpy.True_
 
     def test_int8(self):
-        import numpypy as numpy
+        import numpy
 
         assert numpy.int8.mro() == [numpy.int8, numpy.signedinteger,
                                     numpy.integer, numpy.number,
@@ -574,7 +574,7 @@
         assert numpy.int8('128') == -128
 
     def test_uint8(self):
-        import numpypy as numpy
+        import numpy
 
         assert numpy.uint8.mro() == [numpy.uint8, numpy.unsignedinteger,
                                      numpy.integer, numpy.number,
@@ -599,7 +599,7 @@
         assert numpy.uint8('256') == 0
 
     def test_int16(self):
-        import numpypy as numpy
+        import numpy
 
         x = numpy.int16(3)
         assert x == 3
@@ -641,7 +641,7 @@
             assert numpy.uint32('4294967296') == 0
 
     def test_int_(self):
-        import numpypy as numpy
+        import numpy
 
         assert numpy.int_ is numpy.dtype(int).type
         assert numpy.int_.mro() == [numpy.int_, numpy.signedinteger,
@@ -752,7 +752,7 @@
 
     def test_complex_format(self):
         import sys
-        import numpypy as numpy
+        import numpy
 
         for complex_ in (numpy.complex128, numpy.complex64,):
             for real, imag, should in [
@@ -792,7 +792,7 @@
             assert "{:g}".format(numpy.complex_(0.5+1.5j)) == '{:g}'.format(0.5+1.5j)
 
     def test_complex(self):
-        import numpypy as numpy
+        import numpy
 
         assert numpy.complex_ is numpy.complex128
         assert numpy.csingle is numpy.complex64
@@ -812,7 +812,7 @@
         assert d.char == 'F'
 
     def test_subclass_type(self):
-        import numpypy as numpy
+        import numpy
 
         class X(numpy.float64):
             def m(self):
@@ -826,12 +826,12 @@
         assert b.dtype.type is numpy.float64
 
     def test_long_as_index(self):
-        from numpypy import int_, float64
+        from numpy import int_, float64
         assert (1, 2, 3)[int_(1)] == 2
         raises(TypeError, lambda: (1, 2, 3)[float64(1)])
 
     def test_int(self):
-        from numpypy import int32, int64, int_
+        from numpy import int32, int64, int_
         import sys
         assert issubclass(int_, int)
         if sys.maxint == (1<<31) - 1:
@@ -842,7 +842,7 @@
             assert int_ is int64
 
     def test_various_types(self):
-        import numpypy as numpy
+        import numpy
 
         assert numpy.int16 is numpy.short
         assert numpy.int8 is numpy.byte
@@ -864,7 +864,7 @@
         assert not issubclass(numpy.longfloat, numpy.float64)
 
     def test_mro(self):
-        import numpypy as numpy
+        import numpy
 
         assert numpy.int16.__mro__ == (numpy.int16, numpy.signedinteger,
                                        numpy.integer, numpy.number,
@@ -873,7 +873,7 @@
 
     def test_operators(self):
         from operator import truediv
-        from numpypy import float64, int_, True_, False_
+        from numpy import float64, int_, True_, False_
         assert 5 / int_(2) == int_(2)
         assert truediv(int_(3), int_(2)) == float64(1.5)
         assert truediv(3, int_(2)) == float64(1.5)
@@ -899,7 +899,7 @@
 
     def test_alternate_constructs(self):
         import numpy as np
-        from numpypy import dtype
+        from numpy import dtype
         nnp = self.non_native_prefix
         byteorder = self.native_prefix
         assert dtype('i8') == dtype(byteorder + 'i8') == dtype('=i8') == dtype(long)
@@ -922,7 +922,7 @@
         assert d.str == '|S0'
 
     def test_dtype_str(self):
-        from numpypy import dtype
+        from numpy import dtype
         byteorder = self.native_prefix
         assert dtype('i8').str == byteorder + 'i8'
         assert dtype('<i8').str == '<i8'
@@ -949,7 +949,7 @@
         assert dtype(('f8', 2)).str == "|V16"
 
     def test_intp(self):
-        from numpypy import dtype
+        from numpy import dtype
         for s in ['p', 'int']:
             assert dtype(s) is dtype('intp')
         for s in ['P', 'uint']:
@@ -968,16 +968,16 @@
             assert dtype('P').name == 'uint64'
 
     def test_alignment(self):
-        from numpypy import dtype
+        from numpy import dtype
         assert dtype('i4').alignment == 4
 
     def test_isnative(self):
-        from numpypy import dtype
+        from numpy import dtype
         assert dtype('i4').isnative == True
         assert dtype('>i8').isnative == False
 
     def test_any_all_nonzero(self):
-        import numpypy as numpy
+        import numpy
         x = numpy.bool_(True)
         assert x.any() is numpy.True_
         assert x.all() is numpy.True_
@@ -1000,7 +1000,7 @@
         assert x.__nonzero__() is True
 
     def test_ravel(self):
-        from numpypy import float64, int8, array
+        from numpy import float64, int8, array
         x = float64(42.5).ravel()
         assert x.dtype == float64
         assert (x == array([42.5])).all()
@@ -1023,7 +1023,7 @@
 
 class AppTestStrUnicodeDtypes(BaseNumpyAppTest):
     def test_mro(self):
-        from numpypy import str_, unicode_, character, flexible, generic
+        from numpy import str_, unicode_, character, flexible, generic
         import sys
         if '__pypy__' in sys.builtin_module_names:
             assert str_.mro() == [str_, character, flexible, generic,
@@ -1037,7 +1037,7 @@
                                       flexible, generic, object]
 
     def test_str_dtype(self):
-        from numpypy import dtype, str_
+        from numpy import dtype, str_
 
         raises(TypeError, "dtype('Sx')")
         for t in ['S8', '|S8', '=S8']:
@@ -1058,7 +1058,7 @@
             assert d.str == '|S1'
 
     def test_unicode_dtype(self):
-        from numpypy import dtype, unicode_
+        from numpy import dtype, unicode_
 
         raises(TypeError, "dtype('Ux')")
         d = dtype('U8')
@@ -1070,11 +1070,11 @@
         assert d.num == 19
 
     def test_string_boxes(self):
-        from numpypy import str_
+        from numpy import str_
         assert isinstance(str_(3), str_)
 
     def test_unicode_boxes(self):
-        from numpypy import unicode_
+        from numpy import unicode_
         import sys
         if '__pypy__' in sys.builtin_module_names:
             exc = raises(NotImplementedError, unicode_, 3)
@@ -1085,7 +1085,7 @@
 
     def test_character_dtype(self):
         import numpy as np
-        from numpypy import array, character
+        from numpy import array, character
         x = array([["A", "B"], ["C", "D"]], character)
         assert (x == [["A", "B"], ["C", "D"]]).all()
         d = np.dtype('c')
@@ -1098,7 +1098,7 @@
     spaceconfig = dict(usemodules=["micronumpy", "struct", "binascii"])
 
     def test_create(self):
-        from numpypy import dtype, void
+        from numpy import dtype, void
 
         raises(ValueError, "dtype([('x', int), ('x', float)])")
         d = dtype([("x", "<i4"), ("y", "<f4"), ("z", "<u2"), ("v", "<f8")])
@@ -1157,7 +1157,7 @@
             raises(NotImplementedError, np.dtype, d)
 
     def test_create_subarrays(self):
-        from numpypy import dtype
+        from numpy import dtype
         d = dtype([("x", "float", (2,)), ("y", "int64", (2,))])
         assert d.itemsize == 32
         assert d.name == "void256"
@@ -1278,7 +1278,7 @@
         assert repr(d) == "dtype([('f0', '<f8'), ('f1', '<f8')])"
 
     def test_pickle_record(self):
-        from numpypy import array, dtype
+        from numpy import array, dtype
         from cPickle import loads, dumps
 
         d = dtype([("x", "int32"), ("y", "int32"), ("z", "int32"), ("value", float)])
@@ -1289,7 +1289,7 @@
         assert new_d.__reduce__() == d.__reduce__()
 
     def test_pickle_record_subarrays(self):
-        from numpypy import array, dtype
+        from numpy import array, dtype
         from cPickle import loads, dumps
 
         d = dtype([("x", "int32", (3,)), ("y", "int32", (2,)), ("z", "int32", (4,)), ("value", float, (5,))])
@@ -1321,7 +1321,7 @@
             cls.w_check_non_native = cls.space.wrap(interp2app(check_non_native))
 
     def test_non_native(self):
-        from numpypy import array
+        from numpy import array
         a = array([1, 2, 3], dtype=self.non_native_prefix + 'i2')
         assert a[0] == 1
         assert (a + a)[1] == 4
@@ -1344,7 +1344,7 @@
 
 class AppTestObjectDtypes(BaseNumpyAppTest):
     def test_scalar_from_object(self):
-        from numpypy import array
+        from numpy import array
         import sys
         class Polynomial(object):
             pass
diff --git a/pypy/module/micronumpy/test/test_iterators.py b/pypy/module/micronumpy/test/test_iterators.py
--- a/pypy/module/micronumpy/test/test_iterators.py
+++ b/pypy/module/micronumpy/test/test_iterators.py
@@ -13,6 +13,11 @@
         self.strides = strides
         self.start = start
 
+    def get_shape(self):
+        return self.shape
+
+    def get_strides(self):
+        return self.strides
 
 class TestIterDirect(object):
     def test_iterator_basic(self):
diff --git a/pypy/module/micronumpy/test/test_ndarray.py b/pypy/module/micronumpy/test/test_ndarray.py
--- a/pypy/module/micronumpy/test/test_ndarray.py
+++ b/pypy/module/micronumpy/test/test_ndarray.py
@@ -269,13 +269,13 @@
                 assert not a.flags['F']
 
     def test_ndmin(self):
-        from numpypy import array
+        from numpy import array
 
         arr = array([[[1]]], ndmin=1)
         assert arr.shape == (1, 1, 1)
 
     def test_noop_ndmin(self):
-        from numpypy import array
+        from numpy import array
         arr = array([1], ndmin=3)
         assert arr.shape == (1, 1, 1)
 
@@ -289,7 +289,7 @@
         assert a.dtype == np.intp
 
     def test_array_copy(self):
-        from numpypy import array
+        from numpy import array
         a = array(range(12)).reshape(3,4)
         b = array(a, ndmin=4)
         assert b.shape == (1, 1, 3, 4)
@@ -353,12 +353,12 @@
         assert str(exc.value) == 'buffer is read-only'
 
     def test_type(self):
-        from numpypy import array
+        from numpy import array
         ar = array(range(5))
         assert type(ar) is type(ar + ar)
 
     def test_ndim(self):
-        from numpypy import array
+        from numpy import array
         x = array(0.2)
         assert x.ndim == 0
         x = array([1, 2])
@@ -367,12 +367,12 @@
         assert x.ndim == 2
         x = array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])
         assert x.ndim == 3
-        # numpy actually raises an AttributeError, but numpypy raises an
+        # numpy actually raises an AttributeError, but numpy.raises an
         # TypeError
         raises((TypeError, AttributeError), 'x.ndim = 3')
 
     def test_zeros(self):
-        from numpypy import zeros
+        from numpy import zeros
         a = zeros(15)
         # Check that storage was actually zero'd.
         assert a[10] == 0.0
@@ -431,7 +431,7 @@
         assert type(b) is np.ndarray
 
     def test_size(self):
-        from numpypy import array,arange,cos
+        from numpy import array,arange,cos
         assert array(3).size == 1
         a = array([1, 2, 3])
         assert a.size == 3
@@ -440,13 +440,13 @@
         assert ten == 10
 
     def test_empty(self):
-        from numpypy import empty
+        from numpy import empty
         a = empty(2)
         a[1] = 1.0
         assert a[1] == 1.0
 
     def test_ones(self):
-        from numpypy import ones, dtype
+        from numpy import ones, dtype
         a = ones(3)
         assert len(a) == 3
         assert a[0] == 1
@@ -458,7 +458,7 @@
         assert b.dtype is dtype(complex)
 
     def test_arange(self):
-        from numpypy import arange, dtype
+        from numpy import arange, dtype
         a = arange(3)
         assert (a == [0, 1, 2]).all()
         assert a.dtype is dtype(int)
@@ -480,7 +480,7 @@
         assert arange(False, True, True).dtype is dtype(int)
 
     def test_copy(self):
-        from numpypy import arange, array
+        from numpy import arange, array
         a = arange(5)
         b = a.copy()
         for i in xrange(5):
@@ -522,7 +522,7 @@
             raises(NotImplementedError, a.copy, order=True)
 
     def test_iterator_init(self):
-        from numpypy import array
+        from numpy import array
         a = array(range(5))
         assert a[3] == 3
 
@@ -546,7 +546,7 @@
         assert (a == [[1], [2]]).all()
 
     def test_getitem(self):
-        from numpypy import array
+        from numpy import array
         a = array(range(5))
         raises(IndexError, "a[5]")
         a = a + a
@@ -555,14 +555,14 @@
         raises(IndexError, "a[-6]")
 
     def test_getitem_float(self):
-        from numpypy import array
+        from numpy import array
         a = array([1, 2, 3, 4])
         assert a[1.2] == 2
         assert a[1.6] == 2
         assert a[-1.2] == 4
 
     def test_getitem_tuple(self):
-        from numpypy import array
+        from numpy import array
         a = array(range(5))
         raises(IndexError, "a[(1,2)]")
         for i in xrange(5):
@@ -572,28 +572,28 @@
             assert a[i] == b[i]
 
     def test_getitem_nd(self):
-        from numpypy import arange
+        from numpy import arange
         a = arange(15).reshape(3, 5)
         assert a[1, 3] == 8
         assert a.T[1, 2] == 11
 
     def test_getitem_obj_index(self):
-        from numpypy import arange
+        from numpy import arange
         a = arange(10)
         assert a[self.CustomIndexObject(1)] == 1
 
     def test_getitem_obj_prefer_index_to_int(self):
-        from numpypy import arange
+        from numpy import arange
         a = arange(10)
         assert a[self.CustomIndexIntObject(0, 1)] == 0
 
     def test_getitem_obj_int(self):
-        from numpypy import arange
+        from numpy import arange
         a = arange(10)
         assert a[self.CustomIntObject(1)] == 1
 
     def test_setitem(self):
-        from numpypy import array
+        from numpy import array
         a = array(range(5))
         a[-1] = 5.0
         assert a[4] == 5.0
@@ -612,7 +612,7 @@
         assert a[2] == -0.005
 
     def test_setitem_tuple(self):
-        from numpypy import array
+        from numpy import array
         a = array(range(5))
         raises(IndexError, "a[(1,2)] = [0,1]")
         for i in xrange(5):
@@ -630,25 +630,25 @@
         assert a[2] == 100
 
     def test_setitem_obj_index(self):
-        from numpypy import arange
+        from numpy import arange
         a = arange(10)
         a[self.CustomIndexObject(1)] = 100
         assert a[1] == 100
 
     def test_setitem_obj_prefer_index_to_int(self):
-        from numpypy import arange
+        from numpy import arange
         a = arange(10)
         a[self.CustomIndexIntObject(0, 1)] = 100
         assert a[0] == 100
 
     def test_setitem_obj_int(self):
-        from numpypy import arange
+        from numpy import arange
         a = arange(10)
         a[self.CustomIntObject(1)] = 100
         assert a[1] == 100
 
     def test_delitem(self):
-        import numpypy as np
+        import numpy as np
         a = np.arange(10)
         exc = raises(ValueError, 'del a[2]')
         assert exc.value.message == 'cannot delete array elements'
@@ -665,7 +665,7 @@
         # numpy will swallow errors in __int__ and __index__ and
         # just raise IndexError.
 
-        from numpypy import arange
+        from numpy import arange
         a = arange(10)
         exc = raises(IndexError, "a[ErrorIndex()] == 0")
         assert exc.value.message == 'cannot convert index to integer'
@@ -673,7 +673,7 @@
         assert exc.value.message == 'cannot convert index to integer'
 
     def test_setslice_array(self):
-        from numpypy import array
+        from numpy import array
         a = array(5)
         exc = raises(ValueError, "a[:] = 4")
         assert exc.value[0] == "cannot slice a 0-d array"
@@ -687,7 +687,7 @@
         assert b[1] == 0.
 
     def test_setslice_of_slice_array(self):
-        from numpypy import array, zeros
+        from numpy import array, zeros
         a = zeros(5)
         a[::2] = array([9., 10., 11.])
         assert a[0] == 9.
@@ -706,7 +706,7 @@
         assert a[0] == 3.
 
     def test_setslice_list(self):
-        from numpypy import array
+        from numpy import array
         a = array(range(5), float)
         b = [0., 1.]
         a[1:4:2] = b
@@ -714,7 +714,7 @@
         assert a[3] == 1.
 
     def test_setslice_constant(self):
-        from numpypy import array
+        from numpy import array
         a = array(range(5), float)
         a[1:4:2] = 0.
         assert a[1] == 0.
@@ -722,7 +722,7 @@
 
     def test_newaxis(self):
         import math
-        from numpypy import array, cos, zeros, newaxis
+        from numpy import array, cos, zeros, newaxis
         a = array(range(5))
         b = array([range(5)])
         assert (a[newaxis] == b).all()
@@ -743,7 +743,7 @@
         assert o == 3
 
     def test_newaxis_slice(self):
-        from numpypy import array, newaxis
+        from numpy import array, newaxis
 
         a = array(range(5))
         b = array(range(1,5))
@@ -755,14 +755,14 @@
         assert (a[newaxis,1:] == c).all()
 
     def test_newaxis_assign(self):
-        from numpypy import array, newaxis
+        from numpy import array, newaxis
 
         a = array(range(5))
         a[newaxis,1] = [2]
         assert a[1] == 2
 
     def test_newaxis_virtual(self):
-        from numpypy import array, newaxis
+        from numpy import array, newaxis
 
         a = array(range(5))
         b = (a + a)[newaxis]
@@ -770,20 +770,20 @@
         assert (b == c).all()
 
     def test_newaxis_then_slice(self):
-        from numpypy import array, newaxis
+        from numpy import array, newaxis
         a = array(range(5))
         b = a[newaxis]
         assert b.shape == (1, 5)
         assert (b[0,1:] == a[1:]).all()
 
     def test_slice_then_newaxis(self):
-        from numpypy import array, newaxis
+        from numpy import array, newaxis
         a = array(range(5))
         b = a[2:]
         assert (b[newaxis] == [[2, 3, 4]]).all()
 
     def test_scalar(self):
-        from numpypy import array, dtype, int_
+        from numpy import array, dtype, int_
         a = array(3)
         exc = raises(IndexError, "a[0]")
         assert exc.value[0] == "0-d arrays can't be indexed"
@@ -816,13 +816,13 @@
         assert a == 2.5
 
     def test_len(self):
-        from numpypy import array
+        from numpy import array
         a = array(range(5))
         assert len(a) == 5
         assert len(a + a) == 5
 
     def test_shape(self):
-        from numpypy import array
+        from numpy import array
         a = array(range(5))
         assert a.shape == (5,)


More information about the pypy-commit mailing list