Commits

Amaury Forgeot d'Arc committed 6844023 Merge

hg merge default again

Comments (0)

Files changed (27)

pypy/interpreter/buffer.py

         elif step == 1:
             length = stop - start
             if length != len(newstring):
-                msg = "buffer slice assignment is wrong size"
-                raise OperationError(space.w_ValueError, space.wrap(msg))
+                if length < 0 and len(newstring) == 0:
+                    pass     # ok anyway
+                else:
+                    msg = "right operand length must match slice length"
+                    raise OperationError(space.w_ValueError, space.wrap(msg))
             self.setslice(start, newstring)
         else:
             raise OperationError(space.w_ValueError,

pypy/jit/metainterp/optimizeopt/rewrite.py

         source_start_box = self.get_constant_box(op.getarg(3))
         dest_start_box = self.get_constant_box(op.getarg(4))
         length = self.get_constant_box(op.getarg(5))
+        extrainfo = op.getdescr().get_extra_info()
         if (source_start_box and dest_start_box
             and length and (dest_value.is_virtual() or length.getint() <= 8) and
-            (source_value.is_virtual() or length.getint() <= 8)):
+            (source_value.is_virtual() or length.getint() <= 8) and
+            len(extrainfo.write_descrs_arrays) == 1):   # <-sanity check
             from pypy.jit.metainterp.optimizeopt.virtualize import VArrayValue
             source_start = source_start_box.getint()
             dest_start = dest_start_box.getint()
+            # XXX fish fish fish
+            arraydescr = extrainfo.write_descrs_arrays[0]
             for index in range(length.getint()):
-                # XXX fish fish fish
-                arraydescr = op.getdescr().get_extra_info().write_descrs_arrays[0]
                 if source_value.is_virtual():
                     assert isinstance(source_value, VArrayValue)
                     val = source_value.getitem(index + source_start)

pypy/module/__builtin__/test/test_buffer.py

         b[:] = '12345'
         assert a.tostring() == 'hello 12345'
         raises(IndexError, 'b[5] = "."')
+        b[4:2] = ''
+        assert a.tostring() == 'hello 12345'
 
         b = buffer(b, 2)
         assert len(b) == 3

pypy/module/_cffi_backend/cbuffer.py

 from pypy.interpreter.error import operationerrfmt
 from pypy.interpreter.buffer import RWBuffer
-from pypy.interpreter.gateway import unwrap_spec
+from pypy.interpreter.gateway import unwrap_spec, interp2app
+from pypy.interpreter.typedef import TypeDef
 from pypy.rpython.lltypesystem import rffi
 from pypy.module._cffi_backend import cdataobj, ctypeptr, ctypearray
 
         for i in range(len(string)):
             raw_cdata[i] = string[i]
 
+LLBuffer.typedef = TypeDef(
+    "buffer",
+    __module__ = "_cffi_backend",
+    __len__ = interp2app(RWBuffer.descr_len),
+    __getitem__ = interp2app(RWBuffer.descr_getitem),
+    __setitem__ = interp2app(RWBuffer.descr_setitem),
+    __buffer__ = interp2app(RWBuffer.descr__buffer__),
+    )
+LLBuffer.typedef.acceptable_as_base_class = False
+
 
 @unwrap_spec(cdata=cdataobj.W_CData, size=int)
 def buffer(space, cdata, size=-1):

pypy/module/_cffi_backend/test/_backend_test_c.py

     type_or_class = "type"
     mandatory_b_prefix = ''
     mandatory_u_prefix = 'u'
-    readbuf = str
-    bufchar = lambda x: x
     bytechr = chr
     class U(object):
         def __add__(self, other):
     unichr = chr
     mandatory_b_prefix = 'b'
     mandatory_u_prefix = ''
-    readbuf = lambda buf: buf.tobytes()
-    if sys.version_info < (3, 3):
-        bufchar = lambda x: bytes([ord(x)])
-    else:
-        bufchar = ord
     bytechr = lambda n: bytes([n])
     u = ""
 
     assert (p < s) ^ (p > s)
 
 def test_buffer():
+    import __builtin__
     BShort = new_primitive_type("short")
     s = newp(new_pointer_type(BShort), 100)
     assert sizeof(s) == size_of_ptr()
     assert sizeof(BShort) == 2
-    assert len(readbuf(buffer(s))) == 2
+    assert len(buffer(s)) == 2
     #
     BChar = new_primitive_type("char")
     BCharArray = new_array_type(new_pointer_type(BChar), None)
     c = newp(BCharArray, b"hi there")
+    #
     buf = buffer(c)
-    assert readbuf(buf) == b"hi there\x00"
+    assert str(buf).startswith('<_cffi_backend.buffer object at 0x')
+    # --mb_length--
     assert len(buf) == len(b"hi there\x00")
-    assert buf[0] == bufchar('h')
-    assert buf[2] == bufchar(' ')
-    assert list(buf) == list(map(bufchar, "hi there\x00"))
-    buf[2] = bufchar('-')
-    assert c[2] == b'-'
-    assert readbuf(buf) == b"hi-there\x00"
-    c[2] = b'!'
-    assert buf[2] == bufchar('!')
-    assert readbuf(buf) == b"hi!there\x00"
-    c[2] = b'-'
-    buf[:2] = b'HI'
-    assert string(c) == b'HI-there'
-    if sys.version_info < (3,) or sys.version_info >= (3, 3):
-        assert buf[:4:2] == b'H-'
-        if '__pypy__' not in sys.builtin_module_names:
-            # XXX pypy doesn't support the following assignment so far
-            buf[:4:2] = b'XY'
-            assert string(c) == b'XIYthere'
+    # --mb_item--
+    for i in range(-12, 12):
+        try:
+            expected = b"hi there\x00"[i]
+        except IndexError:
+            py.test.raises(IndexError, "buf[i]")
+        else:
+            assert buf[i] == expected
+    # --mb_slice--
+    assert buf[:] == b"hi there\x00"
+    for i in range(-12, 12):
+        assert buf[i:] == b"hi there\x00"[i:]
+        assert buf[:i] == b"hi there\x00"[:i]
+        for j in range(-12, 12):
+            assert buf[i:j] == b"hi there\x00"[i:j]
+    # --misc--
+    assert list(buf) == list(b"hi there\x00")
+    # --mb_as_buffer--
+    py.test.raises(TypeError, __builtin__.buffer, c)
+    bf1 = __builtin__.buffer(buf)
+    assert len(bf1) == len(buf) and bf1[3] == "t"
+    if hasattr(__builtin__, 'memoryview'):      # Python >= 2.7
+        py.test.raises(TypeError, memoryview, c)
+        mv1 = memoryview(buf)
+        assert len(mv1) == len(buf) and mv1[3] == "t"
+    # --mb_ass_item--
+    expected = list(b"hi there\x00")
+    for i in range(-12, 12):
+        try:
+            expected[i] = chr(i & 0xff)
+        except IndexError:
+            py.test.raises(IndexError, "buf[i] = chr(i & 0xff)")
+        else:
+            buf[i] = chr(i & 0xff)
+        assert list(buf) == expected
+    # --mb_ass_slice--
+    buf[:] = b"hi there\x00"
+    assert list(buf) == list(c) == list(b"hi there\x00")
+    py.test.raises(ValueError, 'buf[:] = b"shorter"')
+    py.test.raises(ValueError, 'buf[:] = b"this is much too long!"')
+    buf[4:2] = b""   # no effect, but should work
+    assert buf[:] == b"hi there\x00"
+    expected = list(b"hi there\x00")
+    x = 0
+    for i in range(-12, 12):
+        for j in range(-12, 12):
+            start = i if i >= 0 else i + len(buf)
+            stop  = j if j >= 0 else j + len(buf)
+            start = max(0, min(len(buf), start))
+            stop  = max(0, min(len(buf), stop))
+            sample = chr(x & 0xff) * (stop - start)
+            x += 1
+            buf[i:j] = sample
+            expected[i:j] = sample
+            assert list(buf) == expected
 
 def test_getcname():
     BUChar = new_primitive_type("unsigned char")

pypy/module/_multiprocessing/test/test_connection.py

 
 class AppTestBufferTooShort:
     def setup_class(cls):
-        space = gettestobjspace(usemodules=('_multiprocessing', 'thread', 'signal'))
+        space = gettestobjspace(usemodules=('_multiprocessing', 'thread',
+                                            'signal', 'itertools'))
         cls.space = space
 
         if option.runappdirect:

pypy/module/_multiprocessing/test/test_memory.py

 class AppTestMemory:
     def setup_class(cls):
         space = gettestobjspace(
-            usemodules=('_multiprocessing', 'mmap', '_rawffi', '_ffi'))
+            usemodules=('_multiprocessing', 'mmap', '_rawffi', '_ffi',
+                        'itertools'))
         cls.space = space
 
     def test_address_of(self):

pypy/module/bz2/interp_bz2.py

             buffering = 1024   # minimum amount of compressed data read at once
         self.buffering = buffering
 
-    def close(self):
-        self.stream.close()
+    def close1(self, closefileno):
+        self.stream.close1(closefileno)
 
     def tell(self):
         return self.readlength
         self.compressor = W_BZ2Compressor(space, compresslevel)
         self.writtenlength = 0
 
-    def close(self):
+    def close1(self, closefileno):
         self.stream.write(self.space.str_w(self.compressor.flush()))
-        self.stream.close()
+        self.stream.close1(closefileno)
 
     def write(self, data):
         self.stream.write(self.space.str_w(self.compressor.compress(data)))

pypy/module/cpyext/dictobject.py

 @specialize.memo()
 def make_frozendict(space):
     return space.appexec([], '''():
-    import collections
-    class FrozenDict(collections.Mapping):
+    import _abcoll
+    class FrozenDict(_abcoll.Mapping):
         def __init__(self, *args, **kwargs):
             self._d = dict(*args, **kwargs)
         def __iter__(self):

pypy/module/cpyext/test/test_import.py

 
 class TestImport(BaseApiTest):
     def test_import(self, space, api):
-        pdb = api.PyImport_Import(space.wrap("pdb"))
-        assert pdb
-        assert space.getattr(pdb, space.wrap("pm"))
+        stat = api.PyImport_Import(space.wrap("stat"))
+        assert stat
+        assert space.getattr(stat, space.wrap("S_IMODE"))
 
     def test_addmodule(self, space, api):
         with rffi.scoped_str2charp("sys") as modname:
         assert space.is_true(space.contains(w_dict, space.wrap(testmod)))
 
     def test_reload(self, space, api):
-        pdb = api.PyImport_Import(space.wrap("pdb"))
-        space.delattr(pdb, space.wrap("set_trace"))
-        pdb = api.PyImport_ReloadModule(pdb)
-        assert space.getattr(pdb, space.wrap("set_trace"))
+        stat = api.PyImport_Import(space.wrap("stat"))
+        space.delattr(stat, space.wrap("S_IMODE"))
+        stat = api.PyImport_ReloadModule(stat)
+        assert space.getattr(stat, space.wrap("S_IMODE"))
 
 class AppTestImportLogic(AppTestCpythonExtensionBase):
     def test_import_logic(self):

pypy/module/imp/test/test_app.py

 
 class AppTestImpModule:
     def setup_class(cls):
+        from pypy.conftest import gettestobjspace
+        cls.space = gettestobjspace(usemodules=('imp', 'itertools'))
         cls.w_imp = cls.space.getbuiltinmodule('imp')
         cls.w_file_module = cls.space.wrap(__file__)
 

pypy/module/imp/test/test_import.py

                     test_reload = "def test():\n    raise ValueError\n",
                     infinite_reload = "import infinite_reload; reload(infinite_reload)",
                     del_sys_module = "import sys\ndel sys.modules['del_sys_module']\n",
-                    itertools = "hello_world = 42\n",
+                    _md5 = "hello_world = 42\n",
                     gc = "should_never_be_seen = 42\n",
                     )
     root.ensure("notapackage", dir=1)    # empty, no __init__.py
 class AppTestImport:
 
     def setup_class(cls): # interpreter-level
-        cls.space = gettestobjspace(usemodules=['itertools'])
+        cls.space = gettestobjspace(usemodules=['_md5'])
         cls.w_runappdirect = cls.space.wrap(conftest.option.runappdirect)
         cls.saved_modules = _setup(cls.space)
         #XXX Compile class
 
     def test_shadow_extension_1(self):
         if self.runappdirect: skip("hard to test: module is already imported")
-        # 'import itertools' is supposed to find itertools.py if there is
+        # 'import _md5' is supposed to find _md5.py if there is
         # one in sys.path.
         import sys
-        assert 'itertools' not in sys.modules
-        import itertools
-        assert hasattr(itertools, 'hello_world')
-        assert not hasattr(itertools, 'count')
-        assert '(built-in)' not in repr(itertools)
-        del sys.modules['itertools']
+        assert '_md5' not in sys.modules
+        import _md5
+        assert hasattr(_md5, 'hello_world')
+        assert not hasattr(_md5, 'count')
+        assert '(built-in)' not in repr(_md5)
+        del sys.modules['_md5']
 
     def test_shadow_extension_2(self):
         if self.runappdirect: skip("hard to test: module is already imported")
-        # 'import itertools' is supposed to find the built-in module even
+        # 'import _md5' is supposed to find the built-in module even
         # if there is also one in sys.path as long as it is *after* the
         # special entry '.../lib_pypy/__extensions__'.  (Note that for now
-        # there is one in lib_pypy/itertools.py, which should not be seen
+        # there is one in lib_pypy/_md5.py, which should not be seen
         # either; hence the (built-in) test below.)
         import sys
-        assert 'itertools' not in sys.modules
+        assert '_md5' not in sys.modules
         sys.path.append(sys.path.pop(0))
         try:
-            import itertools
-            assert not hasattr(itertools, 'hello_world')
-            assert hasattr(itertools, 'izip')
-            assert '(built-in)' in repr(itertools)
+            import _md5
+            assert not hasattr(_md5, 'hello_world')
+            assert hasattr(_md5, 'digest_size')
+            assert '(built-in)' in repr(_md5)
         finally:
             sys.path.insert(0, sys.path.pop())
-        del sys.modules['itertools']
+        del sys.modules['_md5']
 
     def test_invalid_pathname(self):
         import imp
 class AppTestImportHooks(object):
 
     def setup_class(cls):
-        space = cls.space = gettestobjspace(usemodules=('struct',))
+        space = cls.space = gettestobjspace(usemodules=('struct', 'itertools'))
         mydir = os.path.dirname(__file__)
         cls.w_hooktest = space.wrap(os.path.join(mydir, 'hooktest'))
         space.appexec([space.wrap(mydir)], """

pypy/module/math/test/test_math.py

 
 class AppTestMath:
     def setup_class(cls):
-        cls.space = gettestobjspace(usemodules=['math', 'struct'])
+        cls.space = gettestobjspace(usemodules=['math', 'struct', 'itertools'])
         cls.w_cases = cls.space.wrap(test_direct.MathTests.TESTCASES)
         cls.w_consistent_host = cls.space.wrap(test_direct.consistent_host)
 

pypy/module/micronumpy/arrayimpl/concrete.py

     def __init__(self, array):
         self.array = array
         self.offset = array.start
-        self.skip = array.strides[0]
+        self.skip = array.get_strides()[0]
         self.dtype = array.dtype
         self.index = 0
         self.size = array.get_shape()[0]
 class AxisIterator(base.BaseArrayIterator):
     def __init__(self, array, shape, dim):
         self.shape = shape
-        strides = array.strides
-        backstrides = array.backstrides
+        strides = array.get_strides()
+        backstrides = array.get_backstrides()
         if len(shape) == len(strides):
             # keepdims = True
             self.strides = strides[:dim] + [0] + strides[dim + 1:]
 class BaseConcreteArray(base.BaseArrayImplementation):
     start = 0
     parent = None
+
+    # JIT hints that length of all those arrays is a constant
     
     def get_shape(self):
         shape = self.shape
         jit.hint(len(shape), promote=True)
         return shape
 
+    def get_strides(self):
+        strides = self.strides
+        jit.hint(len(strides), promote=True)
+        return strides
+
+    def get_backstrides(self):
+        backstrides = self.backstrides
+        jit.hint(len(backstrides), promote=True)
+        return backstrides
+
     def getitem(self, index):
         return self.dtype.getitem(self, index)
 
         new_strides = None
         if self.size > 0:
             new_strides = calc_new_strides(new_shape, self.get_shape(),
-                                           self.strides, self.order)
+                                           self.get_strides(), self.order)
         if new_strides:
             # We can create a view, strides somehow match up.
             ndims = len(new_shape)
     @jit.unroll_safe
     def _lookup_by_index(self, space, view_w):
         item = self.start
+        strides = self.get_strides()
         for i, w_index in enumerate(view_w):
             if space.isinstance_w(w_index, space.w_slice):
                 raise IndexError
                 raise operationerrfmt(space.w_IndexError,
                       "index (%d) out of range (0<=index<%d", i, self.get_shape()[i],
                 )
-            item += idx * self.strides[i]
+            item += idx * strides[i]
         return item
 
     @jit.unroll_safe
     def _lookup_by_unwrapped_index(self, space, lst):
         item = self.start
         shape = self.get_shape()
+        strides = self.get_strides()
         assert len(lst) == len(shape)
         for i, idx in enumerate(lst):
             if idx < 0:
                 raise operationerrfmt(space.w_IndexError,
                       "index (%d) out of range (0<=index<%d", i, shape[i],
                 )
-            item += idx * self.strides[i]
+            item += idx * strides[i]
         return item
 
     def getitem_index(self, space, index):
         backstrides = []
         shape = []
         for i in range(len(self.get_shape()) - 1, -1, -1):
-            strides.append(self.strides[i])
-            backstrides.append(self.backstrides[i])
+            strides.append(self.get_strides()[i])
+            backstrides.append(self.get_backstrides()[i])
             shape.append(self.get_shape()[i])
         return SliceArray(self.start, strides,
                           backstrides, shape, self)
         return AxisIterator(self, shape, dim)
 
     def create_dot_iter(self, shape, skip):
-        r = calculate_dot_strides(self.strides, self.backstrides,
+        r = calculate_dot_strides(self.get_strides(), self.get_backstrides(),
                                   shape, skip)
         return MultiDimViewIterator(self, self.start, r[0], r[1], shape)
 
     def swapaxes(self, axis1, axis2):
         shape = self.get_shape()[:]
-        strides = self.strides[:]
-        backstrides = self.backstrides[:]
+        strides = self.get_strides()[:]
+        backstrides = self.get_backstrides()[:]
         shape[axis1], shape[axis2] = shape[axis2], shape[axis1]   
         strides[axis1], strides[axis2] = strides[axis2], strides[axis1]
         backstrides[axis1], backstrides[axis2] = backstrides[axis2], backstrides[axis1] 
     def create_iter(self, shape=None):
         if shape is None or shape == self.get_shape():
             return ConcreteArrayIterator(self)
-        r = calculate_broadcast_strides(self.strides, self.backstrides,
+        r = calculate_broadcast_strides(self.get_strides(),
+                                        self.get_backstrides(),
                                         self.get_shape(), shape)
         return MultiDimViewIterator(self, 0, r[0], r[1], shape)
 
 
     def create_iter(self, shape=None):
         if shape is not None and shape != self.get_shape():
-            r = calculate_broadcast_strides(self.strides, self.backstrides,
+            r = calculate_broadcast_strides(self.get_strides(),
+                                            self.get_backstrides(),
                                             self.get_shape(), shape)
             return MultiDimViewIterator(self.parent,
                                         self.start, r[0], r[1], shape)
         if len(self.get_shape()) == 1:
             return OneDimViewIterator(self)
-        return MultiDimViewIterator(self.parent, self.start, self.strides,
-                                    self.backstrides, self.get_shape())
+        return MultiDimViewIterator(self.parent, self.start,
+                                    self.get_strides(),
+                                    self.get_backstrides(), self.get_shape())
 
     def set_shape(self, space, new_shape):
         if len(self.get_shape()) < 2 or self.size == 0:
             strides = []
             backstrides = []
             dtype = self.dtype
-            s = self.strides[0] // dtype.get_size()
+            s = self.get_strides()[0] // dtype.get_size()
             if self.order == 'C':
                 new_shape.reverse()
             for sh in new_shape:
                 new_shape.reverse()
             return SliceArray(self.start, strides, backstrides, new_shape,
                               self)
-        new_strides = calc_new_strides(new_shape, self.get_shape(), self.strides,
+        new_strides = calc_new_strides(new_shape, self.get_shape(),
+                                       self.get_strides(),
                                        self.order)
         if new_strides is None:
             raise OperationError(space.w_AttributeError, space.wrap(

pypy/module/micronumpy/interp_boxes.py

             arr.storage[i] = arg[i]
         return W_StringBox(arr, 0, arr.dtype)
 
-    # Running entire test suite needs this function to succeed,
-    # running single test_stringarray succeeds without it.
-    # With convert_to() test_ztranslation fails since 
-    # W_CharacterBox is not a W_GenericBox.
-    # Why is it needed for multiple tests?
-    #def convert_to(self, dtype):
-    #    xxx
-
 class W_UnicodeBox(W_CharacterBox):
     def descr__new__unicode_box(space, w_subtype, w_arg):
         from pypy.module.micronumpy.interp_dtype import new_unicode_dtype

pypy/module/micronumpy/iter.py

     def apply(self, arr):
         ofs, subdtype = arr.dtype.fields[self.name]
         # strides backstrides are identical, ofs only changes start
-        return W_NDimArray.new_slice(arr.start + ofs, arr.strides,
-                                     arr.backstrides,
+        return W_NDimArray.new_slice(arr.start + ofs, arr.get_strides(),
+                                     arr.get_backstrides(),
                                      arr.shape, arr, subdtype)
 
 class Chunks(BaseChunk):
 
     def apply(self, arr):
         shape = self.extend_shape(arr.shape)
-        r = calculate_slice_strides(arr.shape, arr.start, arr.strides,
-                                    arr.backstrides, self.l)
+        r = calculate_slice_strides(arr.shape, arr.start, arr.get_strides(),
+                                    arr.get_backstrides(), self.l)
         _, start, strides, backstrides = r
         return W_NDimArray.new_slice(start, strides[:], backstrides[:],
                                      shape[:], arr)

pypy/module/micronumpy/strides.py

             i //= shape[s]
     return coords, step, lngth
 
+@jit.unroll_safe
 def shape_agreement(space, shape1, w_arr2, broadcast_down=True):
     if w_arr2 is None:
         return shape1
         )
     return ret
 
+@jit.unroll_safe
 def _shape_agreement(shape1, shape2):
     """ Checks agreement about two shapes with respect to broadcasting. Returns
     the resulting shape.

pypy/module/micronumpy/support.py

         i *= x
     return i
 
+@jit.unroll_safe
 def calc_strides(shape, dtype, order):
     strides = []
     backstrides = []

pypy/module/test_lib_pypy/test_itertools.py

 
 class AppTestItertools:
     def setup_class(cls):
-        cls.space = gettestobjspace()
+        cls.space = gettestobjspace(usemodules=['itertools'])
         cls.w_itertools = cls.space.appexec([], "(): import itertools; return itertools")
 
     def test_chain(self):

pypy/module/test_lib_pypy/test_pwd.py

     def setup_class(cls):
         if sys.platform == 'win32':
             py.test.skip("Unix only")
-        cls.space = gettestobjspace(usemodules=('_ffi', '_rawffi'))
+        cls.space = gettestobjspace(usemodules=('_ffi', '_rawffi',
+                                                'itertools'))
         cls.space.appexec((), "(): import pwd")
 
     def test_getpwuid(self):

pypy/module/zipimport/test/test_undocumented.py

 
 class AppTestZipImport:
     def setup_class(cls):
-        space = gettestobjspace(usemodules=['zipimport', 'rctime', 'struct'])
+        space = gettestobjspace(usemodules=['zipimport', 'rctime', 'struct',
+                                            'itertools'])
         cls.space = space
         cls.w_created_paths = space.wrap(created_paths)
     

pypy/module/zipimport/test/test_zipimport.py

             return __file__
         """).compile()
 
+        usemodules = ['zipimport', 'rctime', 'struct', 'itertools']
         if cls.compression == ZIP_DEFLATED:
-            space = gettestobjspace(usemodules=['zipimport', 'zlib', 'rctime', 'struct'])
-        else:
-            space = gettestobjspace(usemodules=['zipimport', 'rctime', 'struct'])
-            
+            usemodules.append('zlib')
+        space = gettestobjspace(usemodules=usemodules)
         cls.space = space
         tmpdir = udir.ensure('zipimport_%s' % cls.__name__, dir=1)
         now = time.time()

pypy/objspace/std/test/test_iterobject.py

         raises(TypeError, len, iter(iterable))
         
     def test_no_len_on_deque_iter(self):
-        from collections import deque
+        from _collections import deque
         iterable = deque([1,2,3,4])
         raises(TypeError, len, iter(iterable))
 
         it = reversed([5,6,7])
         raises(TypeError, len, it)
 
-    def test_no_len_on_UserList_iter(self):
+    def test_no_len_on_UserList_iter_reversed(self):
+        import sys, _abcoll
+        sys.modules['collections'] = _abcoll
         from UserList import UserList
         iterable = UserList([1,2,3,4])
         raises(TypeError, len, iter(iterable))
-
-    def test_no_len_on_UserList_reversed(self):
-        from UserList import UserList
-        iterable = UserList([1,2,3,4])
         raises(TypeError, len, reversed(iterable))
+        del sys.modules['collections']
 
     def test_no_len_on_set_iter(self):
         iterable = set([1,2,3,4])

pypy/objspace/std/test/test_methodcache.py

             setattr(a, "a%s" % i, i)
         cache_counter = __pypy__.method_cache_counter("x")
         assert cache_counter[0] == 0 # 0 hits, because all the attributes are new
-
-    def test_get_module_from_namedtuple(self):
-        # this used to crash
-        from collections import namedtuple
-        assert namedtuple("a", "b").__module__

pypy/objspace/std/test/test_typeobject.py

         A.__dict__['x'] = 5
         assert A.x == 5
 
+
+class AppTestWithMethodCacheCounter:
+    def setup_class(cls):
+        cls.space = gettestobjspace(
+            **{"objspace.std.withmethodcachecounter": True})
+
+    def test_module_from_handbuilt_type(self):
+        d = {'tuple': tuple, '__name__': 'foomod'}
+        exec """class foo(tuple): pass""" in d
+        t = d['foo']
+        t.__module__ = 'barmod'
+        # this last line used to crash; see ab926f846f39
+        assert t.__module__
+
+
 class AppTestMutableBuiltintypes:
 
     def setup_class(cls):

pypy/rlib/rbigint.py

         self.size = size or len(digits)
         self.sign = sign
 
+    # __eq__ and __ne__ method exist for testingl only, they are not RPython!
+    def __eq__(self, other):
+        # NOT_RPYTHON
+        if not isinstance(other, rbigint):
+            return NotImplemented
+        return self.eq(other)
+
+    def __ne__(self, other):
+        # NOT_RPYTHON
+        return not (self == other)
+
     def digit(self, x):
         """Return the x'th digit, as an int."""
         return self._digits[x]

pypy/rlib/test/test_rbigint.py

 from __future__ import division
+
+import operator
+import sys
+from random import random, randint, sample
+
 import py
-import operator, sys, array
-from random import random, randint, sample
-from pypy.rlib.rbigint import rbigint, SHIFT, MASK, KARATSUBA_CUTOFF
-from pypy.rlib.rbigint import _store_digit, _mask_digit
-from pypy.rlib.rfloat import NAN
+
 from pypy.rlib import rbigint as lobj
 from pypy.rlib.rarithmetic import r_uint, r_longlong, r_ulonglong, intmask
+from pypy.rlib.rbigint import (rbigint, SHIFT, MASK, KARATSUBA_CUTOFF,
+    _store_digit, _mask_digit)
+from pypy.rlib.rfloat import NAN
 from pypy.rpython.test.test_llinterp import interpret
 
+
 class TestRLong(object):
     def test_simple(self):
         for op1 in [-2, -1, 0, 1, 2, 50]:
         rl = rbigint.fromint(sys.maxint).add(rbigint.fromint(42))
         assert rl.touint() == result
 
+    def test_eq_ne_operators(self):
+        a1 = rbigint.fromint(12)
+        a2 = rbigint.fromint(12)
+        a3 = rbigint.fromint(123)
+
+        assert a1 == a2
+        assert a1 != a3
+        assert not (a1 != a2)
+        assert not (a1 == a3)
+
+
 def gen_signs(l):
     for s in l:
         if s == 0: