Add test for __fields__ being read-only

This commit is contained in:
Raymond Hettinger 2007-11-14 23:02:30 +00:00
parent 78f27e001b
commit b5e5d0741a
1 changed files with 8 additions and 0 deletions

View File

@ -43,6 +43,14 @@ class TestNamedTuple(unittest.TestCase):
self.assertEqual(p.__replace__('x', 1), (1, 22)) # test __replace__ method self.assertEqual(p.__replace__('x', 1), (1, 22)) # test __replace__ method
self.assertEqual(p.__asdict__(), dict(x=11, y=22)) # test __dict__ method self.assertEqual(p.__asdict__(), dict(x=11, y=22)) # test __dict__ method
# Verify that __fields__ is read-only
try:
p.__fields__ = ('F1' ,'F2')
except AttributeError:
pass
else:
self.fail('The __fields__ attribute needs to be read-only')
# verify that field string can have commas # verify that field string can have commas
Point = namedtuple('Point', 'x, y') Point = namedtuple('Point', 'x, y')
p = Point(x=11, y=22) p = Point(x=11, y=22)