summaryrefslogtreecommitdiff
path: root/Lib/test/test_collections.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2009-02-10 01:24:05 +0000
committerRaymond Hettinger <python@rcn.com>2009-02-10 01:24:05 +0000
commit322daea7c3ba7fa73b09ebd50a78078d23d318a5 (patch)
tree6b760626e3024d3f5af361c25eb72d0adac8e3c0 /Lib/test/test_collections.py
parentc5eba1e4f72e36368c52f56ebf7a5dde00ca3ee0 (diff)
downloadcpython-git-322daea7c3ba7fa73b09ebd50a78078d23d318a5.tar.gz
Issue 1818: collections.namedtuple() to support automatic renaming of invalid fieldnames.
Diffstat (limited to 'Lib/test/test_collections.py')
-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 17ec30c65f..4901eae8e5 100644
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -44,6 +44,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)