Skip to content

Commit 6a20ee7

Browse files
committed
Added test suite for the complete Unicode database. The test previously
only tested a few cases.
1 parent ba90909 commit 6a20ee7

File tree

1 file changed

+79
-7
lines changed

1 file changed

+79
-7
lines changed

Lib/test/test_unicodedata.py

Lines changed: 79 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,89 @@
11
""" Test script for the unicodedata module.
22
3-
Written by Marc-Andre Lemburg ([email protected]).
3+
Written by Marc-Andre Lemburg ([email protected]).
44
5-
(c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
5+
(c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
66
77
"""#"
8-
from test_support import verbose
9-
import sys
8+
import sha
109

11-
# Test Unicode database APIs
10+
def test_methods():
11+
12+
h = sha.sha()
13+
for i in range(65536):
14+
char = unichr(i)
15+
data = [
16+
17+
# Predicates (single char)
18+
char.isalnum() and u'1' or u'0',
19+
char.isalpha() and u'1' or u'0',
20+
char.isdecimal() and u'1' or u'0',
21+
char.isdigit() and u'1' or u'0',
22+
char.islower() and u'1' or u'0',
23+
char.isnumeric() and u'1' or u'0',
24+
char.isspace() and u'1' or u'0',
25+
char.istitle() and u'1' or u'0',
26+
char.isupper() and u'1' or u'0',
27+
28+
# Predicates (multiple chars)
29+
(char + u'abc').isalnum() and u'1' or u'0',
30+
(char + u'abc').isalpha() and u'1' or u'0',
31+
(char + u'123').isdecimal() and u'1' or u'0',
32+
(char + u'123').isdigit() and u'1' or u'0',
33+
(char + u'abc').islower() and u'1' or u'0',
34+
(char + u'123').isnumeric() and u'1' or u'0',
35+
(char + u' \t').isspace() and u'1' or u'0',
36+
(char + u'abc').istitle() and u'1' or u'0',
37+
(char + u'ABC').isupper() and u'1' or u'0',
38+
39+
# Mappings (single char)
40+
char.lower(),
41+
char.upper(),
42+
char.title(),
43+
44+
# Mappings (multiple chars)
45+
(char + u'abc').lower(),
46+
(char + u'ABC').upper(),
47+
(char + u'abc').title(),
48+
(char + u'ABC').title(),
49+
50+
]
51+
h.update(u''.join(data).encode('unicode-internal'))
52+
return h.hexdigest()
53+
54+
def test_unicodedata():
55+
56+
h = sha.sha()
57+
for i in range(65536):
58+
char = unichr(i)
59+
data = [
60+
# Properties
61+
str(unicodedata.digit(char, -1)),
62+
str(unicodedata.numeric(char, -1)),
63+
str(unicodedata.decimal(char, -1)),
64+
unicodedata.category(char),
65+
unicodedata.bidirectional(char),
66+
unicodedata.decomposition(char),
67+
str(unicodedata.mirrored(char)),
68+
str(unicodedata.combining(char)),
69+
]
70+
h.update(''.join(data))
71+
return h.hexdigest()
72+
73+
### Run tests
74+
75+
print 'Testing Unicode Database...'
76+
print 'Methods:',
77+
print test_methods()
78+
79+
# In case unicodedata is not available, this will raise an ImportError,
80+
# but still test the above cases...
1281
import unicodedata
82+
print 'Functions:',
83+
print test_unicodedata()
1384

14-
print 'Testing unicodedata module...',
85+
# Some additional checks of the API:
86+
print 'API:',
1587

1688
assert unicodedata.digit(u'A',None) is None
1789
assert unicodedata.digit(u'9') == 9
@@ -47,4 +119,4 @@
47119
assert unicodedata.combining(u'a') == 0
48120
assert unicodedata.combining(u'\u20e1') == 230
49121

50-
print 'done.'
122+
print 'ok'

0 commit comments

Comments
 (0)