]> granicus.if.org Git - python/commitdiff
Add test for __fields__ being read-only
authorRaymond Hettinger <python@rcn.com>
Wed, 14 Nov 2007 23:02:30 +0000 (23:02 +0000)
committerRaymond Hettinger <python@rcn.com>
Wed, 14 Nov 2007 23:02:30 +0000 (23:02 +0000)
Lib/test/test_collections.py

index 348919f42d00dcfa0f99eabe643a4fbffb8a11bf..04d4d9d24699e577c0b5bcdd4c930a25f7e29be1 100644 (file)
@@ -43,6 +43,14 @@ 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 __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
         Point = namedtuple('Point', 'x, y')
         p = Point(x=11, y=22)