Author: Armin Rigo <[email protected]>
Branch: py3.3
Changeset: r72557:d4d93a364ca7
Date: 2014-07-27 11:55 +0200
http://bitbucket.org/pypy/pypy/changeset/d4d93a364ca7/
Log: Merged in numerodix/pypy/py3.3 (pull request #252)
py3.3 fixes for reprlib tests
diff --git a/lib-python/3/test/test_reprlib.py
b/lib-python/3/test/test_reprlib.py
--- a/lib-python/3/test/test_reprlib.py
+++ b/lib-python/3/test/test_reprlib.py
@@ -140,8 +140,12 @@
# Functions
eq(repr(hash), '<built-in function hash>')
# Methods
- self.assertTrue(repr(''.split).startswith(
- '<built-in method split of str object at 0x'))
+ self.assertTrue(any((
+ # cpython
+ repr(''.split).startswith('<built-in method split of str object at
0x'),
+ # pypy
+ repr(''.split) == "<bound method str.split of ''>",
+ )))
def test_range(self):
eq = self.assertEqual
@@ -178,9 +182,13 @@
self.assertRegex(r(x), r'<cell at 0x.*\.\.\..*>')
def test_descriptors(self):
- eq = self.assertEqual
# method descriptors
- eq(repr(dict.items), "<method 'items' of 'dict' objects>")
+ self.assertTrue(any((
+ # cpython
+ repr(dict.items) == "<method 'items' of 'dict' objects>",
+ # pypy
+ repr(dict.items).startswith("<function items at 0x"),
+ )))
# XXX member descriptors
# XXX attribute descriptors
# XXX slot descriptors
diff --git a/pypy/interpreter/nestedscope.py b/pypy/interpreter/nestedscope.py
--- a/pypy/interpreter/nestedscope.py
+++ b/pypy/interpreter/nestedscope.py
@@ -71,6 +71,14 @@
return "<%s(%s) at 0x%x>" % (self.__class__.__name__,
content, uid(self))
+ def descr__repr__(self, space):
+ if self.w_value is None:
+ content = "empty"
+ else:
+ content = "%s object at 0x%x" % (space.type(self.w_value).name,
uid(self.w_value))
+ s = "<cell at 0x%x: %s>" % (uid(self), content)
+ return space.wrap(s.decode('utf-8'))
+
def descr__cell_contents(self, space):
try:
return self.get()
diff --git a/pypy/interpreter/test/test_nestedscope.py
b/pypy/interpreter/test/test_nestedscope.py
--- a/pypy/interpreter/test/test_nestedscope.py
+++ b/pypy/interpreter/test/test_nestedscope.py
@@ -59,6 +59,28 @@
def test_lambda_in_genexpr(self):
assert [x() for x in (lambda: x for x in range(10))] == list(range(10))
+ def test_cell_repr(self):
+ import re
+ from reprlib import repr as r # Don't shadow builtin repr
+
+ def get_cell():
+ x = 42
+ def inner():
+ return x
+ return inner
+ x = get_cell().__closure__[0]
+ assert re.match(r'<cell at 0x[0-9A-Fa-f]+: int object at
0x[0-9A-Fa-f]+>', repr(x))
+ assert re.match(r'<cell at 0x.*\.\.\..*>', r(x))
+
+ def get_cell():
+ if False:
+ x = 42
+ def inner():
+ return x
+ return inner
+ x = get_cell().__closure__[0]
+ assert re.match(r'<cell at 0x[0-9A-Fa-f]+: empty>', repr(x))
+
def test_cell_contents(self):
def f(x):
def f(y):
diff --git a/pypy/interpreter/typedef.py b/pypy/interpreter/typedef.py
--- a/pypy/interpreter/typedef.py
+++ b/pypy/interpreter/typedef.py
@@ -944,6 +944,7 @@
__eq__ = interp2app(Cell.descr__eq__),
__hash__ = None,
__reduce__ = interp2app(Cell.descr__reduce__),
+ __repr__ = interp2app(Cell.descr__repr__),
__setstate__ = interp2app(Cell.descr__setstate__),
cell_contents= GetSetProperty(Cell.descr__cell_contents, cls=Cell),
)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit