MCPcopy Index your code
hub / github.com/python/cpython / test_tupleness

Method test_tupleness

Lib/test/test_collections.py:506–527  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

504 self.assertEqual(repr(p), 'Point(x=11, y=22)')
505
506 def test_tupleness(self):
507 Point = namedtuple('Point', 'x y')
508 p = Point(11, 22)
509
510 self.assertIsInstance(p, tuple)
511 self.assertEqual(p, (11, 22)) # matches a real tuple
512 self.assertEqual(tuple(p), (11, 22)) # coercible to a real tuple
513 self.assertEqual(list(p), [11, 22]) # coercible to a list
514 self.assertEqual(max(p), 22) # iterable
515 self.assertEqual(max(*p), 22) # star-able
516 x, y = p
517 self.assertEqual(p, (x, y)) # unpacks like a tuple
518 self.assertEqual((p[0], p[1]), (11, 22)) # indexable like a tuple
519 with self.assertRaises(IndexError):
520 p[3]
521 self.assertEqual(p[-1], 22)
522 self.assertEqual(hash(p), hash((11, 22)))
523
524 self.assertEqual(p.x, x)
525 self.assertEqual(p.y, y)
526 with self.assertRaises(AttributeError):
527 p.z
528
529 def test_odd_sizes(self):
530 Zero = namedtuple('Zero', '')

Callers

nothing calls this directly

Calls 6

namedtupleFunction · 0.90
listClass · 0.85
assertIsInstanceMethod · 0.80
PointClass · 0.70
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected