Commit abc649dd authored by Victor Stinner's avatar Victor Stinner

Issue #14107: fix bigmem tests on str.capitalize(), str.swapcase() and

str.title(). Compute correctly how much memory is required for the test
(memuse).
parent c6fbf47b
...@@ -69,8 +69,7 @@ ucs4_char_size = 4 ...@@ -69,8 +69,7 @@ ucs4_char_size = 4
class BaseStrTest: class BaseStrTest:
@bigmemtest(size=_2G, memuse=2) def _test_capitalize(self, size):
def test_capitalize(self, size):
_ = self.from_latin1 _ = self.from_latin1
SUBSTR = self.from_latin1(' abc def ghi') SUBSTR = self.from_latin1(' abc def ghi')
s = _('-') * size + SUBSTR s = _('-') * size + SUBSTR
...@@ -421,8 +420,7 @@ class BaseStrTest: ...@@ -421,8 +420,7 @@ class BaseStrTest:
self.assertEqual(len(s), size) self.assertEqual(len(s), size)
self.assertEqual(s.strip(), SUBSTR.strip()) self.assertEqual(s.strip(), SUBSTR.strip())
@bigmemtest(size=_2G, memuse=2) def _test_swapcase(self, size):
def test_swapcase(self, size):
_ = self.from_latin1 _ = self.from_latin1
SUBSTR = _("aBcDeFG12.'\xa9\x00") SUBSTR = _("aBcDeFG12.'\xa9\x00")
sublen = len(SUBSTR) sublen = len(SUBSTR)
...@@ -433,8 +431,7 @@ class BaseStrTest: ...@@ -433,8 +431,7 @@ class BaseStrTest:
self.assertEqual(s[:sublen * 3], SUBSTR.swapcase() * 3) self.assertEqual(s[:sublen * 3], SUBSTR.swapcase() * 3)
self.assertEqual(s[-sublen * 3:], SUBSTR.swapcase() * 3) self.assertEqual(s[-sublen * 3:], SUBSTR.swapcase() * 3)
@bigmemtest(size=_2G, memuse=2) def _test_title(self, size):
def test_title(self, size):
_ = self.from_latin1 _ = self.from_latin1
SUBSTR = _('SpaaHAaaAaham') SUBSTR = _('SpaaHAaaAaham')
s = SUBSTR * (size // len(SUBSTR) + 2) s = SUBSTR * (size // len(SUBSTR) + 2)
...@@ -608,6 +605,18 @@ class StrTest(unittest.TestCase, BaseStrTest): ...@@ -608,6 +605,18 @@ class StrTest(unittest.TestCase, BaseStrTest):
for name, memuse in self._adjusted.items(): for name, memuse in self._adjusted.items():
getattr(type(self), name).memuse = memuse getattr(type(self), name).memuse = memuse
@bigmemtest(size=_2G, memuse=ucs4_char_size * 3)
def test_capitalize(self, size):
self._test_capitalize(size)
@bigmemtest(size=_2G, memuse=ucs4_char_size * 3)
def test_title(self, size):
self._test_title(size)
@bigmemtest(size=_2G, memuse=ucs4_char_size * 3)
def test_swapcase(self, size):
self._test_swapcase(size)
# Many codecs convert to the legacy representation first, explaining # Many codecs convert to the legacy representation first, explaining
# why we add 'ucs4_char_size' to the 'memuse' below. # why we add 'ucs4_char_size' to the 'memuse' below.
...@@ -763,6 +772,18 @@ class BytesTest(unittest.TestCase, BaseStrTest): ...@@ -763,6 +772,18 @@ class BytesTest(unittest.TestCase, BaseStrTest):
s = self.from_latin1('.') * size s = self.from_latin1('.') * size
self.assertEqual(len(s.decode('utf-8')), size) self.assertEqual(len(s.decode('utf-8')), size)
@bigmemtest(size=_2G, memuse=2)
def test_capitalize(self, size):
self._test_capitalize(size)
@bigmemtest(size=_2G, memuse=2)
def test_title(self, size):
self._test_title(size)
@bigmemtest(size=_2G, memuse=2)
def test_swapcase(self, size):
self._test_swapcase(size)
class BytearrayTest(unittest.TestCase, BaseStrTest): class BytearrayTest(unittest.TestCase, BaseStrTest):
...@@ -774,6 +795,18 @@ class BytearrayTest(unittest.TestCase, BaseStrTest): ...@@ -774,6 +795,18 @@ class BytearrayTest(unittest.TestCase, BaseStrTest):
s = self.from_latin1('.') * size s = self.from_latin1('.') * size
self.assertEqual(len(s.decode('utf-8')), size) self.assertEqual(len(s.decode('utf-8')), size)
@bigmemtest(size=_2G, memuse=2)
def test_capitalize(self, size):
self._test_capitalize(size)
@bigmemtest(size=_2G, memuse=2)
def test_title(self, size):
self._test_title(size)
@bigmemtest(size=_2G, memuse=2)
def test_swapcase(self, size):
self._test_swapcase(size)
test_hash = None test_hash = None
test_split_large = None test_split_large = None
......
...@@ -10628,6 +10628,9 @@ unicode_title(PyObject *self) ...@@ -10628,6 +10628,9 @@ unicode_title(PyObject *self)
{ {
if (PyUnicode_READY(self) == -1) if (PyUnicode_READY(self) == -1)
return NULL; return NULL;
if (PyUnicode_IS_ASCII(self))
return ascii_case_operation(self, ascii_do_title);
else
return case_operation(self, do_title); return case_operation(self, do_title);
} }
...@@ -10644,6 +10647,9 @@ unicode_capitalize(PyObject *self) ...@@ -10644,6 +10647,9 @@ unicode_capitalize(PyObject *self)
return NULL; return NULL;
if (PyUnicode_GET_LENGTH(self) == 0) if (PyUnicode_GET_LENGTH(self) == 0)
return unicode_result_unchanged(self); return unicode_result_unchanged(self);
if (PyUnicode_IS_ASCII(self))
return ascii_case_operation(self, ascii_do_capitalize);
else
return case_operation(self, do_capitalize); return case_operation(self, do_capitalize);
} }
...@@ -10659,6 +10665,7 @@ unicode_casefold(PyObject *self) ...@@ -10659,6 +10665,7 @@ unicode_casefold(PyObject *self)
return NULL; return NULL;
if (PyUnicode_IS_ASCII(self)) if (PyUnicode_IS_ASCII(self))
return ascii_upper_or_lower(self, 1); return ascii_upper_or_lower(self, 1);
else
return case_operation(self, do_casefold); return case_operation(self, do_casefold);
} }
...@@ -11893,6 +11900,7 @@ unicode_lower(PyObject *self) ...@@ -11893,6 +11900,7 @@ unicode_lower(PyObject *self)
return NULL; return NULL;
if (PyUnicode_IS_ASCII(self)) if (PyUnicode_IS_ASCII(self))
return ascii_upper_or_lower(self, 1); return ascii_upper_or_lower(self, 1);
else
return case_operation(self, do_lower); return case_operation(self, do_lower);
} }
...@@ -12784,6 +12792,9 @@ unicode_swapcase(PyObject *self) ...@@ -12784,6 +12792,9 @@ unicode_swapcase(PyObject *self)
{ {
if (PyUnicode_READY(self) == -1) if (PyUnicode_READY(self) == -1)
return NULL; return NULL;
if (PyUnicode_IS_ASCII(self))
return ascii_case_operation(self, ascii_do_swapcase);
else
return case_operation(self, do_swapcase); return case_operation(self, do_swapcase);
} }
...@@ -12934,6 +12945,7 @@ unicode_upper(PyObject *self) ...@@ -12934,6 +12945,7 @@ unicode_upper(PyObject *self)
return NULL; return NULL;
if (PyUnicode_IS_ASCII(self)) if (PyUnicode_IS_ASCII(self))
return ascii_upper_or_lower(self, 0); return ascii_upper_or_lower(self, 0);
else
return case_operation(self, do_upper); return case_operation(self, do_upper);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment