summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_funcattrs.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_funcattrs.py')
-rw-r--r--Lib/test/test_funcattrs.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/test_funcattrs.py b/Lib/test/test_funcattrs.py
index 4d19368..f4a38b9 100644
--- a/Lib/test/test_funcattrs.py
+++ b/Lib/test/test_funcattrs.py
@@ -2,6 +2,15 @@ from test import support
import types
import unittest
+
+def global_function():
+ def inner_function():
+ class LocalClass:
+ pass
+ return LocalClass
+ return lambda: inner_function
+
+
class FuncAttrsTest(unittest.TestCase):
def setUp(self):
class F:
@@ -96,6 +105,24 @@ class FunctionPropertiesTest(FuncAttrsTest):
self.assertEqual(self.fi.a.__name__, 'a')
self.cannot_set_attr(self.fi.a, "__name__", 'a', AttributeError)
+ def test___qualname__(self):
+ # PEP 3155
+ self.assertEqual(self.b.__qualname__, 'FuncAttrsTest.setUp.<locals>.b')
+ self.assertEqual(FuncAttrsTest.setUp.__qualname__, 'FuncAttrsTest.setUp')
+ self.assertEqual(global_function.__qualname__, 'global_function')
+ self.assertEqual(global_function().__qualname__,
+ 'global_function.<locals>.<lambda>')
+ self.assertEqual(global_function()().__qualname__,
+ 'global_function.<locals>.inner_function')
+ self.assertEqual(global_function()()().__qualname__,
+ 'global_function.<locals>.inner_function.<locals>.LocalClass')
+ self.b.__qualname__ = 'c'
+ self.assertEqual(self.b.__qualname__, 'c')
+ self.b.__qualname__ = 'd'
+ self.assertEqual(self.b.__qualname__, 'd')
+ # __qualname__ must be a string
+ self.cannot_set_attr(self.b, '__qualname__', 7, TypeError)
+
def test___code__(self):
num_one, num_two = 7, 8
def a(): pass