MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_tupleness

Method test_tupleness

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected