summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-10-06 20:41:08 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-10-06 20:41:08 (GMT)
commit399df5549673040fdc6a6022c463e33fddcc4c2c (patch)
treed082c3cac28c96fdce5536c2c5c3535afc27027c /Lib
parentb6080b696762a4998e1ed8bd3532f53b960959a7 (diff)
downloadcpython-399df5549673040fdc6a6022c463e33fddcc4c2c.zip
cpython-399df5549673040fdc6a6022c463e33fddcc4c2c.tar.gz
cpython-399df5549673040fdc6a6022c463e33fddcc4c2c.tar.bz2
Fix expected memory consumption for test_translate
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_bigmem.py33
1 files changed, 25 insertions, 8 deletions
diff --git a/Lib/test/test_bigmem.py b/Lib/test/test_bigmem.py
index 4353602..4d7535c 100644
--- a/Lib/test/test_bigmem.py
+++ b/Lib/test/test_bigmem.py
@@ -446,14 +446,7 @@ class BaseStrTest:
def test_translate(self, size):
_ = self.from_latin1
SUBSTR = _('aZz.z.Aaz.')
- if isinstance(SUBSTR, str):
- trans = {
- ord(_('.')): _('-'),
- ord(_('a')): _('!'),
- ord(_('Z')): _('$'),
- }
- else:
- trans = bytes.maketrans(b'.aZ', b'-!$')
+ trans = bytes.maketrans(b'.aZ', b'-!$')
sublen = len(SUBSTR)
repeats = size // sublen + 2
s = SUBSTR * repeats
@@ -735,6 +728,30 @@ class StrTest(unittest.TestCase, BaseStrTest):
finally:
r = s = None
+ # The original test_translate is overriden here, so as to get the
+ # correct size estimate: str.translate() uses an intermediate Py_UCS4
+ # representation.
+
+ @bigmemtest(size=_2G, memuse=ascii_char_size * 2 + ucs4_char_size)
+ def test_translate(self, size):
+ _ = self.from_latin1
+ SUBSTR = _('aZz.z.Aaz.')
+ trans = {
+ ord(_('.')): _('-'),
+ ord(_('a')): _('!'),
+ ord(_('Z')): _('$'),
+ }
+ sublen = len(SUBSTR)
+ repeats = size // sublen + 2
+ s = SUBSTR * repeats
+ s = s.translate(trans)
+ self.assertEqual(len(s), repeats * sublen)
+ self.assertEqual(s[:sublen], SUBSTR.translate(trans))
+ self.assertEqual(s[-sublen:], SUBSTR.translate(trans))
+ self.assertEqual(s.count(_('.')), 0)
+ self.assertEqual(s.count(_('!')), repeats * 2)
+ self.assertEqual(s.count(_('z')), repeats * 3)
+
class BytesTest(unittest.TestCase, BaseStrTest):