summaryrefslogtreecommitdiff
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_funcattrs.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_funcattrs.py b/Lib/test/test_funcattrs.py
index 8f481bb64e..35fd657ec0 100644
--- a/Lib/test/test_funcattrs.py
+++ b/Lib/test/test_funcattrs.py
@@ -93,6 +93,26 @@ class FunctionPropertiesTest(FuncAttrsTest):
self.fail("shouldn't be able to read an empty cell")
a = 12
+ def test_set_cell(self):
+ a = 12
+ def f(): return a
+ c = f.__closure__
+ c[0].cell_contents = 9
+ self.assertEqual(c[0].cell_contents, 9)
+ self.assertEqual(f(), 9)
+ self.assertEqual(a, 9)
+ del c[0].cell_contents
+ try:
+ c[0].cell_contents
+ except ValueError:
+ pass
+ else:
+ self.fail("shouldn't be able to read an empty cell")
+ with self.assertRaises(NameError):
+ f()
+ with self.assertRaises(UnboundLocalError):
+ print(a)
+
def test___name__(self):
self.assertEqual(self.b.__name__, 'b')
self.b.__name__ = 'c'