diff options
Diffstat (limited to 'Lib/test/test_collections.py')
-rw-r--r-- | Lib/test/test_collections.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py index ade5da2..24266ed 100644 --- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -38,6 +38,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') @@ -58,6 +65,12 @@ class TestNamedTuple(unittest.TestCase): self.assertEqual(p.y, y) self.assertRaises(AttributeError, eval, 'p.z', locals()) + def test_odd_sizes(self): + Zero = NamedTuple('Zero', '') + self.assertEqual(Zero(), ()) + Dot = NamedTuple('Dot', 'd') + self.assertEqual(Dot(1), (1,)) + class TestOneTrickPonyABCs(unittest.TestCase): |