Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_unicodedata.py @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | b36cb4602e21 |
| children |
| rev | line source |
|---|---|
| 12074 | 1 """ Test script for the unicodedata module. |
| 2 | |
|
14875
17b5c43c08a6
Added test suite for the complete Unicode database. The test previously
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
3 Written by Marc-Andre Lemburg (mal@lemburg.com). |
| 12074 | 4 |
|
14875
17b5c43c08a6
Added test suite for the complete Unicode database. The test previously
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
5 (c) Copyright CNRI, All Rights Reserved. NO WARRANTY. |
| 12074 | 6 |
|
49796
0bcafa64eccb
Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49124
diff
changeset
|
7 """ |
|
0bcafa64eccb
Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49124
diff
changeset
|
8 |
|
0bcafa64eccb
Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49124
diff
changeset
|
9 import sys |
|
0bcafa64eccb
Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49124
diff
changeset
|
10 import unittest |
|
38052
32a187f3d5ba
In stdlib, use hashlib instead of deprecated md5 and sha modules.
Georg Brandl <georg@python.org>
parents:
36924
diff
changeset
|
11 import hashlib |
|
49796
0bcafa64eccb
Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49124
diff
changeset
|
12 import subprocess |
|
0bcafa64eccb
Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49124
diff
changeset
|
13 import test.test_support |
|
14875
17b5c43c08a6
Added test suite for the complete Unicode database. The test previously
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
14 |
|
14896
ad98c136475e
Fixed encoding to use an endianness independent format.
Marc-André Lemburg <mal@egenix.com>
parents:
14875
diff
changeset
|
15 encoding = 'utf-8' |
|
ad98c136475e
Fixed encoding to use an endianness independent format.
Marc-André Lemburg <mal@egenix.com>
parents:
14875
diff
changeset
|
16 |
|
14875
17b5c43c08a6
Added test suite for the complete Unicode database. The test previously
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
17 |
|
17b5c43c08a6
Added test suite for the complete Unicode database. The test previously
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
18 ### Run tests |
|
17b5c43c08a6
Added test suite for the complete Unicode database. The test previously
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
19 |
|
28075
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
20 class UnicodeMethodsTest(unittest.TestCase): |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
21 |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
22 # update this, if the database changes |
|
59693
344cb6a4ef7d
Issue #8024: Update the Unicode database to 5.2
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59323
diff
changeset
|
23 expectedchecksum = '4504dffd035baea02c5b9de82bebc3d65e0e0baf' |
|
28075
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
24 |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
25 def test_method_checksum(self): |
|
38052
32a187f3d5ba
In stdlib, use hashlib instead of deprecated md5 and sha modules.
Georg Brandl <georg@python.org>
parents:
36924
diff
changeset
|
26 h = hashlib.sha1() |
|
60074
66e757d8ea93
#7643: Unicode codepoints VT (0x0B) and FF (0x0C) are linebreaks according to Unicode Standard Annex #14.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59693
diff
changeset
|
27 for i in range(0x10000): |
|
28075
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
28 char = unichr(i) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
29 data = [ |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
30 # Predicates (single char) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
31 u"01"[char.isalnum()], |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
32 u"01"[char.isalpha()], |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
33 u"01"[char.isdecimal()], |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
34 u"01"[char.isdigit()], |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
35 u"01"[char.islower()], |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
36 u"01"[char.isnumeric()], |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
37 u"01"[char.isspace()], |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
38 u"01"[char.istitle()], |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
39 u"01"[char.isupper()], |
|
14875
17b5c43c08a6
Added test suite for the complete Unicode database. The test previously
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
40 |
|
28075
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
41 # Predicates (multiple chars) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
42 u"01"[(char + u'abc').isalnum()], |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
43 u"01"[(char + u'abc').isalpha()], |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
44 u"01"[(char + u'123').isdecimal()], |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
45 u"01"[(char + u'123').isdigit()], |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
46 u"01"[(char + u'abc').islower()], |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
47 u"01"[(char + u'123').isnumeric()], |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
48 u"01"[(char + u' \t').isspace()], |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
49 u"01"[(char + u'abc').istitle()], |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
50 u"01"[(char + u'ABC').isupper()], |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
51 |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
52 # Mappings (single char) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
53 char.lower(), |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
54 char.upper(), |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
55 char.title(), |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
56 |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
57 # Mappings (multiple chars) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
58 (char + u'abc').lower(), |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
59 (char + u'ABC').upper(), |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
60 (char + u'abc').title(), |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
61 (char + u'ABC').title(), |
| 12074 | 62 |
|
28075
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
63 ] |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
64 h.update(u''.join(data).encode(encoding)) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
65 result = h.hexdigest() |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
66 self.assertEqual(result, self.expectedchecksum) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
67 |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
68 class UnicodeDatabaseTest(unittest.TestCase): |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
69 |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
70 def setUp(self): |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
71 # In case unicodedata is not available, this will raise an ImportError, |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
72 # but the other test cases will still be run |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
73 import unicodedata |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
74 self.db = unicodedata |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
75 |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
76 def tearDown(self): |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
77 del self.db |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
78 |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
79 class UnicodeFunctionsTest(UnicodeDatabaseTest): |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
80 |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
81 # update this, if the database changes |
|
59693
344cb6a4ef7d
Issue #8024: Update the Unicode database to 5.2
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59323
diff
changeset
|
82 expectedchecksum = '6ccf1b1a36460d2694f9b0b0f0324942fe70ede6' |
|
28075
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
83 |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
84 def test_function_checksum(self): |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
85 data = [] |
|
38052
32a187f3d5ba
In stdlib, use hashlib instead of deprecated md5 and sha modules.
Georg Brandl <georg@python.org>
parents:
36924
diff
changeset
|
86 h = hashlib.sha1() |
| 12074 | 87 |
|
28075
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
88 for i in range(0x10000): |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
89 char = unichr(i) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
90 data = [ |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
91 # Properties |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
92 str(self.db.digit(char, -1)), |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
93 str(self.db.numeric(char, -1)), |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
94 str(self.db.decimal(char, -1)), |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
95 self.db.category(char), |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
96 self.db.bidirectional(char), |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
97 self.db.decomposition(char), |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
98 str(self.db.mirrored(char)), |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
99 str(self.db.combining(char)), |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
100 ] |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
101 h.update(''.join(data)) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
102 result = h.hexdigest() |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
103 self.assertEqual(result, self.expectedchecksum) |
| 12074 | 104 |
|
28075
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
105 def test_digit(self): |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
106 self.assertEqual(self.db.digit(u'A', None), None) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
107 self.assertEqual(self.db.digit(u'9'), 9) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
108 self.assertEqual(self.db.digit(u'\u215b', None), None) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
109 self.assertEqual(self.db.digit(u'\u2468'), 9) |
|
47451
ed471a8009a6
Change all functions that expect one unicode character to accept a pair of
Walter Dörwald <walter@livinglogic.de>
parents:
42387
diff
changeset
|
110 self.assertEqual(self.db.digit(u'\U00020000', None), None) |
|
28075
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
111 |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
112 self.assertRaises(TypeError, self.db.digit) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
113 self.assertRaises(TypeError, self.db.digit, u'xx') |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
114 self.assertRaises(ValueError, self.db.digit, u'x') |
| 12074 | 115 |
|
28075
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
116 def test_numeric(self): |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
117 self.assertEqual(self.db.numeric(u'A',None), None) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
118 self.assertEqual(self.db.numeric(u'9'), 9) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
119 self.assertEqual(self.db.numeric(u'\u215b'), 0.125) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
120 self.assertEqual(self.db.numeric(u'\u2468'), 9.0) |
|
56406
a9864417286b
#1571184: makeunicodedata.py now generates the functions _PyUnicode_ToNumeric,
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
55002
diff
changeset
|
121 self.assertEqual(self.db.numeric(u'\ua627'), 7.0) |
|
47451
ed471a8009a6
Change all functions that expect one unicode character to accept a pair of
Walter Dörwald <walter@livinglogic.de>
parents:
42387
diff
changeset
|
122 self.assertEqual(self.db.numeric(u'\U00020000', None), None) |
|
28075
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
123 |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
124 self.assertRaises(TypeError, self.db.numeric) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
125 self.assertRaises(TypeError, self.db.numeric, u'xx') |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
126 self.assertRaises(ValueError, self.db.numeric, u'x') |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
127 |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
128 def test_decimal(self): |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
129 self.assertEqual(self.db.decimal(u'A',None), None) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
130 self.assertEqual(self.db.decimal(u'9'), 9) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
131 self.assertEqual(self.db.decimal(u'\u215b', None), None) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
132 self.assertEqual(self.db.decimal(u'\u2468', None), None) |
|
47451
ed471a8009a6
Change all functions that expect one unicode character to accept a pair of
Walter Dörwald <walter@livinglogic.de>
parents:
42387
diff
changeset
|
133 self.assertEqual(self.db.decimal(u'\U00020000', None), None) |
|
28075
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
134 |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
135 self.assertRaises(TypeError, self.db.decimal) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
136 self.assertRaises(TypeError, self.db.decimal, u'xx') |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
137 self.assertRaises(ValueError, self.db.decimal, u'x') |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
138 |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
139 def test_category(self): |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
140 self.assertEqual(self.db.category(u'\uFFFE'), 'Cn') |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
141 self.assertEqual(self.db.category(u'a'), 'Ll') |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
142 self.assertEqual(self.db.category(u'A'), 'Lu') |
|
47451
ed471a8009a6
Change all functions that expect one unicode character to accept a pair of
Walter Dörwald <walter@livinglogic.de>
parents:
42387
diff
changeset
|
143 self.assertEqual(self.db.category(u'\U00020000'), 'Lo') |
| 12074 | 144 |
|
28075
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
145 self.assertRaises(TypeError, self.db.category) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
146 self.assertRaises(TypeError, self.db.category, u'xx') |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
147 |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
148 def test_bidirectional(self): |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
149 self.assertEqual(self.db.bidirectional(u'\uFFFE'), '') |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
150 self.assertEqual(self.db.bidirectional(u' '), 'WS') |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
151 self.assertEqual(self.db.bidirectional(u'A'), 'L') |
|
47451
ed471a8009a6
Change all functions that expect one unicode character to accept a pair of
Walter Dörwald <walter@livinglogic.de>
parents:
42387
diff
changeset
|
152 self.assertEqual(self.db.bidirectional(u'\U00020000'), 'L') |
|
28075
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
153 |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
154 self.assertRaises(TypeError, self.db.bidirectional) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
155 self.assertRaises(TypeError, self.db.bidirectional, u'xx') |
| 12074 | 156 |
|
28075
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
157 def test_decomposition(self): |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
158 self.assertEqual(self.db.decomposition(u'\uFFFE'),'') |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
159 self.assertEqual(self.db.decomposition(u'\u00bc'), '<fraction> 0031 2044 0034') |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
160 |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
161 self.assertRaises(TypeError, self.db.decomposition) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
162 self.assertRaises(TypeError, self.db.decomposition, u'xx') |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
163 |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
164 def test_mirrored(self): |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
165 self.assertEqual(self.db.mirrored(u'\uFFFE'), 0) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
166 self.assertEqual(self.db.mirrored(u'a'), 0) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
167 self.assertEqual(self.db.mirrored(u'\u2201'), 1) |
|
47451
ed471a8009a6
Change all functions that expect one unicode character to accept a pair of
Walter Dörwald <walter@livinglogic.de>
parents:
42387
diff
changeset
|
168 self.assertEqual(self.db.mirrored(u'\U00020000'), 0) |
|
28075
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
169 |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
170 self.assertRaises(TypeError, self.db.mirrored) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
171 self.assertRaises(TypeError, self.db.mirrored, u'xx') |
| 12074 | 172 |
|
28075
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
173 def test_combining(self): |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
174 self.assertEqual(self.db.combining(u'\uFFFE'), 0) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
175 self.assertEqual(self.db.combining(u'a'), 0) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
176 self.assertEqual(self.db.combining(u'\u20e1'), 230) |
|
47451
ed471a8009a6
Change all functions that expect one unicode character to accept a pair of
Walter Dörwald <walter@livinglogic.de>
parents:
42387
diff
changeset
|
177 self.assertEqual(self.db.combining(u'\U00020000'), 0) |
|
28075
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
178 |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
179 self.assertRaises(TypeError, self.db.combining) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
180 self.assertRaises(TypeError, self.db.combining, u'xx') |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
181 |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
182 def test_normalize(self): |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
183 self.assertRaises(TypeError, self.db.normalize) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
184 self.assertRaises(ValueError, self.db.normalize, 'unknown', u'xx') |
|
31930
f8c0ac5bef02
Special case normalization of empty strings. Fixes #924361.
Martin v. Löwis <martin@v.loewis.de>
parents:
28917
diff
changeset
|
185 self.assertEqual(self.db.normalize('NFKC', u''), u'') |
|
28075
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
186 # The rest can be found in test_normalization.py |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
187 # which requires an external file. |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
188 |
|
59819
8f1202ca888e
Merged revisions 78646 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
53474
diff
changeset
|
189 def test_pr29(self): |
|
8f1202ca888e
Merged revisions 78646 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
53474
diff
changeset
|
190 # http://www.unicode.org/review/pr-29.html |
|
67190
52a861746129
Merged revisions 87541,87543 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
59819
diff
changeset
|
191 # See issues #1054943 and #10254. |
|
52a861746129
Merged revisions 87541,87543 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
59819
diff
changeset
|
192 composed = (u"\u0b47\u0300\u0b3e", u"\u1100\u0300\u1161", |
|
52a861746129
Merged revisions 87541,87543 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
59819
diff
changeset
|
193 u'Li\u030dt-s\u1e73\u0301', |
|
52a861746129
Merged revisions 87541,87543 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
59819
diff
changeset
|
194 u'\u092e\u093e\u0930\u094d\u0915 \u091c\u093c' |
|
52a861746129
Merged revisions 87541,87543 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
59819
diff
changeset
|
195 + u'\u0941\u0915\u0947\u0930\u092c\u0930\u094d\u0917', |
|
52a861746129
Merged revisions 87541,87543 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
59819
diff
changeset
|
196 u'\u0915\u093f\u0930\u094d\u0917\u093f\u091c\u093c' |
|
52a861746129
Merged revisions 87541,87543 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
59819
diff
changeset
|
197 + 'u\u0938\u094d\u0924\u093e\u0928') |
|
52a861746129
Merged revisions 87541,87543 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
59819
diff
changeset
|
198 for text in composed: |
|
59819
8f1202ca888e
Merged revisions 78646 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
53474
diff
changeset
|
199 self.assertEqual(self.db.normalize('NFC', text), text) |
|
8f1202ca888e
Merged revisions 78646 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
53474
diff
changeset
|
200 |
|
67190
52a861746129
Merged revisions 87541,87543 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
59819
diff
changeset
|
201 def test_issue10254(self): |
|
52a861746129
Merged revisions 87541,87543 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
59819
diff
changeset
|
202 # Crash reported in #10254 |
|
52a861746129
Merged revisions 87541,87543 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
59819
diff
changeset
|
203 a = u'C\u0338' * 20 + u'C\u0327' |
|
52a861746129
Merged revisions 87541,87543 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
59819
diff
changeset
|
204 b = u'C\u0338' * 20 + u'\xC7' |
|
52a861746129
Merged revisions 87541,87543 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
59819
diff
changeset
|
205 self.assertEqual(self.db.normalize('NFC', a), b) |
|
52a861746129
Merged revisions 87541,87543 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
59819
diff
changeset
|
206 |
|
32951
024ff0ab4588
SF #989185: Drop unicode.iswide() and unicode.width() and add
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31930
diff
changeset
|
207 def test_east_asian_width(self): |
|
024ff0ab4588
SF #989185: Drop unicode.iswide() and unicode.width() and add
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31930
diff
changeset
|
208 eaw = self.db.east_asian_width |
|
024ff0ab4588
SF #989185: Drop unicode.iswide() and unicode.width() and add
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31930
diff
changeset
|
209 self.assertRaises(TypeError, eaw, 'a') |
|
024ff0ab4588
SF #989185: Drop unicode.iswide() and unicode.width() and add
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31930
diff
changeset
|
210 self.assertRaises(TypeError, eaw, u'') |
|
024ff0ab4588
SF #989185: Drop unicode.iswide() and unicode.width() and add
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31930
diff
changeset
|
211 self.assertRaises(TypeError, eaw, u'ra') |
|
024ff0ab4588
SF #989185: Drop unicode.iswide() and unicode.width() and add
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31930
diff
changeset
|
212 self.assertEqual(eaw(u'\x1e'), 'N') |
|
024ff0ab4588
SF #989185: Drop unicode.iswide() and unicode.width() and add
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31930
diff
changeset
|
213 self.assertEqual(eaw(u'\x20'), 'Na') |
|
024ff0ab4588
SF #989185: Drop unicode.iswide() and unicode.width() and add
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31930
diff
changeset
|
214 self.assertEqual(eaw(u'\uC894'), 'W') |
|
024ff0ab4588
SF #989185: Drop unicode.iswide() and unicode.width() and add
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31930
diff
changeset
|
215 self.assertEqual(eaw(u'\uFF66'), 'H') |
|
024ff0ab4588
SF #989185: Drop unicode.iswide() and unicode.width() and add
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31930
diff
changeset
|
216 self.assertEqual(eaw(u'\uFF1F'), 'F') |
|
024ff0ab4588
SF #989185: Drop unicode.iswide() and unicode.width() and add
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31930
diff
changeset
|
217 self.assertEqual(eaw(u'\u2010'), 'A') |
|
47451
ed471a8009a6
Change all functions that expect one unicode character to accept a pair of
Walter Dörwald <walter@livinglogic.de>
parents:
42387
diff
changeset
|
218 self.assertEqual(eaw(u'\U00020000'), 'W') |
|
28075
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
219 |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
220 class UnicodeMiscTest(UnicodeDatabaseTest): |
| 12074 | 221 |
|
49796
0bcafa64eccb
Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49124
diff
changeset
|
222 def test_failed_import_during_compiling(self): |
|
0bcafa64eccb
Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49124
diff
changeset
|
223 # Issue 4367 |
|
0bcafa64eccb
Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49124
diff
changeset
|
224 # Decoding \N escapes requires the unicodedata module. If it can't be |
|
0bcafa64eccb
Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49124
diff
changeset
|
225 # imported, we shouldn't segfault. |
|
0bcafa64eccb
Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49124
diff
changeset
|
226 |
|
0bcafa64eccb
Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49124
diff
changeset
|
227 # This program should raise a SyntaxError in the eval. |
|
0bcafa64eccb
Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49124
diff
changeset
|
228 code = "import sys;" \ |
|
0bcafa64eccb
Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49124
diff
changeset
|
229 "sys.modules['unicodedata'] = None;" \ |
|
0bcafa64eccb
Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49124
diff
changeset
|
230 """eval("u'\N{SOFT HYPHEN}'")""" |
|
0bcafa64eccb
Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49124
diff
changeset
|
231 args = [sys.executable, "-c", code] |
|
0bcafa64eccb
Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49124
diff
changeset
|
232 # We use a subprocess because the unicodedata module may already have |
|
0bcafa64eccb
Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49124
diff
changeset
|
233 # been loaded in this process. |
|
0bcafa64eccb
Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49124
diff
changeset
|
234 popen = subprocess.Popen(args, stderr=subprocess.PIPE) |
|
0bcafa64eccb
Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49124
diff
changeset
|
235 popen.wait() |
|
0bcafa64eccb
Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49124
diff
changeset
|
236 self.assertEqual(popen.returncode, 1) |
|
0bcafa64eccb
Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49124
diff
changeset
|
237 error = "SyntaxError: (unicode error) \N escapes not supported " \ |
|
0bcafa64eccb
Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49124
diff
changeset
|
238 "(can't load unicodedata module)" |
|
58460
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
56406
diff
changeset
|
239 self.assertIn(error, popen.stderr.read()) |
|
49796
0bcafa64eccb
Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49124
diff
changeset
|
240 |
|
28075
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
241 def test_decimal_numeric_consistent(self): |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
242 # Test that decimal and numeric are consistent, |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
243 # i.e. if a character has a decimal value, |
|
35276
4adbd331d335
Fix all wrong instances of "it's".
Georg Brandl <georg@python.org>
parents:
32951
diff
changeset
|
244 # its numeric value should be the same. |
|
28075
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
245 count = 0 |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
246 for i in xrange(0x10000): |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
247 c = unichr(i) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
248 dec = self.db.decimal(c, -1) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
249 if dec != -1: |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
250 self.assertEqual(dec, self.db.numeric(c)) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
251 count += 1 |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53474
diff
changeset
|
252 self.assertTrue(count >= 10) # should have tested at least the ASCII digits |
| 12074 | 253 |
|
28075
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
254 def test_digit_numeric_consistent(self): |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
255 # Test that digit and numeric are consistent, |
|
28231
4cafa5141012
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
28075
diff
changeset
|
256 # i.e. if a character has a digit value, |
|
35276
4adbd331d335
Fix all wrong instances of "it's".
Georg Brandl <georg@python.org>
parents:
32951
diff
changeset
|
257 # its numeric value should be the same. |
|
28075
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
258 count = 0 |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
259 for i in xrange(0x10000): |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
260 c = unichr(i) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
261 dec = self.db.digit(c, -1) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
262 if dec != -1: |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
263 self.assertEqual(dec, self.db.numeric(c)) |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
264 count += 1 |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53474
diff
changeset
|
265 self.assertTrue(count >= 10) # should have tested at least the ASCII digits |
| 12074 | 266 |
|
42386
7e7dce3089e3
Bug #1704793: Raise KeyError if unicodedata.lookup cannot
Martin v. Löwis <martin@v.loewis.de>
parents:
38422
diff
changeset
|
267 def test_bug_1704793(self): |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
60074
diff
changeset
|
268 self.assertEqual(self.db.lookup("GOTHIC LETTER FAIHU"), u'\U00010346') |
|
42387
85b7f40e1c1c
Bug #1704793: Return UTF-16 pair if unicodedata.lookup cannot
Martin v. Löwis <martin@v.loewis.de>
parents:
38422
diff
changeset
|
269 |
|
49124
c37c7dbd7880
Issue #3811: The Unicode database was updated to 5.1.
Martin v. Löwis <martin@v.loewis.de>
parents:
47451
diff
changeset
|
270 def test_ucd_510(self): |
|
c37c7dbd7880
Issue #3811: The Unicode database was updated to 5.1.
Martin v. Löwis <martin@v.loewis.de>
parents:
47451
diff
changeset
|
271 import unicodedata |
|
c37c7dbd7880
Issue #3811: The Unicode database was updated to 5.1.
Martin v. Löwis <martin@v.loewis.de>
parents:
47451
diff
changeset
|
272 # In UCD 5.1.0, a mirrored property changed wrt. UCD 3.2.0 |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53474
diff
changeset
|
273 self.assertTrue(unicodedata.mirrored(u"\u0f3a")) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53474
diff
changeset
|
274 self.assertTrue(not unicodedata.ucd_3_2_0.mirrored(u"\u0f3a")) |
|
49124
c37c7dbd7880
Issue #3811: The Unicode database was updated to 5.1.
Martin v. Löwis <martin@v.loewis.de>
parents:
47451
diff
changeset
|
275 # Also, we now have two ways of representing |
|
c37c7dbd7880
Issue #3811: The Unicode database was updated to 5.1.
Martin v. Löwis <martin@v.loewis.de>
parents:
47451
diff
changeset
|
276 # the upper-case mapping: as delta, or as absolute value |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53474
diff
changeset
|
277 self.assertTrue(u"a".upper()==u'A') |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53474
diff
changeset
|
278 self.assertTrue(u"\u1d79".upper()==u'\ua77d') |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53474
diff
changeset
|
279 self.assertTrue(u".".upper()==u".") |
|
53400
f08f776082ec
Merged revisions 71894 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents:
49796
diff
changeset
|
280 |
|
f08f776082ec
Merged revisions 71894 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents:
49796
diff
changeset
|
281 def test_bug_5828(self): |
|
f08f776082ec
Merged revisions 71894 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents:
49796
diff
changeset
|
282 self.assertEqual(u"\u1d79".lower(), u"\u1d79") |
|
f08f776082ec
Merged revisions 71894 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents:
49796
diff
changeset
|
283 # Only U+0000 should have U+0000 as its upper/lower/titlecase variant |
|
f08f776082ec
Merged revisions 71894 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents:
49796
diff
changeset
|
284 self.assertEqual( |
|
f08f776082ec
Merged revisions 71894 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents:
49796
diff
changeset
|
285 [ |
|
f08f776082ec
Merged revisions 71894 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents:
49796
diff
changeset
|
286 c for c in range(sys.maxunicode+1) |
|
f08f776082ec
Merged revisions 71894 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents:
49796
diff
changeset
|
287 if u"\x00" in unichr(c).lower()+unichr(c).upper()+unichr(c).title() |
|
f08f776082ec
Merged revisions 71894 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents:
49796
diff
changeset
|
288 ], |
|
f08f776082ec
Merged revisions 71894 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents:
49796
diff
changeset
|
289 [0] |
|
f08f776082ec
Merged revisions 71894 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents:
49796
diff
changeset
|
290 ) |
|
f08f776082ec
Merged revisions 71894 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents:
49796
diff
changeset
|
291 |
|
53474
355beb0bd02b
Merged revisions 71972 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents:
53450
diff
changeset
|
292 def test_bug_4971(self): |
|
53450
c92e93a54298
Merged revisions 71947 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
53400
diff
changeset
|
293 # LETTER DZ WITH CARON: DZ, Dz, dz |
|
c92e93a54298
Merged revisions 71947 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
53400
diff
changeset
|
294 self.assertEqual(u"\u01c4".title(), u"\u01c5") |
|
c92e93a54298
Merged revisions 71947 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
53400
diff
changeset
|
295 self.assertEqual(u"\u01c5".title(), u"\u01c5") |
|
c92e93a54298
Merged revisions 71947 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
53400
diff
changeset
|
296 self.assertEqual(u"\u01c6".title(), u"\u01c5") |
|
42386
7e7dce3089e3
Bug #1704793: Raise KeyError if unicodedata.lookup cannot
Martin v. Löwis <martin@v.loewis.de>
parents:
38422
diff
changeset
|
297 |
|
60074
66e757d8ea93
#7643: Unicode codepoints VT (0x0B) and FF (0x0C) are linebreaks according to Unicode Standard Annex #14.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59693
diff
changeset
|
298 def test_linebreak_7643(self): |
|
66e757d8ea93
#7643: Unicode codepoints VT (0x0B) and FF (0x0C) are linebreaks according to Unicode Standard Annex #14.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59693
diff
changeset
|
299 for i in range(0x10000): |
|
66e757d8ea93
#7643: Unicode codepoints VT (0x0B) and FF (0x0C) are linebreaks according to Unicode Standard Annex #14.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59693
diff
changeset
|
300 lines = (unichr(i) + u'A').splitlines() |
|
66e757d8ea93
#7643: Unicode codepoints VT (0x0B) and FF (0x0C) are linebreaks according to Unicode Standard Annex #14.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59693
diff
changeset
|
301 if i in (0x0a, 0x0b, 0x0c, 0x0d, 0x85, |
|
66e757d8ea93
#7643: Unicode codepoints VT (0x0B) and FF (0x0C) are linebreaks according to Unicode Standard Annex #14.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59693
diff
changeset
|
302 0x1c, 0x1d, 0x1e, 0x2028, 0x2029): |
|
66e757d8ea93
#7643: Unicode codepoints VT (0x0B) and FF (0x0C) are linebreaks according to Unicode Standard Annex #14.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59693
diff
changeset
|
303 self.assertEqual(len(lines), 2, |
|
66e757d8ea93
#7643: Unicode codepoints VT (0x0B) and FF (0x0C) are linebreaks according to Unicode Standard Annex #14.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59693
diff
changeset
|
304 r"\u%.4x should be a linebreak" % i) |
|
66e757d8ea93
#7643: Unicode codepoints VT (0x0B) and FF (0x0C) are linebreaks according to Unicode Standard Annex #14.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59693
diff
changeset
|
305 else: |
|
66e757d8ea93
#7643: Unicode codepoints VT (0x0B) and FF (0x0C) are linebreaks according to Unicode Standard Annex #14.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59693
diff
changeset
|
306 self.assertEqual(len(lines), 1, |
|
66e757d8ea93
#7643: Unicode codepoints VT (0x0B) and FF (0x0C) are linebreaks according to Unicode Standard Annex #14.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59693
diff
changeset
|
307 r"\u%.4x should not be a linebreak" % i) |
|
66e757d8ea93
#7643: Unicode codepoints VT (0x0B) and FF (0x0C) are linebreaks according to Unicode Standard Annex #14.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59693
diff
changeset
|
308 |
|
28075
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
309 def test_main(): |
|
28917
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28231
diff
changeset
|
310 test.test_support.run_unittest( |
|
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28231
diff
changeset
|
311 UnicodeMiscTest, |
|
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28231
diff
changeset
|
312 UnicodeMethodsTest, |
|
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28231
diff
changeset
|
313 UnicodeFunctionsTest |
|
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28231
diff
changeset
|
314 ) |
|
28075
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
315 |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
316 if __name__ == "__main__": |
|
7fdcc4cfc759
Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
317 test_main() |
