summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-02-10 02:41:10 (GMT)
committerBenjamin Peterson <benjamin@python.org>2009-02-10 02:41:10 (GMT)
commita86f2c06fd08e8aebf3641c1ad2d234425b90c55 (patch)
tree0780de78edaaf79a9dbe66d7b2011a8cbb4c9ddd /Lib/test
parent3a409e91d80b754699c9522217d70abd28d6f4f1 (diff)
downloadcpython-a86f2c06fd08e8aebf3641c1ad2d234425b90c55.zip
cpython-a86f2c06fd08e8aebf3641c1ad2d234425b90c55.tar.gz
cpython-a86f2c06fd08e8aebf3641c1ad2d234425b90c55.tar.bz2
Merged revisions 69466,69480 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r69466 | raymond.hettinger | 2009-02-09 12:39:41 -0600 (Mon, 09 Feb 2009) | 3 lines Issue 5171: itertools.product docstring missing 'repeat' argument ........ r69480 | raymond.hettinger | 2009-02-09 19:24:05 -0600 (Mon, 09 Feb 2009) | 1 line Issue 1818: collections.namedtuple() to support automatic renaming of invalid fieldnames. ........
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_collections.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
index c0cc016..1127910 100644
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -47,6 +47,17 @@ class TestNamedTuple(unittest.TestCase):
self.assertRaises(TypeError, Point._make, [11]) # catch too few args
self.assertRaises(TypeError, Point._make, [11, 22, 33]) # catch too many args
+ def test_name_fixer(self):
+ for spec, renamed in [
+ [('efg', 'g%hi'), ('efg', '_2')], # field with non-alpha char
+ [('abc', 'class'), ('abc', '_2')], # field has keyword
+ [('8efg', '9ghi'), ('_1', '_2')], # field starts with digit
+ [('abc', '_efg'), ('abc', '_2')], # field with leading underscore
+ [('abc', 'efg', 'efg', 'ghi'), ('abc', 'efg', '_3', 'ghi')], # duplicate field
+ [('abc', '', 'x'), ('abc', '_2', 'x')], # fieldname is a space
+ ]:
+ self.assertEqual(namedtuple('NT', spec, rename=True)._fields, renamed)
+
def test_instance(self):
Point = namedtuple('Point', 'x y')
p = Point(11, 22)