(self)
| 2477 | |
| 2478 | @unittest.expectedFailure # TODO: RUSTPYTHON |
| 2479 | def test_raiseMemError(self): |
| 2480 | asciifields = "nnb" |
| 2481 | compactfields = asciifields + "nP" |
| 2482 | ascii_struct_size = support.calcobjsize(asciifields) |
| 2483 | compact_struct_size = support.calcobjsize(compactfields) |
| 2484 | |
| 2485 | for char in ('a', '\xe9', '\u20ac', '\U0010ffff'): |
| 2486 | code = ord(char) |
| 2487 | if code < 0x80: |
| 2488 | char_size = 1 # sizeof(Py_UCS1) |
| 2489 | struct_size = ascii_struct_size |
| 2490 | elif code < 0x100: |
| 2491 | char_size = 1 # sizeof(Py_UCS1) |
| 2492 | struct_size = compact_struct_size |
| 2493 | elif code < 0x10000: |
| 2494 | char_size = 2 # sizeof(Py_UCS2) |
| 2495 | struct_size = compact_struct_size |
| 2496 | else: |
| 2497 | char_size = 4 # sizeof(Py_UCS4) |
| 2498 | struct_size = compact_struct_size |
| 2499 | # Note: sys.maxsize is half of the actual max allocation because of |
| 2500 | # the signedness of Py_ssize_t. Strings of maxlen-1 should in principle |
| 2501 | # be allocatable, given enough memory. |
| 2502 | maxlen = ((sys.maxsize - struct_size) // char_size) |
| 2503 | alloc = lambda: char * maxlen |
| 2504 | with self.subTest( |
| 2505 | char=char, |
| 2506 | struct_size=struct_size, |
| 2507 | char_size=char_size |
| 2508 | ): |
| 2509 | # self-check |
| 2510 | self.assertEqual( |
| 2511 | sys.getsizeof(char * 42), |
| 2512 | struct_size + (char_size * (42 + 1)) |
| 2513 | ) |
| 2514 | self.assertRaises(MemoryError, alloc) |
| 2515 | self.assertRaises(MemoryError, alloc) |
| 2516 | |
| 2517 | def test_format_subclass(self): |
| 2518 | class S(str): |
nothing calls this directly
no test coverage detected