]> 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:11 +0000 (10:20 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Tue, 10 Dec 2013 08:20:11 +0000 (10:20 +0200)
Lib/test/test_repr.py
Misc/NEWS

index 062fccf9e09a6367835b807c47544df9e6ce4726..ae5203d107409737c0fd265849adb2819cc7129e 100644 (file)
@@ -179,8 +179,15 @@ class ReprTests(unittest.TestCase):
         self.assertTrue(repr(x).startswith('<read-only buffer for 0x'))
 
     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.assertRegexpMatches(repr(x), r'<cell at 0x[0-9a-f]+: '
+                                          r'int object at 0x[0-9a-f]+>')
+        self.assertRegexpMatches(r(x), r'<cell at.*\.\.\..*>')
 
     def test_descriptors(self):
         eq = self.assertEqual
index 30b796716ff94d4a68911038770e83525fb268c7..b1a4e1ffa481c8d3cae856172e548331bdd926a9 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -77,6 +77,8 @@ IDLE
 Tests
 -----
 
+- Issue #19928: Implemented a test for repr() of cell objects.
+
 - Issue #19595: Re-enabled a long-disabled test in test_winsound.
 
 - Issue #19588: Fixed tests in test_random that were silently skipped most