Debian Codegraph @

pypy/module/unicodedata/test/test_unicodedata.py

raw symbols SCIP
1 import py
2 import sys
3
4 class AppTestUnicodeData:
5 spaceconfig = dict(usemodules=('unicodedata',))
6
7 def test_hangul_syllables(self):
8 import unicodedata
9 # Test all leading, vowel and trailing jamo
10 # but not every combination of them.
11 for code, name in ((0xAC00, 'HANGUL SYLLABLE GA'),
12 (0xAE69, 'HANGUL SYLLABLE GGAEG'),
13 (0xB0D2, 'HANGUL SYLLABLE NYAGG'),
14 (0xB33B, 'HANGUL SYLLABLE DYAEGS'),
15 (0xB5A4, 'HANGUL SYLLABLE DDEON'),
16 (0xB80D, 'HANGUL SYLLABLE RENJ'),
17 (0xBA76, 'HANGUL SYLLABLE MYEONH'),
18 (0xBCDF, 'HANGUL SYLLABLE BYED'),
19 (0xBF48, 'HANGUL SYLLABLE BBOL'),
20 (0xC1B1, 'HANGUL SYLLABLE SWALG'),
21 (0xC41A, 'HANGUL SYLLABLE SSWAELM'),
22 (0xC683, 'HANGUL SYLLABLE OELB'),
23 (0xC8EC, 'HANGUL SYLLABLE JYOLS'),
24 (0xCB55, 'HANGUL SYLLABLE JJULT'),
25 (0xCDBE, 'HANGUL SYLLABLE CWEOLP'),
26 (0xD027, 'HANGUL SYLLABLE KWELH'),
27 (0xD290, 'HANGUL SYLLABLE TWIM'),
28 (0xD4F9, 'HANGUL SYLLABLE PYUB'),
29 (0xD762, 'HANGUL SYLLABLE HEUBS'),
30 (0xAE27, 'HANGUL SYLLABLE GYIS'),
31 (0xB090, 'HANGUL SYLLABLE GGISS'),
32 (0xB0AD, 'HANGUL SYLLABLE NANG'),
33 (0xB316, 'HANGUL SYLLABLE DAEJ'),
34 (0xB57F, 'HANGUL SYLLABLE DDYAC'),
35 (0xB7E8, 'HANGUL SYLLABLE RYAEK'),
36 (0xBA51, 'HANGUL SYLLABLE MEOT'),
37 (0xBCBA, 'HANGUL SYLLABLE BEP'),
38 (0xBF23, 'HANGUL SYLLABLE BBYEOH'),
39 (0xD7A3, 'HANGUL SYLLABLE HIH')):
40 assert unicodedata.name(chr(code)) == name
41 assert unicodedata.lookup(name) == chr(code)
42 # Test outside the range
43 raises(ValueError, unicodedata.name, chr(0xAC00 - 1))
44 raises(ValueError, unicodedata.name, chr(0xD7A3 + 1))
45
46 def test_cjk(self):
47 import sys
48 import unicodedata
49 assert int(unicodedata.unidata_version.split(".")[0]) >= 8
50 cases = [
51 ('3400', '4DB5'),
52 ('4E00', '9FFD'),
53 ('20000', '2A6DF'),
54 ('2A700', '2B738'),
55 ('2B740', '2CEA1'),
56 ('2CEB0', '2EBE0'),
57 ('30000', '3134A'),
58 ]
59 for first, last in cases:
60 first = int(first, 16)
61 last = int(last, 16)
62 # Test at and inside the boundary
63 for i in (first, first + 1, last - 1, last):
64 charname = 'CJK UNIFIED IDEOGRAPH-%X'%i
65 char = chr(i)
66 assert unicodedata.name(char) == charname
67 assert unicodedata.lookup(charname) == char
68 # Test outside the boundary
69 for i in first - 1, last + 1:
70 charname = 'CJK UNIFIED IDEOGRAPH-%X'%i
71 char = chr(i)
72 try:
73 unicodedata.name(char)
74 except ValueError as e:
75 assert str(e) == 'no such name'
76 raises(KeyError, unicodedata.lookup, charname)
77
78 def test_bug_1704793(self): # from CPython
79 import unicodedata
80 assert unicodedata.lookup("GOTHIC LETTER FAIHU") == '\U00010346'
81
82 def test_yes_alias_python3(self):
83 import unicodedata
84 assert unicodedata.lookup("LATIN SMALL LETTER GHA") == u"\u01a3"
85 assert unicodedata.name(u"\u01a3") == "LATIN SMALL LETTER OI"
86
87 def test_normalize_bad_argcount(self):
88 import unicodedata
89 raises(TypeError, unicodedata.normalize, 'x')
90
91 def test_normalize_nonunicode(self):
92 import unicodedata
93 exc_info = raises(TypeError, unicodedata.normalize, 'NFC', b'x')
94 assert 'must be unicode, not' in str(exc_info.value)
95
96 @py.test.mark.skipif("sys.maxunicode < 0x10ffff")
97 def test_normalize_wide(self):
98 import unicodedata
99 assert unicodedata.normalize('NFC', '\U000110a5\U000110ba') == '\U000110ab'
100
101 def test_is_normalized(self):
102 import unicodedata
103 assert unicodedata.is_normalized("NFC", '\U000110ab')
104 assert not unicodedata.is_normalized("NFC", '\U000110a5\U000110ba')
105
106 def test_linebreaks(self):
107 linebreaks = (0x0a, 0x0b, 0x0c, 0x0d, 0x85,
108 0x1c, 0x1d, 0x1e, 0x2028, 0x2029)
109 for i in linebreaks:
110 for j in range(-2, 3):
111 lines = (chr(i + j) + 'A').splitlines()
112 if i + j in linebreaks:
113 assert len(lines) == 2
114 else:
115 assert len(lines) == 1
116
117 def test_mirrored(self):
118 import unicodedata
119 # For no reason, unicodedata.mirrored() returns an int, not a bool
120 assert repr(unicodedata.mirrored(' ')) == '0'
121
122 def test_bidirectional_not_one_character(self):
123 import unicodedata
124 exc_info = raises(TypeError, unicodedata.bidirectional, u'xx')
125 assert str(exc_info.value) == 'need a single Unicode character as parameter'
126
127 def test_aliases(self):
128 import unicodedata
129 aliases = [
130 ('LATIN CAPITAL LETTER GHA', 0x01A2),
131 ('LATIN SMALL LETTER GHA', 0x01A3),
132 ('KANNADA LETTER LLLA', 0x0CDE),
133 ('LAO LETTER FO FON', 0x0E9D),
134 ('LAO LETTER FO FAY', 0x0E9F),
135 ('LAO LETTER RO', 0x0EA3),
136 ('LAO LETTER LO', 0x0EA5),
137 ('TIBETAN MARK BKA- SHOG GI MGO RGYAN', 0x0FD0),
138 ('YI SYLLABLE ITERATION MARK', 0xA015),
139 ('PRESENTATION FORM FOR VERTICAL RIGHT WHITE LENTICULAR BRACKET', 0xFE18),
140 ('BYZANTINE MUSICAL SYMBOL FTHORA SKLIRON CHROMA VASIS', 0x1D0C5)
141 ]
142 for alias, codepoint in aliases:
143 name = unicodedata.name(chr(codepoint))
144 assert name != alias
145 assert unicodedata.lookup(alias) == unicodedata.lookup(name)
146 raises(KeyError, unicodedata.ucd_3_2_0.lookup, alias)
147
148 def test_named_sequences(self):
149 import unicodedata
150 sequences = [
151 ('LATIN SMALL LETTER R WITH TILDE', '\u0072\u0303'),
152 ('TAMIL SYLLABLE SAI', '\u0BB8\u0BC8'),
153 ('TAMIL SYLLABLE MOO', '\u0BAE\u0BCB'),
154 ('TAMIL SYLLABLE NNOO', '\u0BA3\u0BCB'),
155 ('TAMIL CONSONANT KSS', '\u0B95\u0BCD\u0BB7\u0BCD'),
156 ]
157 for seqname, codepoints in sequences:
158 assert unicodedata.lookup(seqname) == codepoints
159 raises(SyntaxError, eval, r'"\N{%s}"' % seqname)
160
161 def test_names_in_pua_range(self):
162 # We are storing named seq in the PUA 15, but their names shouldn't leak
163 import unicodedata
164 for cp in range(0xf0000, 0xf0300, 7):
165 exc = raises(ValueError, unicodedata.name, chr(cp))
166 assert str(exc.value) == 'no such name'
167
168 def test_east_asian_width_9_0_changes(self):
169 import unicodedata
170 assert unicodedata.ucd_3_2_0.east_asian_width('\u231a') == 'N'
171 assert unicodedata.east_asian_width('\u231a') == 'W'
172
173 def test_11_change(self):
174 import unicodedata
175 assert unicodedata.name(chr(0x1f9b9)) == "SUPERVILLAIN"
176
177 def test_12_1_change(self):
178 import unicodedata
179 assert unicodedata.name(chr(0x32ff)) == 'SQUARE ERA NAME REIWA'
180
181 def test_13_0_change(self):
182 import unicodedata
183 assert unicodedata.lookup('CIRCLED CC')
184
185 def test_14_0_change(self):
186 import unicodedata
187 assert unicodedata.lookup('PLAYGROUND SLIDE')