summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_code.py2
-rw-r--r--Lib/test/test_descr.py11
-rw-r--r--Lib/test/test_dis.py1
-rw-r--r--Lib/test/test_funcattrs.py27
-rw-r--r--Lib/test/test_metaclass.py8
-rw-r--r--Lib/test/test_reprlib.py13
-rw-r--r--Lib/test/test_sys.py4
7 files changed, 51 insertions, 15 deletions
diff --git a/Lib/test/test_code.py b/Lib/test/test_code.py
index e1c7a78..3377a7b 100644
--- a/Lib/test/test_code.py
+++ b/Lib/test/test_code.py
@@ -16,7 +16,7 @@ cellvars: ('x',)
freevars: ()
nlocals: 2
flags: 3
-consts: ('None', '<code object g>')
+consts: ('None', '<code object g>', "'f.<locals>.g'")
>>> dump(f(4).__code__)
name: g
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 15219db..4a7a9d2 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -4492,9 +4492,14 @@ class DictProxyTests(unittest.TestCase):
self.assertEqual(type(C.__dict__), type(B.__dict__))
def test_repr(self):
- # Testing dict_proxy.__repr__
- dict_ = {k: v for k, v in self.C.__dict__.items()}
- self.assertEqual(repr(self.C.__dict__), 'dict_proxy({!r})'.format(dict_))
+ # Testing dict_proxy.__repr__.
+ # We can't blindly compare with the repr of another dict as ordering
+ # of keys and values is arbitrary and may differ.
+ r = repr(self.C.__dict__)
+ self.assertTrue(r.startswith('dict_proxy('), r)
+ self.assertTrue(r.endswith(')'), r)
+ for k, v in self.C.__dict__.items():
+ self.assertIn('{!r}: {!r}'.format(k, v), r)
class PTypesLongInitTest(unittest.TestCase):
diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py
index 4b0b02a..be38007 100644
--- a/Lib/test/test_dis.py
+++ b/Lib/test/test_dis.py
@@ -339,6 +339,7 @@ Flags: OPTIMIZED, NEWLOCALS, VARARGS, VARKEYWORDS, GENERATOR
Constants:
0: None
1: <code object f at (.*), file "(.*)", line (.*)>
+ 2: 'tricky.<locals>.f'
Variable names:
0: x
1: y
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
diff --git a/Lib/test/test_metaclass.py b/Lib/test/test_metaclass.py
index 6862900..e6fe20a 100644
--- a/Lib/test/test_metaclass.py
+++ b/Lib/test/test_metaclass.py
@@ -159,6 +159,7 @@ Use a __prepare__ method that returns an instrumented dict.
... bar = 123
...
d['__module__'] = 'test.test_metaclass'
+ d['__qualname__'] = 'C'
d['foo'] = 4
d['foo'] = 42
d['bar'] = 123
@@ -177,12 +178,12 @@ Use a metaclass that doesn't derive from type.
... b = 24
...
meta: C ()
- ns: [('__module__', 'test.test_metaclass'), ('a', 42), ('b', 24)]
+ ns: [('__module__', 'test.test_metaclass'), ('__qualname__', 'C'), ('a', 42), ('b', 24)]
kw: []
>>> type(C) is dict
True
>>> print(sorted(C.items()))
- [('__module__', 'test.test_metaclass'), ('a', 42), ('b', 24)]
+ [('__module__', 'test.test_metaclass'), ('__qualname__', 'C'), ('a', 42), ('b', 24)]
>>>
And again, with a __prepare__ attribute.
@@ -199,11 +200,12 @@ And again, with a __prepare__ attribute.
...
prepare: C () [('other', 'booh')]
d['__module__'] = 'test.test_metaclass'
+ d['__qualname__'] = 'C'
d['a'] = 1
d['a'] = 2
d['b'] = 3
meta: C ()
- ns: [('__module__', 'test.test_metaclass'), ('a', 2), ('b', 3)]
+ ns: [('__module__', 'test.test_metaclass'), ('__qualname__', 'C'), ('a', 2), ('b', 3)]
kw: [('other', 'booh')]
>>>
diff --git a/Lib/test/test_reprlib.py b/Lib/test/test_reprlib.py
index 439fa33..0365cea 100644
--- a/Lib/test/test_reprlib.py
+++ b/Lib/test/test_reprlib.py
@@ -129,8 +129,8 @@ class ReprTests(unittest.TestCase):
self.assertIn(s.find("..."), [12, 13])
def test_lambda(self):
- self.assertTrue(repr(lambda x: x).startswith(
- "<function <lambda"))
+ r = repr(lambda x: x)
+ self.assertTrue(r.startswith("<function ReprTests.test_lambda.<locals>.<lambda"), r)
# XXX anonymous functions? see func_repr
def test_builtin_function(self):
@@ -278,13 +278,14 @@ class aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
''')
from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import qux
# Unbound methods first
- self.assertTrue(repr(qux.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.amethod).startswith(
- '<function amethod'))
+ r = repr(qux.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.amethod)
+ self.assertTrue(r.startswith('<function aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.amethod'), r)
# Bound method next
iqux = qux.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()
- self.assertTrue(repr(iqux.amethod).startswith(
+ r = repr(iqux.amethod)
+ self.assertTrue(r.startswith(
'<bound method aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.amethod of <%s.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa object at 0x' \
- % (qux.__name__,) ))
+ % (qux.__name__,) ), r)
def test_builtin_function(self):
# XXX test built-in functions and methods with really long names
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index ba0b592..3169f67 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -730,7 +730,7 @@ class SizeofTest(unittest.TestCase):
check(x, size(vh + '12P3i' + CO_MAXBLOCKS*'3i' + 'P' + extras*'P'))
# function
def func(): pass
- check(func, size(h + '11P'))
+ check(func, size(h + '12P'))
class c():
@staticmethod
def foo():
@@ -828,7 +828,7 @@ class SizeofTest(unittest.TestCase):
# type
# (PyTypeObject + PyNumberMethods + PyMappingMethods +
# PySequenceMethods + PyBufferProcs)
- s = size(vh + 'P2P15Pl4PP9PP11PI') + size('16Pi17P 3P 10P 2P 2P')
+ s = size(vh + 'P2P15Pl4PP9PP11PI') + size('16Pi17P 3P 10P 2P 3P')
check(int, s)
# class
class newstyleclass(object): pass