|
12 | 12 | import struct
|
13 | 13 | import sys
|
14 | 14 | import textwrap
|
| 15 | +import unicodedata |
15 | 16 | import unittest
|
16 | 17 | import warnings
|
17 | 18 | from test import support, string_tests
|
@@ -617,11 +618,21 @@ def test_isspace(self):
|
617 | 618 | self.checkequalnofix(True, '\u2000', 'isspace')
|
618 | 619 | self.checkequalnofix(True, '\u200a', 'isspace')
|
619 | 620 | self.checkequalnofix(False, '\u2014', 'isspace')
|
620 |
| - # apparently there are no non-BMP spaces chars in Unicode 6 |
| 621 | + # There are no non-BMP whitespace chars as of Unicode 12. |
621 | 622 | for ch in ['\U00010401', '\U00010427', '\U00010429', '\U0001044E',
|
622 | 623 | '\U0001F40D', '\U0001F46F']:
|
623 | 624 | self.assertFalse(ch.isspace(), '{!a} is not space.'.format(ch))
|
624 | 625 |
|
| 626 | + @support.requires_resource('cpu') |
| 627 | + def test_isspace_invariant(self): |
| 628 | + for codepoint in range(sys.maxunicode + 1): |
| 629 | + char = chr(codepoint) |
| 630 | + bidirectional = unicodedata.bidirectional(char) |
| 631 | + category = unicodedata.category(char) |
| 632 | + self.assertEqual(char.isspace(), |
| 633 | + (bidirectional in ('WS', 'B', 'S') |
| 634 | + or category == 'Zs')) |
| 635 | + |
625 | 636 | def test_isalnum(self):
|
626 | 637 | super().test_isalnum()
|
627 | 638 | for ch in ['\U00010401', '\U00010427', '\U00010429', '\U0001044E',
|
|
0 commit comments