(self)
| 470 | self.assertEqual(NT.__module__, collections) |
| 471 | |
| 472 | def test_instance(self): |
| 473 | Point = namedtuple('Point', 'x y') |
| 474 | p = Point(11, 22) |
| 475 | self.assertEqual(p, Point(x=11, y=22)) |
| 476 | self.assertEqual(p, Point(11, y=22)) |
| 477 | self.assertEqual(p, Point(y=22, x=11)) |
| 478 | self.assertEqual(p, Point(*(11, 22))) |
| 479 | self.assertEqual(p, Point(**dict(x=11, y=22))) |
| 480 | self.assertRaises(TypeError, Point, 1) # too few args |
| 481 | self.assertRaises(TypeError, Point, 1, 2, 3) # too many args |
| 482 | with self.assertRaises(TypeError): # wrong keyword argument |
| 483 | Point(XXX=1, y=2) |
| 484 | with self.assertRaises(TypeError): # missing keyword argument |
| 485 | Point(x=1) |
| 486 | self.assertEqual(repr(p), 'Point(x=11, y=22)') |
| 487 | self.assertNotIn('__weakref__', dir(p)) |
| 488 | self.assertEqual(p, Point._make([11, 22])) # test _make classmethod |
| 489 | self.assertEqual(p._fields, ('x', 'y')) # test _fields attribute |
| 490 | self.assertEqual(p._replace(x=1), (1, 22)) # test _replace method |
| 491 | self.assertEqual(p._asdict(), dict(x=11, y=22)) # test _asdict method |
| 492 | |
| 493 | with self.assertRaises(TypeError): |
| 494 | p._replace(x=1, error=2) |
| 495 | |
| 496 | # verify that field string can have commas |
| 497 | Point = namedtuple('Point', 'x, y') |
| 498 | p = Point(x=11, y=22) |
| 499 | self.assertEqual(repr(p), 'Point(x=11, y=22)') |
| 500 | |
| 501 | # verify that fieldspec can be a non-string sequence |
| 502 | Point = namedtuple('Point', ('x', 'y')) |
| 503 | p = Point(x=11, y=22) |
| 504 | self.assertEqual(repr(p), 'Point(x=11, y=22)') |
| 505 | |
| 506 | def test_tupleness(self): |
| 507 | Point = namedtuple('Point', 'x y') |
nothing calls this directly
no test coverage detected