Add error-checking to namedtuple's _replace() method.

This commit is contained in:
Raymond Hettinger 2008-01-05 02:17:24 +00:00
parent 02740f73ff
commit 1b50fd7cb3
3 changed files with 15 additions and 2 deletions

View file

@ -55,6 +55,13 @@ class TestNamedTuple(unittest.TestCase):
self.assertEqual(p._replace(x=1), (1, 22)) # test _replace method
self.assertEqual(p._asdict(), dict(x=11, y=22)) # test _asdict method
try:
p._replace(x=1, error=2)
except ValueError:
pass
else:
self._fail('Did not detect an incorrect fieldname')
# verify that field string can have commas
Point = namedtuple('Point', 'x, y')
p = Point(x=11, y=22)