aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_unicode.py
diff options
context:
space:
mode:
authorDennis Sweeney <36520290+sweeneyde@users.noreply.github.com>2022-05-17 10:12:21 -0400
committerGitHub <noreply@github.com>2022-05-17 10:12:21 -0400
commit19a4252459540913d0fd69beb66454f7c19bfef8 (patch)
tree5eb3a1dec148f6f07bf1b5087b52a14899c31ce5 /Lib/test/test_unicode.py
parent8781a041a00b7a202d73bcb47606ea10e56fb1d1 (diff)
downloadcpython-19a4252459540913d0fd69beb66454f7c19bfef8.tar.gz
cpython-19a4252459540913d0fd69beb66454f7c19bfef8.zip
gh-92536: Update unicode struct size to ensure MemoryError is raised (GH-92867)
Diffstat (limited to 'Lib/test/test_unicode.py')
-rw-r--r--Lib/test/test_unicode.py16
1 files changed, 6 insertions, 10 deletions
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index c98fabf8bc9..64abc0c761b 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -2370,14 +2370,9 @@ class UnicodeTest(string_tests.CommonTest,
self.assertIs(s.expandtabs(), s)
def test_raiseMemError(self):
- if struct.calcsize('P') == 8:
- # 64 bits pointers
- ascii_struct_size = 48
- compact_struct_size = 72
- else:
- # 32 bits pointers
- ascii_struct_size = 24
- compact_struct_size = 36
+ null_byte = 1
+ ascii_struct_size = sys.getsizeof("a") - len("a") - null_byte
+ compact_struct_size = sys.getsizeof("\xff") - len("\xff") - null_byte
for char in ('a', '\xe9', '\u20ac', '\U0010ffff'):
code = ord(char)
@@ -2395,8 +2390,9 @@ class UnicodeTest(string_tests.CommonTest,
# be allocatable, given enough memory.
maxlen = ((sys.maxsize - struct_size) // char_size)
alloc = lambda: char * maxlen
- self.assertRaises(MemoryError, alloc)
- self.assertRaises(MemoryError, alloc)
+ with self.subTest(char=char):
+ self.assertRaises(MemoryError, alloc)
+ self.assertRaises(MemoryError, alloc)
def test_format_subclass(self):
class S(str):