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

Method test_translate

Lib/test/test_bigmem.py:746–763  ·  view source on GitHub ↗
(self, size)

Source from the content-addressed store, hash-verified

744
745 @bigmemtest(size=_2G, memuse=ascii_char_size * 2 + ucs4_char_size)
746 def test_translate(self, size):
747 _ = self.from_latin1
748 SUBSTR = _('aZz.z.Aaz.')
749 trans = {
750 ord(_('.')): _('-'),
751 ord(_('a')): _('!'),
752 ord(_('Z')): _('$'),
753 }
754 sublen = len(SUBSTR)
755 repeats = size // sublen + 2
756 s = SUBSTR * repeats
757 s = s.translate(trans)
758 self.assertEqual(len(s), repeats * sublen)
759 self.assertEqual(s[:sublen], SUBSTR.translate(trans))
760 self.assertEqual(s[-sublen:], SUBSTR.translate(trans))
761 self.assertEqual(s.count(_('.')), 0)
762 self.assertEqual(s.count(_('!')), repeats * 2)
763 self.assertEqual(s.count(_('z')), repeats * 3)
764
765
766class BytesTest(unittest.TestCase, BaseStrTest):

Callers

nothing calls this directly

Calls 4

_Function · 0.70
translateMethod · 0.45
assertEqualMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected