]> granicus.if.org Git - python/commitdiff
Issue #19928: Implemented a test for repr() of cell objects.
authorSerhiy Storchaka <storchaka@gmail.com>
Tue, 10 Dec 2013 08:20:31 +0000 (10:20 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Tue, 10 Dec 2013 08:20:31 +0000 (10:20 +0200)
Lib/test/test_reprlib.py
Misc/NEWS

index 7bf224735e35fb00d740871e38a6c42c0beeee77..3687de98b6de452b635bba0d16aeccaecb4442b5 100644 (file)
@@ -166,10 +166,16 @@ class ReprTests(unittest.TestCase):
         eq(r([[[[[[{}]]]]]]), "[[[[[[{}]]]]]]")
         eq(r([[[[[[[{}]]]]]]]), "[[[[[[[...]]]]]]]")
 
-    @unittest.skip('hard to catch a cell object')
     def test_cell(self):
-        # XXX Hmm? How to get at a cell object?
-        pass
+        def get_cell():
+            x = 42
+            def inner():
+                return x
+            return inner
+        x = get_cell().__closure__[0]
+        self.assertRegex(repr(x),
+                         r'<cell at 0x[0-9a-f]+: int object at 0x[0-9a-f]+>')
+        self.assertRegex(r(x), r'<cell at 0x.*\.\.\..*>')
 
     def test_descriptors(self):
         eq = self.assertEqual
index 535c3af0be44e50698768b29f9b534efb1a9af09..9026e754cbecefa54ecc5aff9901f9a6a5a34e57 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -114,6 +114,8 @@ IDLE
 Tests
 -----
 
+- Issue #19928: Implemented a test for repr() of cell objects.
+
 - Issue #19535: Fixed test_docxmlrpc when python is run with -OO.
 
 - Issue #19926: Removed unneeded test_main from test_abstract_numbers.