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

Method test_builtin_map

Lib/test/test_iter.py:608–635  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

606
607 # Test map()'s use of iterators.
608 def test_builtin_map(self):
609 self.assertEqual(list(map(lambda x: x+1, SequenceClass(5))),
610 list(range(1, 6)))
611
612 d = {"one": 1, "two": 2, "three": 3}
613 self.assertEqual(list(map(lambda k, d=d: (k, d[k]), d)),
614 list(d.items()))
615 dkeys = list(d.keys())
616 expected = [(i < len(d) and dkeys[i] or None,
617 i,
618 i < len(d) and dkeys[i] or None)
619 for i in range(3)]
620
621 f = open(TESTFN, "w", encoding="utf-8")
622 try:
623 for i in range(10):
624 f.write("xy" * i + "\n") # line i has len 2*i+1
625 finally:
626 f.close()
627 f = open(TESTFN, "r", encoding="utf-8")
628 try:
629 self.assertEqual(list(map(len, f)), list(range(1, 21, 2)))
630 finally:
631 f.close()
632 try:
633 unlink(TESTFN)
634 except OSError:
635 pass
636
637 # Test zip()'s use of iterators.
638 def test_builtin_zip(self):

Callers

nothing calls this directly

Calls 9

assertEqualMethod · 0.95
unlinkFunction · 0.90
listClass · 0.85
SequenceClassClass · 0.70
openFunction · 0.50
itemsMethod · 0.45
keysMethod · 0.45
writeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected