]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix the expected memory use of utf-8 encoding. Also, release the
authorAntoine Pitrou <solipsis@pitrou.net>
Wed, 12 Jan 2011 20:46:37 +0000 (20:46 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Wed, 12 Jan 2011 20:46:37 +0000 (20:46 +0000)
one reference to a huge object even when an exception is raised.

Lib/test/test_bigmem.py

index e2b552101b2e21dc3ec85b93b5e0a32cdce9ebaf..ac6b1096e1637c4f37ff421d8e305a756c7498b3 100644 (file)
@@ -564,8 +564,11 @@ class StrTest(unittest.TestCase, BaseStrTest):
         if expectedsize is None:
             expectedsize = size
 
-        s = c * size
-        self.assertEqual(len(s.encode(enc)), expectedsize)
+        try:
+            s = c * size
+            self.assertEqual(len(s.encode(enc)), expectedsize)
+        finally:
+            s = None
 
     def setUp(self):
         # HACK: adjust memory use of tests inherited from BaseStrTest
@@ -586,7 +589,8 @@ class StrTest(unittest.TestCase, BaseStrTest):
         for name, memuse in self._adjusted.items():
             getattr(type(self), name).memuse = memuse
 
-    @bigmemtest(minsize=_2G + 2, memuse=character_size + 1)
+    # the utf8 encoder preallocates big time (4x the number of characters)
+    @bigmemtest(minsize=_2G + 2, memuse=character_size + 4)
     def test_encode(self, size):
         return self.basic_encode_test(size, 'utf-8')