Skip to content

Commit 1f79cdf

Browse files
Issue python#19928: Implemented a test for repr() of cell objects.
1 parent 9df8a1c commit 1f79cdf

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

Lib/test/test_reprlib.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,16 @@ def test_nesting(self):
166166
eq(r([[[[[[{}]]]]]]), "[[[[[[{}]]]]]]")
167167
eq(r([[[[[[[{}]]]]]]]), "[[[[[[[...]]]]]]]")
168168

169-
@unittest.skip('hard to catch a cell object')
170169
def test_cell(self):
171-
# XXX Hmm? How to get at a cell object?
172-
pass
170+
def get_cell():
171+
x = 42
172+
def inner():
173+
return x
174+
return inner
175+
x = get_cell().__closure__[0]
176+
self.assertRegex(repr(x),
177+
r'<cell at 0x[0-9a-f]+: int object at 0x[0-9a-f]+>')
178+
self.assertRegex(r(x), r'<cell at 0x.*\.\.\..*>')
173179

174180
def test_descriptors(self):
175181
eq = self.assertEqual

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ IDLE
114114
Tests
115115
-----
116116

117+
- Issue #19928: Implemented a test for repr() of cell objects.
118+
117119
- Issue #19535: Fixed test_docxmlrpc when python is run with -OO.
118120

119121
- Issue #19926: Removed unneeded test_main from test_abstract_numbers.

0 commit comments

Comments
 (0)