diff options
author | Raymond Hettinger <python@rcn.com> | 2007-09-17 00:55:00 +0000 |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2007-09-17 00:55:00 +0000 |
commit | d36a60e1e3410450d337d4de732e127e48a6a042 (patch) | |
tree | 00c975e8766388d640629ec794061a33e96c3366 /Lib/test/test_collections.py | |
parent | bf10c47389d13b97e75855b262e077bfa688968c (diff) | |
download | cpython-git-d36a60e1e3410450d337d4de732e127e48a6a042.tar.gz |
Sync-up named tuples with the latest version of the ASPN recipe.
Allows optional commas in the field-name spec (help when named tuples are used in conjuction with sql queries).
Adds the __fields__ attribute for introspection and to support conversion to dictionary form.
Adds a __replace__() method similar to str.replace() but using a named field as a target.
Clean-up spelling and presentation in doc-strings.
Diffstat (limited to 'Lib/test/test_collections.py')
-rw-r--r-- | Lib/test/test_collections.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py index f5dad7d223..94015b42d3 100644 --- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -30,6 +30,13 @@ class TestNamedTuple(unittest.TestCase): self.assertEqual(repr(p), 'Point(x=11, y=22)') self.assert_('__dict__' not in dir(p)) # verify instance has no dict self.assert_('__weakref__' not in dir(p)) + self.assertEqual(p.__fields__, ('x', 'y')) # test __fields__ attribute + self.assertEqual(p.__replace__('x', 1), (1, 22)) # test __replace__ method + + # verify that field string can have commas + Point = NamedTuple('Point', 'x, y') + p = Point(x=11, y=22) + self.assertEqual(repr(p), 'Point(x=11, y=22)') def test_tupleness(self): Point = NamedTuple('Point', 'x y') |