[Python-checkins] cpython: Fix expected memory consumption for test_translate
antoine.pitrou
python-checkins at python.org
Thu Oct 6 22:44:45 CEST 2011
http://hg.python.org/cpython/rev/849f35a575a5
changeset: 72766:849f35a575a5
user: Antoine Pitrou <solipsis at pitrou.net>
date: Thu Oct 06 22:41:08 2011 +0200
summary:
Fix expected memory consumption for test_translate
files:
Lib/test/test_bigmem.py | 33 +++++++++++++++++++++-------
1 files changed, 25 insertions(+), 8 deletions(-)
diff --git a/Lib/test/test_bigmem.py b/Lib/test/test_bigmem.py
--- a/Lib/test/test_bigmem.py
+++ b/Lib/test/test_bigmem.py
@@ -446,14 +446,7 @@
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 @@
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):
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list