Guido van Rossum | 24bdb04 | 2000-03-28 20:29:59 +0000 | [diff] [blame] | 1 | """ Test script for the unicodedata module. |
| 2 | |
Marc-André Lemburg | 6a20ee7 | 2000-09-26 16:18:58 +0000 | [diff] [blame] | 3 | Written by Marc-Andre Lemburg (mal@lemburg.com). |
Guido van Rossum | 24bdb04 | 2000-03-28 20:29:59 +0000 | [diff] [blame] | 4 | |
Marc-André Lemburg | 6a20ee7 | 2000-09-26 16:18:58 +0000 | [diff] [blame] | 5 | (c) Copyright CNRI, All Rights Reserved. NO WARRANTY. |
Guido van Rossum | 24bdb04 | 2000-03-28 20:29:59 +0000 | [diff] [blame] | 6 | |
Benjamin Peterson | 6f7fad1 | 2008-11-21 22:58:57 +0000 | [diff] [blame] | 7 | """ |
| 8 | |
| 9 | import sys |
| 10 | import unittest |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 11 | import hashlib |
Benjamin Peterson | 6f7fad1 | 2008-11-21 22:58:57 +0000 | [diff] [blame] | 12 | import subprocess |
| 13 | import test.support |
Guido van Rossum | 24bdb04 | 2000-03-28 20:29:59 +0000 | [diff] [blame] | 14 | |
Marc-André Lemburg | 67ceca7 | 2000-09-27 12:24:34 +0000 | [diff] [blame] | 15 | encoding = 'utf-8' |
| 16 | |
Marc-André Lemburg | 6a20ee7 | 2000-09-26 16:18:58 +0000 | [diff] [blame] | 17 | |
| 18 | ### Run tests |
| 19 | |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 20 | class UnicodeMethodsTest(unittest.TestCase): |
Marc-André Lemburg | 6a20ee7 | 2000-09-26 16:18:58 +0000 | [diff] [blame] | 21 | |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 22 | # update this, if the database changes |
Walter Dörwald | 1b08b30 | 2009-04-25 14:13:56 +0000 | [diff] [blame^] | 23 | expectedchecksum = 'b7db9b5f1d804976fa921d2009cbef6f025620c1' |
Guido van Rossum | 24bdb04 | 2000-03-28 20:29:59 +0000 | [diff] [blame] | 24 | |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 25 | def test_method_checksum(self): |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 26 | h = hashlib.sha1() |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 27 | for i in range(65536): |
Guido van Rossum | 84fc66d | 2007-05-03 17:18:26 +0000 | [diff] [blame] | 28 | char = chr(i) |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 29 | data = [ |
| 30 | # Predicates (single char) |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 31 | "01"[char.isalnum()], |
| 32 | "01"[char.isalpha()], |
| 33 | "01"[char.isdecimal()], |
| 34 | "01"[char.isdigit()], |
| 35 | "01"[char.islower()], |
| 36 | "01"[char.isnumeric()], |
| 37 | "01"[char.isspace()], |
| 38 | "01"[char.istitle()], |
| 39 | "01"[char.isupper()], |
Guido van Rossum | 24bdb04 | 2000-03-28 20:29:59 +0000 | [diff] [blame] | 40 | |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 41 | # Predicates (multiple chars) |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 42 | "01"[(char + 'abc').isalnum()], |
| 43 | "01"[(char + 'abc').isalpha()], |
| 44 | "01"[(char + '123').isdecimal()], |
| 45 | "01"[(char + '123').isdigit()], |
| 46 | "01"[(char + 'abc').islower()], |
| 47 | "01"[(char + '123').isnumeric()], |
| 48 | "01"[(char + ' \t').isspace()], |
| 49 | "01"[(char + 'abc').istitle()], |
| 50 | "01"[(char + 'ABC').isupper()], |
Guido van Rossum | 24bdb04 | 2000-03-28 20:29:59 +0000 | [diff] [blame] | 51 | |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 52 | # Mappings (single char) |
| 53 | char.lower(), |
| 54 | char.upper(), |
| 55 | char.title(), |
Guido van Rossum | 24bdb04 | 2000-03-28 20:29:59 +0000 | [diff] [blame] | 56 | |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 57 | # Mappings (multiple chars) |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 58 | (char + 'abc').lower(), |
| 59 | (char + 'ABC').upper(), |
| 60 | (char + 'abc').title(), |
| 61 | (char + 'ABC').title(), |
Guido van Rossum | 24bdb04 | 2000-03-28 20:29:59 +0000 | [diff] [blame] | 62 | |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 63 | ] |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 64 | h.update(''.join(data).encode(encoding)) |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 65 | result = h.hexdigest() |
| 66 | self.assertEqual(result, self.expectedchecksum) |
Guido van Rossum | 24bdb04 | 2000-03-28 20:29:59 +0000 | [diff] [blame] | 67 | |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 68 | class UnicodeDatabaseTest(unittest.TestCase): |
Guido van Rossum | 24bdb04 | 2000-03-28 20:29:59 +0000 | [diff] [blame] | 69 | |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 70 | def setUp(self): |
| 71 | # In case unicodedata is not available, this will raise an ImportError, |
| 72 | # but the other test cases will still be run |
| 73 | import unicodedata |
| 74 | self.db = unicodedata |
Guido van Rossum | 24bdb04 | 2000-03-28 20:29:59 +0000 | [diff] [blame] | 75 | |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 76 | def tearDown(self): |
| 77 | del self.db |
Guido van Rossum | 24bdb04 | 2000-03-28 20:29:59 +0000 | [diff] [blame] | 78 | |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 79 | class UnicodeFunctionsTest(UnicodeDatabaseTest): |
Guido van Rossum | 24bdb04 | 2000-03-28 20:29:59 +0000 | [diff] [blame] | 80 | |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 81 | # update this, if the database changes |
Martin v. Löwis | 93cbca3 | 2008-09-10 14:08:48 +0000 | [diff] [blame] | 82 | expectedchecksum = '3136d5afd787dc2bcb1bdcac95e385349fbebbca' |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 83 | |
| 84 | def test_function_checksum(self): |
| 85 | data = [] |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 86 | h = hashlib.sha1() |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 87 | |
| 88 | for i in range(0x10000): |
Guido van Rossum | 84fc66d | 2007-05-03 17:18:26 +0000 | [diff] [blame] | 89 | char = chr(i) |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 90 | data = [ |
| 91 | # Properties |
| 92 | str(self.db.digit(char, -1)), |
| 93 | str(self.db.numeric(char, -1)), |
| 94 | str(self.db.decimal(char, -1)), |
| 95 | self.db.category(char), |
| 96 | self.db.bidirectional(char), |
| 97 | self.db.decomposition(char), |
| 98 | str(self.db.mirrored(char)), |
| 99 | str(self.db.combining(char)), |
| 100 | ] |
Guido van Rossum | 9c62772 | 2007-08-27 18:31:48 +0000 | [diff] [blame] | 101 | h.update(''.join(data).encode("ascii")) |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 102 | result = h.hexdigest() |
| 103 | self.assertEqual(result, self.expectedchecksum) |
| 104 | |
| 105 | def test_digit(self): |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 106 | self.assertEqual(self.db.digit('A', None), None) |
| 107 | self.assertEqual(self.db.digit('9'), 9) |
| 108 | self.assertEqual(self.db.digit('\u215b', None), None) |
| 109 | self.assertEqual(self.db.digit('\u2468'), 9) |
Walter Dörwald | f342bfc | 2008-06-03 11:45:02 +0000 | [diff] [blame] | 110 | self.assertEqual(self.db.digit('\U00020000', None), None) |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 111 | |
| 112 | self.assertRaises(TypeError, self.db.digit) |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 113 | self.assertRaises(TypeError, self.db.digit, 'xx') |
| 114 | self.assertRaises(ValueError, self.db.digit, 'x') |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 115 | |
| 116 | def test_numeric(self): |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 117 | self.assertEqual(self.db.numeric('A',None), None) |
| 118 | self.assertEqual(self.db.numeric('9'), 9) |
| 119 | self.assertEqual(self.db.numeric('\u215b'), 0.125) |
| 120 | self.assertEqual(self.db.numeric('\u2468'), 9.0) |
Walter Dörwald | f342bfc | 2008-06-03 11:45:02 +0000 | [diff] [blame] | 121 | self.assertEqual(self.db.numeric('\U00020000', None), None) |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 122 | |
| 123 | self.assertRaises(TypeError, self.db.numeric) |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 124 | self.assertRaises(TypeError, self.db.numeric, 'xx') |
| 125 | self.assertRaises(ValueError, self.db.numeric, 'x') |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 126 | |
| 127 | def test_decimal(self): |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 128 | self.assertEqual(self.db.decimal('A',None), None) |
| 129 | self.assertEqual(self.db.decimal('9'), 9) |
| 130 | self.assertEqual(self.db.decimal('\u215b', None), None) |
| 131 | self.assertEqual(self.db.decimal('\u2468', None), None) |
Walter Dörwald | f342bfc | 2008-06-03 11:45:02 +0000 | [diff] [blame] | 132 | self.assertEqual(self.db.decimal('\U00020000', None), None) |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 133 | |
| 134 | self.assertRaises(TypeError, self.db.decimal) |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 135 | self.assertRaises(TypeError, self.db.decimal, 'xx') |
| 136 | self.assertRaises(ValueError, self.db.decimal, 'x') |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 137 | |
| 138 | def test_category(self): |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 139 | self.assertEqual(self.db.category('\uFFFE'), 'Cn') |
| 140 | self.assertEqual(self.db.category('a'), 'Ll') |
| 141 | self.assertEqual(self.db.category('A'), 'Lu') |
Walter Dörwald | f342bfc | 2008-06-03 11:45:02 +0000 | [diff] [blame] | 142 | self.assertEqual(self.db.category('\U00020000'), 'Lo') |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 143 | |
| 144 | self.assertRaises(TypeError, self.db.category) |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 145 | self.assertRaises(TypeError, self.db.category, 'xx') |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 146 | |
| 147 | def test_bidirectional(self): |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 148 | self.assertEqual(self.db.bidirectional('\uFFFE'), '') |
| 149 | self.assertEqual(self.db.bidirectional(' '), 'WS') |
| 150 | self.assertEqual(self.db.bidirectional('A'), 'L') |
Walter Dörwald | f342bfc | 2008-06-03 11:45:02 +0000 | [diff] [blame] | 151 | self.assertEqual(self.db.bidirectional('\U00020000'), 'L') |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 152 | |
| 153 | self.assertRaises(TypeError, self.db.bidirectional) |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 154 | self.assertRaises(TypeError, self.db.bidirectional, 'xx') |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 155 | |
| 156 | def test_decomposition(self): |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 157 | self.assertEqual(self.db.decomposition('\uFFFE'),'') |
| 158 | self.assertEqual(self.db.decomposition('\u00bc'), '<fraction> 0031 2044 0034') |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 159 | |
| 160 | self.assertRaises(TypeError, self.db.decomposition) |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 161 | self.assertRaises(TypeError, self.db.decomposition, 'xx') |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 162 | |
| 163 | def test_mirrored(self): |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 164 | self.assertEqual(self.db.mirrored('\uFFFE'), 0) |
| 165 | self.assertEqual(self.db.mirrored('a'), 0) |
| 166 | self.assertEqual(self.db.mirrored('\u2201'), 1) |
Walter Dörwald | f342bfc | 2008-06-03 11:45:02 +0000 | [diff] [blame] | 167 | self.assertEqual(self.db.mirrored('\U00020000'), 0) |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 168 | |
| 169 | self.assertRaises(TypeError, self.db.mirrored) |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 170 | self.assertRaises(TypeError, self.db.mirrored, 'xx') |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 171 | |
| 172 | def test_combining(self): |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 173 | self.assertEqual(self.db.combining('\uFFFE'), 0) |
| 174 | self.assertEqual(self.db.combining('a'), 0) |
| 175 | self.assertEqual(self.db.combining('\u20e1'), 230) |
Walter Dörwald | f342bfc | 2008-06-03 11:45:02 +0000 | [diff] [blame] | 176 | self.assertEqual(self.db.combining('\U00020000'), 0) |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 177 | |
| 178 | self.assertRaises(TypeError, self.db.combining) |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 179 | self.assertRaises(TypeError, self.db.combining, 'xx') |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 180 | |
| 181 | def test_normalize(self): |
| 182 | self.assertRaises(TypeError, self.db.normalize) |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 183 | self.assertRaises(ValueError, self.db.normalize, 'unknown', 'xx') |
| 184 | self.assertEqual(self.db.normalize('NFKC', ''), '') |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 185 | # The rest can be found in test_normalization.py |
| 186 | # which requires an external file. |
| 187 | |
Hye-Shik Chang | e9ddfbb | 2004-08-04 07:38:35 +0000 | [diff] [blame] | 188 | def test_east_asian_width(self): |
| 189 | eaw = self.db.east_asian_width |
Guido van Rossum | 98297ee | 2007-11-06 21:34:58 +0000 | [diff] [blame] | 190 | self.assertRaises(TypeError, eaw, b'a') |
Guido van Rossum | 254348e | 2007-11-21 19:29:53 +0000 | [diff] [blame] | 191 | self.assertRaises(TypeError, eaw, bytearray()) |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 192 | self.assertRaises(TypeError, eaw, '') |
| 193 | self.assertRaises(TypeError, eaw, 'ra') |
| 194 | self.assertEqual(eaw('\x1e'), 'N') |
| 195 | self.assertEqual(eaw('\x20'), 'Na') |
| 196 | self.assertEqual(eaw('\uC894'), 'W') |
| 197 | self.assertEqual(eaw('\uFF66'), 'H') |
| 198 | self.assertEqual(eaw('\uFF1F'), 'F') |
| 199 | self.assertEqual(eaw('\u2010'), 'A') |
Walter Dörwald | f342bfc | 2008-06-03 11:45:02 +0000 | [diff] [blame] | 200 | self.assertEqual(eaw('\U00020000'), 'W') |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 201 | |
| 202 | class UnicodeMiscTest(UnicodeDatabaseTest): |
| 203 | |
Benjamin Peterson | 6f7fad1 | 2008-11-21 22:58:57 +0000 | [diff] [blame] | 204 | def test_failed_import_during_compiling(self): |
| 205 | # Issue 4367 |
| 206 | # Decoding \N escapes requires the unicodedata module. If it can't be |
| 207 | # imported, we shouldn't segfault. |
| 208 | |
| 209 | # This program should raise a SyntaxError in the eval. |
| 210 | code = "import sys;" \ |
| 211 | "sys.modules['unicodedata'] = None;" \ |
| 212 | """eval("'\\\\N{SOFT HYPHEN}'")""" |
| 213 | args = [sys.executable, "-c", code] |
| 214 | # We use a subprocess because the unicodedata module may already have |
| 215 | # been loaded in this process. |
| 216 | popen = subprocess.Popen(args, stderr=subprocess.PIPE) |
| 217 | popen.wait() |
| 218 | self.assertEqual(popen.returncode, 1) |
| 219 | error = "SyntaxError: (unicode error) \\N escapes not supported " \ |
| 220 | "(can't load unicodedata module)" |
| 221 | self.assertTrue(error in popen.stderr.read().decode("ascii")) |
| 222 | |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 223 | def test_decimal_numeric_consistent(self): |
| 224 | # Test that decimal and numeric are consistent, |
| 225 | # i.e. if a character has a decimal value, |
Georg Brandl | 7eb4b7d | 2005-07-22 21:49:32 +0000 | [diff] [blame] | 226 | # its numeric value should be the same. |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 227 | count = 0 |
Guido van Rossum | 805365e | 2007-05-07 22:24:25 +0000 | [diff] [blame] | 228 | for i in range(0x10000): |
Guido van Rossum | 84fc66d | 2007-05-03 17:18:26 +0000 | [diff] [blame] | 229 | c = chr(i) |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 230 | dec = self.db.decimal(c, -1) |
| 231 | if dec != -1: |
| 232 | self.assertEqual(dec, self.db.numeric(c)) |
| 233 | count += 1 |
| 234 | self.assert_(count >= 10) # should have tested at least the ASCII digits |
| 235 | |
| 236 | def test_digit_numeric_consistent(self): |
| 237 | # Test that digit and numeric are consistent, |
Tim Peters | 669454e | 2003-03-07 17:30:48 +0000 | [diff] [blame] | 238 | # i.e. if a character has a digit value, |
Georg Brandl | 7eb4b7d | 2005-07-22 21:49:32 +0000 | [diff] [blame] | 239 | # its numeric value should be the same. |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 240 | count = 0 |
Guido van Rossum | 805365e | 2007-05-07 22:24:25 +0000 | [diff] [blame] | 241 | for i in range(0x10000): |
Guido van Rossum | 84fc66d | 2007-05-03 17:18:26 +0000 | [diff] [blame] | 242 | c = chr(i) |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 243 | dec = self.db.digit(c, -1) |
| 244 | if dec != -1: |
| 245 | self.assertEqual(dec, self.db.numeric(c)) |
| 246 | count += 1 |
| 247 | self.assert_(count >= 10) # should have tested at least the ASCII digits |
| 248 | |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 249 | def test_bug_1704793(self): |
| 250 | self.assertEquals(self.db.lookup("GOTHIC LETTER FAIHU"), '\U00010346') |
| 251 | |
Martin v. Löwis | 93cbca3 | 2008-09-10 14:08:48 +0000 | [diff] [blame] | 252 | def test_ucd_510(self): |
| 253 | import unicodedata |
| 254 | # In UCD 5.1.0, a mirrored property changed wrt. UCD 3.2.0 |
| 255 | self.assert_(unicodedata.mirrored("\u0f3a")) |
| 256 | self.assert_(not unicodedata.ucd_3_2_0.mirrored("\u0f3a")) |
| 257 | # Also, we now have two ways of representing |
| 258 | # the upper-case mapping: as delta, or as absolute value |
| 259 | self.assert_("a".upper()=='A') |
| 260 | self.assert_("\u1d79".upper()=='\ua77d') |
Walter Dörwald | 1b08b30 | 2009-04-25 14:13:56 +0000 | [diff] [blame^] | 261 | self.assert_(".".upper()=='.') |
| 262 | |
| 263 | def test_bug_5828(self): |
| 264 | self.assertEqual("\u1d79".lower(), "\u1d79") |
| 265 | # Only U+0000 should have U+0000 as its upper/lower/titlecase variant |
| 266 | self.assertEqual( |
| 267 | [ |
| 268 | c for c in range(sys.maxunicode+1) |
| 269 | if "\x00" in chr(c).lower()+chr(c).upper()+chr(c).title() |
| 270 | ], |
| 271 | [0] |
| 272 | ) |
| 273 | |
Martin v. Löwis | 93cbca3 | 2008-09-10 14:08:48 +0000 | [diff] [blame] | 274 | |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 275 | def test_main(): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 276 | test.support.run_unittest( |
Walter Dörwald | 21d3a32 | 2003-05-01 17:45:56 +0000 | [diff] [blame] | 277 | UnicodeMiscTest, |
| 278 | UnicodeMethodsTest, |
| 279 | UnicodeFunctionsTest |
| 280 | ) |
Walter Dörwald | 37c4728 | 2003-02-26 14:49:41 +0000 | [diff] [blame] | 281 | |
| 282 | if __name__ == "__main__": |
| 283 | test_main() |