[pypy-commit] pypy py3k: Fix most tests in __builtin__ module,

amauryfa noreply at buildbot.pypy.org
Mon Nov 7 21:22:35 CET 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3k
Changeset: r48875:22fa14064102
Date: 2011-11-07 21:02 +0100
http://bitbucket.org/pypy/pypy/changeset/22fa14064102/

Log:	Fix most tests in __builtin__ module, including a nasty error in
	type dictonaries: After class C: x=42 C.x correctly succeeds,
	but C.__dict__['x'] was not found!

diff --git a/pypy/module/__builtin__/interp_memoryview.py b/pypy/module/__builtin__/interp_memoryview.py
--- a/pypy/module/__builtin__/interp_memoryview.py
+++ b/pypy/module/__builtin__/interp_memoryview.py
@@ -72,7 +72,7 @@
         return space.wrap(self.buf)
 
     def descr_tobytes(self, space):
-        return space.wrap(self.as_str())
+        return space.wrapbytes(self.as_str())
 
     def descr_tolist(self, space):
         buf = self.buf
diff --git a/pypy/module/__builtin__/operation.py b/pypy/module/__builtin__/operation.py
--- a/pypy/module/__builtin__/operation.py
+++ b/pypy/module/__builtin__/operation.py
@@ -215,7 +215,7 @@
 table of interned strings whose purpose is to speed up dictionary lookups.
 Return the string itself or the previously interned string object with the
 same value."""
-    if space.is_w(space.type(w_str), space.w_str):
+    if space.is_w(space.type(w_str), space.w_unicode):
         return space.new_interned_w_str(w_str)
     raise OperationError(space.w_TypeError, space.wrap("intern() argument must be string."))
 
diff --git a/pypy/module/__builtin__/test/test_abstractinst.py b/pypy/module/__builtin__/test/test_abstractinst.py
--- a/pypy/module/__builtin__/test/test_abstractinst.py
+++ b/pypy/module/__builtin__/test/test_abstractinst.py
@@ -195,10 +195,12 @@
                 """Implement issubclass(sub, cls)."""
                 candidates = cls.__dict__.get("__subclass__", set()) | set([cls])
                 return any(c in candidates for c in sub.mro())
-        class Integer:
 
-            __metaclass__ = ABC
+        # Equivalent to::
+        #     class Integer(metaclass=ABC):
+        #         __subclass__ = set([int])
+        # But with a syntax compatible with 2.x
+        Integer = ABC('Integer', (), dict(__subclass__=set([int])))
 
-            __subclass__ = set([int])
         assert issubclass(int, Integer)
         assert issubclass(int, (Integer,))
diff --git a/pypy/module/__builtin__/test/test_buffer.py b/pypy/module/__builtin__/test/test_buffer.py
--- a/pypy/module/__builtin__/test/test_buffer.py
+++ b/pypy/module/__builtin__/test/test_buffer.py
@@ -12,21 +12,21 @@
         if sys.maxunicode == 65535: # UCS2 build
             assert len(b) == 4
             if sys.byteorder == "big":
-                assert b[0:4] == "\x00a\x00b"
+                assert b[0:4] == b"\x00a\x00b"
             else:
-                assert b[0:4] == "a\x00b\x00"
+                assert b[0:4] == b"a\x00b\x00"
         else: # UCS4 build
             assert len(b) == 8
             if sys.byteorder == "big":
-                assert b[0:8] == "\x00\x00\x00a\x00\x00\x00b"
+                assert b[0:8] == b"\x00\x00\x00a\x00\x00\x00b"
             else:
-                assert b[0:8] == "a\x00\x00\x00b\x00\x00\x00"
+                assert b[0:8] == b"a\x00\x00\x00b\x00\x00\x00"
 
     def test_array_buffer(self):
         import array
         b = buffer(array.array("B", [1, 2, 3]))
         assert len(b) == 3
-        assert b[0:3] == "\x01\x02\x03"
+        assert b[0:3] == b"\x01\x02\x03"
 
     def test_nonzero(self):
         assert buffer('\x00')
@@ -36,68 +36,68 @@
         assert not buffer(array.array("B", []))
 
     def test_str(self):
-        assert str(buffer('hello')) == 'hello'
+        assert str(buffer(b'hello')) == 'hello'
 
     def test_repr(self):
         # from 2.5.2 lib tests
-        assert repr(buffer('hello')).startswith('<read-only buffer for 0x')
+        assert repr(buffer(b'hello')).startswith('<read-only buffer for 0x')
 
     def test_add(self):
-        assert buffer('abc') + 'def' == 'abcdef'
+        assert buffer(b'abc') + b'def' == b'abcdef'
         import array
-        assert buffer('abc') + array.array('c', 'def') == 'abcdef'
+        assert buffer(b'abc') + array.array('b', b'def') == b'abcdef'
 
     def test_cmp(self):
-        assert buffer('ab') != 'ab'
-        assert not ('ab' == buffer('ab'))
-        assert buffer('ab') == buffer('ab')
-        assert not (buffer('ab') != buffer('ab'))
-        assert not (buffer('ab') <  buffer('ab'))
-        assert buffer('ab') <= buffer('ab')
-        assert not (buffer('ab') >  buffer('ab'))
-        assert buffer('ab') >= buffer('ab')
-        assert buffer('ab') != buffer('abc')
-        assert buffer('ab') <  buffer('abc')
-        assert buffer('ab') <= buffer('ab')
-        assert buffer('ab') >  buffer('aa')
-        assert buffer('ab') >= buffer('ab')
+        assert buffer(b'ab') != b'ab'
+        assert not (b'ab' == buffer(b'ab'))
+        assert buffer(b'ab') == buffer(b'ab')
+        assert not (buffer(b'ab') != buffer(b'ab'))
+        assert not (buffer(b'ab') <  buffer(b'ab'))
+        assert buffer(b'ab') <= buffer(b'ab')
+        assert not (buffer(b'ab') >  buffer(b'ab'))
+        assert buffer(b'ab') >= buffer(b'ab')
+        assert buffer(b'ab') != buffer(b'abc')
+        assert buffer(b'ab') <  buffer(b'abc')
+        assert buffer(b'ab') <= buffer(b'ab')
+        assert buffer(b'ab') >  buffer(b'aa')
+        assert buffer(b'ab') >= buffer(b'ab')
 
     def test_hash(self):
-        assert hash(buffer('hello')) == hash('hello')
+        assert hash(buffer(b'hello')) == hash(b'hello')
 
     def test_mul(self):
-        assert buffer('ab') * 5 == 'ababababab'
-        assert buffer('ab') * (-2) == ''
-        assert 5 * buffer('ab') == 'ababababab'
-        assert (-2) * buffer('ab') == ''
+        assert buffer(b'ab') * 5 == b'ababababab'
+        assert buffer(b'ab') * (-2) == b''
+        assert 5 * buffer(b'ab') == b'ababababab'
+        assert (-2) * buffer(b'ab') == b''
 
     def test_offset_size(self):
-        b = buffer('hello world', 6)
+        b = buffer(b'hello world', 6)
         assert len(b) == 5
-        assert b[0] == 'w'
-        assert b[:] == 'world'
+        assert b[0] == b'w'
+        assert b[:] == b'world'
         raises(IndexError, 'b[5]')
         b = buffer(b, 2)
         assert len(b) == 3
-        assert b[0] == 'r'
-        assert b[:] == 'rld'
+        assert b[0] == b'r'
+        assert b[:] == b'rld'
         raises(IndexError, 'b[3]')
-        b = buffer('hello world', 1, 8)
+        b = buffer(b'hello world', 1, 8)
         assert len(b) == 8
-        assert b[0] == 'e'
-        assert b[:] == 'ello wor'
+        assert b[0] == b'e'
+        assert b[:] == b'ello wor'
         raises(IndexError, 'b[8]')
         b = buffer(b, 2, 3)
         assert len(b) == 3
-        assert b[2] == ' '
-        assert b[:] == 'lo '
+        assert b[2] == b' '
+        assert b[:] == b'lo '
         raises(IndexError, 'b[3]')
         b = buffer('hello world', 55)
         assert len(b) == 0
-        assert b[:] == ''
-        b = buffer('hello world', 6, 999)
+        assert b[:] == b''
+        b = buffer(b'hello world', 6, 999)
         assert len(b) == 5
-        assert b[:] == 'world'
+        assert b[:] == b'world'
 
         raises(ValueError, buffer, "abc", -1)
         raises(ValueError, buffer, "abc", 0, -2)
@@ -105,17 +105,17 @@
     def test_rw_offset_size(self):
         import array
 
-        a = array.array("c", 'hello world')
+        a = array.array("b", b'hello world')
         b = buffer(a, 6)
         assert len(b) == 5
-        assert b[0] == 'w'
-        assert b[:] == 'world'
+        assert b[0] == b'w'
+        assert b[:] == b'world'
         raises(IndexError, 'b[5]')
-        b[0] = 'W'
-        assert str(b) == 'World'
-        assert a.tostring() == 'hello World'
-        b[:] = '12345'
-        assert a.tostring() == 'hello 12345'
+        b[0] = b'W'
+        assert str(b) == b'World'
+        assert a.tostring() == b'hello World'
+        b[:] = b'12345'
+        assert a.tostring() == b'hello 12345'
         raises(IndexError, 'b[5] = "."')
 
         b = buffer(b, 2)
@@ -161,7 +161,7 @@
 
     def test_slice(self):
         # Test extended slicing by comparing with list slicing.
-        s = "".join(chr(c) for c in list(range(255, -1, -1)))
+        s = bytes(c for c in list(range(255, -1, -1)))
         b = buffer(s)
         indices = (0, None, 1, 3, 19, 300, -1, -2, -31, -300)
         for start in indices:
@@ -172,8 +172,8 @@
 
 class AppTestMemoryView:
     def test_basic(self):
-        v = memoryview("abc")
-        assert v.tobytes() == "abc"
+        v = memoryview(b"abc")
+        assert v.tobytes() == b"abc"
         assert len(v) == 3
         assert list(v) == ['a', 'b', 'c']
         assert v.tolist() == [97, 98, 99]
@@ -186,17 +186,17 @@
         assert len(w) == 2
 
     def test_rw(self):
-        data = bytearray('abcefg')
+        data = bytearray(b'abcefg')
         v = memoryview(data)
         assert v.readonly is False
-        v[0] = 'z'
+        v[0] = b'z'
         assert data == bytearray(eval("b'zbcefg'"))
-        v[1:4] = '123'
+        v[1:4] = b'123'
         assert data == bytearray(eval("b'z123fg'"))
         raises((ValueError, TypeError), "v[2] = 'spam'")
 
     def test_memoryview_attrs(self):
-        v = memoryview("a"*100)
+        v = memoryview(b"a"*100)
         assert v.format == "B"
         assert v.itemsize == 1
         assert v.shape == (100,)
@@ -204,13 +204,13 @@
         assert v.strides == (1,)
 
     def test_suboffsets(self):
-        v = memoryview("a"*100)
+        v = memoryview(b"a"*100)
         assert v.suboffsets == None
-        v = memoryview(buffer("a"*100, 2))
+        v = memoryview(buffer(b"a"*100, 2))
         assert v.shape == (98,)
         assert v.suboffsets == None
 
     def test_compare(self):
-        assert memoryview("abc") == "abc"
-        assert memoryview("abc") == bytearray("abc")
-        assert memoryview("abc") != 3
+        assert memoryview(b"abc") == b"abc"
+        assert memoryview(b"abc") == bytearray(b"abc")
+        assert memoryview(b"abc") != 3
diff --git a/pypy/module/__builtin__/test/test_builtin.py b/pypy/module/__builtin__/test/test_builtin.py
--- a/pypy/module/__builtin__/test/test_builtin.py
+++ b/pypy/module/__builtin__/test/test_builtin.py
@@ -27,8 +27,8 @@
             cls.w_safe_runtimerror = cls.space.wrap(sys.version_info < (2, 6))
 
     def test_bytes_alias(self):
-        assert bytes is str
-        assert isinstance(eval("b'hi'"), str)
+        assert bytes is not str
+        assert isinstance(eval("b'hi'"), bytes)
 
     def test_import(self):
         m = __import__('pprint')
@@ -73,7 +73,7 @@
 
     def test_globals(self):
         d = {"foo":"bar"}
-        exec "def f(): return globals()" in d
+        exec("def f(): return globals()", d)
         d2 = d["f"]()
         assert d2 is d
 
@@ -157,7 +157,7 @@
         assert format(10, "o") == "12"
         assert format(10, "#o") == "0o12"
         assert format("hi") == "hi"
-        assert isinstance(format(4, u""), unicode)
+        assert isinstance(format(4, u""), str)
 
     def test_vars(self):
         def f():
@@ -208,10 +208,10 @@
     def test_iter_sequence(self):
         raises(TypeError,iter,3)
         x = iter(['a','b','c'])
-        assert x.next() =='a'
-        assert x.next() =='b'
-        assert x.next() =='c'
-        raises(StopIteration,x.next)
+        assert next(x) =='a'
+        assert next(x) =='b'
+        assert next(x) =='c'
+        raises(StopIteration, next, x)
 
     def test_iter___iter__(self):
         # This test assumes that dict.keys() method returns keys in
@@ -235,16 +235,16 @@
         #self.assertRaises(TypeError,iter,[],5)
         #self.assertRaises(TypeError,iter,{},5)
         x = iter(count(),3)
-        assert x.next() ==1
-        assert x.next() ==2
-        raises(StopIteration,x.next)
+        assert next(x) ==1
+        assert next(x) ==2
+        raises(StopIteration, next, x)
 
     def test_enumerate(self):
         seq = range(2,4)
         enum = enumerate(seq)
-        assert enum.next() == (0, 2)
-        assert enum.next() == (1, 3)
-        raises(StopIteration, enum.next)
+        assert next(enum) == (0, 2)
+        assert next(enum) == (1, 3)
+        raises(StopIteration, next, enum)
         raises(TypeError, enumerate, 1)
         raises(TypeError, enumerate, None)
         enum = enumerate(range(5), 2)
@@ -262,7 +262,7 @@
         class Counter:
             def __init__(self):
                 self.count = 0
-            def next(self):
+            def __next__(self):
                 self.count += 1
                 return self.count
         x = Counter()
@@ -297,17 +297,17 @@
     def test_range_up(self):
         x = range(2)
         iter_x = iter(x)
-        assert iter_x.next() == 0
-        assert iter_x.next() == 1
-        raises(StopIteration, iter_x.next)
+        assert next(iter_x) == 0
+        assert next(iter_x) == 1
+        raises(StopIteration, next, iter_x)
 
     def test_range_down(self):
         x = range(4,2,-1)
 
         iter_x = iter(x)
-        assert iter_x.next() == 4
-        assert iter_x.next() == 3
-        raises(StopIteration, iter_x.next)
+        assert next(iter_x) == 4
+        assert next(iter_x) == 3
+        raises(StopIteration, next, iter_x)
 
     def test_range_has_type_identity(self):
         assert type(range(1)) == type(range(1))
@@ -315,13 +315,12 @@
     def test_range_len(self):
         x = range(33)
         assert len(x) == 33
-        x = range(33.2)
-        assert len(x) == 33
+        raises(TypeError, range, 33.2)
         x = range(33,0,-1)
         assert len(x) == 33
         x = range(33,0)
         assert len(x) == 0
-        x = range(33,0.2)
+        raises(TypeError, range, 33, 0.2)
         assert len(x) == 0
         x = range(0,33)
         assert len(x) == 33
@@ -495,7 +494,7 @@
         assert eval(co) == 3
         compile("from __future__ import with_statement", "<test>", "exec")
         raises(SyntaxError, compile, '-', '?', 'eval')
-        raises(ValueError, compile, '"\\xt"', '?', 'eval')
+        raises(SyntaxError, compile, '"\\xt"', '?', 'eval')
         raises(ValueError, compile, '1+2', '?', 'maybenot')
         raises(ValueError, compile, "\n", "<string>", "exec", 0xff)
         raises(TypeError, compile, '1+2', 12, 34)
@@ -513,7 +512,7 @@
     def test_recompile_ast(self):
         import _ast
         # raise exception when node type doesn't match with compile mode
-        co1 = compile('print 1', '<string>', 'exec', _ast.PyCF_ONLY_AST)
+        co1 = compile('print(1)', '<string>', 'exec', _ast.PyCF_ONLY_AST)
         raises(TypeError, compile, co1, '<ast>', 'eval')
         co2 = compile('1+1', '<string>', 'eval', _ast.PyCF_ONLY_AST)
         compile(co2, '<ast>', 'eval')
@@ -589,39 +588,39 @@
         assert firstlineno == 2
 
     def test_print_function(self):
-        import __builtin__
+        import builtins
         import sys
-        import StringIO
-        pr = getattr(__builtin__, "print")
+        import io
+        pr = getattr(builtins, "print")
         save = sys.stdout
-        out = sys.stdout = StringIO.StringIO()
+        out = sys.stdout = io.StringIO()
         try:
             pr("Hello,", "person!")
         finally:
             sys.stdout = save
         assert out.getvalue() == "Hello, person!\n"
-        out = StringIO.StringIO()
+        out = io.StringIO()
         pr("Hello,", "person!", file=out)
         assert out.getvalue() == "Hello, person!\n"
-        out = StringIO.StringIO()
+        out = io.StringIO()
         pr("Hello,", "person!", file=out, end="")
         assert out.getvalue() == "Hello, person!"
-        out = StringIO.StringIO()
+        out = io.StringIO()
         pr("Hello,", "person!", file=out, sep="X")
         assert out.getvalue() == "Hello,Xperson!\n"
-        out = StringIO.StringIO()
+        out = io.StringIO()
         pr(u"Hello,", u"person!", file=out)
         result = out.getvalue()
-        assert isinstance(result, unicode)
+        assert isinstance(result, str)
         assert result == u"Hello, person!\n"
         pr("Hello", file=None) # This works.
-        out = StringIO.StringIO()
+        out = io.StringIO()
         pr(None, file=out)
         assert out.getvalue() == "None\n"
 
     def test_print_exceptions(self):
-        import __builtin__
-        pr = getattr(__builtin__, "print")
+        import builtins
+        pr = getattr(builtins, "print")
         raises(TypeError, pr, x=3)
         raises(TypeError, pr, end=3)
         raises(TypeError, pr, sep=42)
diff --git a/pypy/module/__builtin__/test/test_descriptor.py b/pypy/module/__builtin__/test/test_descriptor.py
--- a/pypy/module/__builtin__/test/test_descriptor.py
+++ b/pypy/module/__builtin__/test/test_descriptor.py
@@ -342,7 +342,7 @@
         except ZeroDivisionError:
             pass
         else:
-            raise Exception, "expected ZeroDivisionError from bad property"
+            raise Exception("expected ZeroDivisionError from bad property")
 
     def test_property_subclass(self):
         class P(property):
diff --git a/pypy/module/__builtin__/test/test_filter.py b/pypy/module/__builtin__/test/test_filter.py
--- a/pypy/module/__builtin__/test/test_filter.py
+++ b/pypy/module/__builtin__/test/test_filter.py
@@ -16,22 +16,10 @@
         raises(TypeError, filter, lambda x: x>3, [1], [2])
 
     def test_filter_no_function_list(self):
-      assert filter(None, [1, 2, 3]) == [1, 2, 3]
-
-    def test_filter_no_function_tuple(self):
-      assert filter(None, (1, 2, 3)) == (1, 2, 3)
-
-    def test_filter_no_function_string(self):
-      assert filter(None, 'mystring') == 'mystring'
+      assert list(filter(None, [1, 2, 3])) == [1, 2, 3]
 
     def test_filter_no_function_with_bools(self):
-      assert filter(None, (True, False, True)) == (True, True)
+      assert tuple(filter(None, (True, False, True))) == (True, True)
       
     def test_filter_list(self):
-      assert filter(lambda x: x>3, [1, 2, 3, 4, 5]) == [4, 5]
-
-    def test_filter_tuple(self):
-      assert filter(lambda x: x>3, (1, 2, 3, 4, 5)) == (4, 5)
-
-    def test_filter_string(self):
-      assert filter(lambda x: x>'a', 'xyzabcd') == 'xyzbcd'
+      assert list(filter(lambda x: x>3, [1, 2, 3, 4, 5])) == [4, 5]
diff --git a/pypy/module/__builtin__/test/test_functional.py b/pypy/module/__builtin__/test/test_functional.py
--- a/pypy/module/__builtin__/test/test_functional.py
+++ b/pypy/module/__builtin__/test/test_functional.py
@@ -70,7 +70,7 @@
       class B(object):
          def __init__(self, n):
             self.n = n
-         def next(self):
+         def __next__(self):
             self.n -= 1
             if self.n == 0: raise StopIteration
             return self.n
@@ -126,12 +126,12 @@
       x = range(2, 9, 3)
       it = iter(x)
       assert iter(it) is it
-      assert it.next() == 2
-      assert it.next() == 5
-      assert it.next() == 8
-      raises(StopIteration, it.next)
+      assert it.__next__() == 2
+      assert it.__next__() == 5
+      assert it.__next__() == 8
+      raises(StopIteration, it.__next__)
       # test again, to make sure that range() is not its own iterator
-      assert iter(x).next() == 2
+      assert iter(x).__next__() == 2
 
    def test_range_object_with___int__(self):
        class A(object):
@@ -143,7 +143,7 @@
        assert list(range(0, 10, A())) == [0, 5]
 
    def test_range_float(self):
-      assert list(range(0.1, 2.0, 1.1)) == [0, 1]
+      raises(TypeError, range(0.1, 2.0, 1.1))
 
    def test_range_long(self):
        import sys
@@ -162,12 +162,12 @@
    def test_reversed(self):
       r = reversed("hello")
       assert iter(r) is r
-      assert r.next() == "o"
-      assert r.next() == "l"
-      assert r.next() == "l"
-      assert r.next() == "e"
-      assert r.next() == "h"
-      raises(StopIteration, r.next)
+      assert r.__next__() == "o"
+      assert r.__next__() == "l"
+      assert r.__next__() == "l"
+      assert r.__next__() == "e"
+      assert r.__next__() == "h"
+      raises(StopIteration, r.__next__)
       assert list(reversed(list(reversed("hello")))) == ['h','e','l','l','o']
       raises(TypeError, reversed, reversed("hello"))
 
diff --git a/pypy/module/__builtin__/test/test_rawinput.py b/pypy/module/__builtin__/test/test_rawinput.py
--- a/pypy/module/__builtin__/test/test_rawinput.py
+++ b/pypy/module/__builtin__/test/test_rawinput.py
@@ -1,30 +1,30 @@
+from __future__ import print_function
 import autopath
 
 
 class AppTestRawInput():
 
     def test_input_and_raw_input(self):
-        import sys, StringIO
-        for prompt, expected in [("def:", "abc/ def:/ghi\n"),
-                                 ("", "abc/ /ghi\n"),
-                                 (42, "abc/ 42/ghi\n"),
-                                 (None, "abc/ None/ghi\n"),
-                                 (Ellipsis, "abc/ /ghi\n")]:
+        import sys, io
+        for prompt, expected in [("def:", "abc/def:/ghi\n"),
+                                 ("", "abc//ghi\n"),
+                                 (42, "abc/42/ghi\n"),
+                                 (None, "abc/None/ghi\n"),
+                                 (Ellipsis, "abc//ghi\n")]:
             for inputfn, inputtext, gottext in [
-                    (raw_input, "foo\nbar\n", "foo"),
-                    (input, "40+2\n", 42)]:
+                    (input, "foo\nbar\n", "foo")]:
                 save = sys.stdin, sys.stdout
                 try:
-                    sys.stdin = StringIO.StringIO(inputtext)
-                    out = sys.stdout = StringIO.StringIO()
-                    print "abc",    # softspace = 1
+                    sys.stdin = io.StringIO(inputtext)
+                    out = sys.stdout = io.StringIO()
+                    print("abc", end='')
                     out.write('/')
                     if prompt is Ellipsis:
                         got = inputfn()
                     else:
                         got = inputfn(prompt)
                     out.write('/')
-                    print "ghi"
+                    print("ghi")
                 finally:
                     sys.stdin, sys.stdout = save
                 assert out.getvalue() == expected
@@ -32,9 +32,9 @@
 
     def test_softspace(self):
         import sys
-        import StringIO
-        fin = StringIO.StringIO()
-        fout = StringIO.StringIO()
+        import io
+        fin = io.StringIO()
+        fout = io.StringIO()
 
         fin.write("Coconuts\n")
         fin.seek(0)
@@ -45,20 +45,20 @@
         sys.stdin = fin
         sys.stdout = fout
 
-        print "test",
-        raw_input("test")
+        print("test", end='')
+        input("test")
 
         sys.stdin = sys_stdin_orig
         sys.stdout = sys_stdout_orig
 
         fout.seek(0)
-        assert fout.read() == "test test"
+        assert fout.read() == "testtest"
 
     def test_softspace_carryover(self):
         import sys
-        import StringIO
-        fin = StringIO.StringIO()
-        fout = StringIO.StringIO()
+        import io
+        fin = io.StringIO()
+        fout = io.StringIO()
 
         fin.write("Coconuts\n")
         fin.seek(0)
@@ -69,12 +69,12 @@
         sys.stdin = fin
         sys.stdout = fout
 
-        print "test",
-        raw_input("test")
-        print "test",
+        print("test", end='')
+        input("test")
+        print("test", end='')
 
         sys.stdin = sys_stdin_orig
         sys.stdout = sys_stdout_orig
 
         fout.seek(0)
-        assert fout.read() == "test testtest"
+        assert fout.read() == "testtesttest"
diff --git a/pypy/objspace/std/dictproxyobject.py b/pypy/objspace/std/dictproxyobject.py
--- a/pypy/objspace/std/dictproxyobject.py
+++ b/pypy/objspace/std/dictproxyobject.py
@@ -20,7 +20,7 @@
     def getitem(self, w_dict, w_key):
         space = self.space
         w_lookup_type = space.type(w_key)
-        if space.is_w(w_lookup_type, space.w_str):
+        if space.is_w(w_lookup_type, space.w_unicode):
             return self.getitem_str(w_dict, space.str_w(w_key))
         else:
             return None
@@ -30,7 +30,7 @@
 
     def setitem(self, w_dict, w_key, w_value):
         space = self.space
-        if space.is_w(space.type(w_key), space.w_str):
+        if space.is_w(space.type(w_key), space.w_unicode):
             self.setitem_str(w_dict, self.space.str_w(w_key), w_value)
         else:
             raise OperationError(space.w_TypeError, space.wrap("cannot add non-string keys to dict of a type"))
@@ -60,7 +60,7 @@
     def delitem(self, w_dict, w_key):
         space = self.space
         w_key_type = space.type(w_key)
-        if space.is_w(w_key_type, space.w_str):
+        if space.is_w(w_key_type, space.w_unicode):
             key = self.space.str_w(w_key)
             if not self.unerase(w_dict.dstorage).deldictvalue(space, key):
                 raise KeyError


More information about the pypy-commit mailing list