1 """ Test script for the Unicode implementation.
4 Modified for Python 2.0 by Fredrik Lundh (fredrik@pythonware.com)
6 (c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
9 from test_support
import verify
, verbose
11 print 'Testing General Unicode Character Name, and case insensitivity...',
13 # General and case insensitivity test:
15 # put all \N escapes inside exec'd raw strings, to make sure this
16 # script runs even if the compiler chokes on \N escapes
18 s = u"\N{LATIN CAPITAL LETTER T}" \
19 u"\N{LATIN SMALL LETTER H}" \
20 u"\N{LATIN SMALL LETTER E}" \
22 u"\N{LATIN SMALL LETTER R}" \
23 u"\N{LATIN CAPITAL LETTER E}" \
24 u"\N{LATIN SMALL LETTER D}" \
26 u"\N{LATIN SMALL LETTER f}" \
27 u"\N{LATIN CAPITAL LeTtEr o}" \
28 u"\N{LATIN SMaLl LETTER x}" \
30 u"\N{LATIN SMALL LETTER A}" \
31 u"\N{LATIN SMALL LETTER T}" \
32 u"\N{LATIN SMALL LETTER E}" \
34 u"\N{LATIN SMALL LETTER T}" \
35 u"\N{LATIN SMALL LETTER H}" \
36 u"\N{LATIN SMALL LETTER E}" \
38 u"\N{LATIN SMALL LETTER S}" \
39 u"\N{LATIN SMALL LETTER H}" \
40 u"\N{LATIN SMALL LETTER E}" \
41 u"\N{LATIN SMALL LETTER E}" \
42 u"\N{LATIN SMALL LETTER P}" \
44 verify(s == u"The rEd fOx ate the sheep.", s)
46 except UnicodeError, v
:
52 print "Testing name to code mapping....",
54 name
= "LATIN SMALL LETTER %s" % char
55 code
= unicodedata
.lookup(name
)
56 verify(unicodedata
.name(code
) == name
)
59 print "Testing code to name mapping for all characters....",
61 for code
in range(65536):
64 name
= unicodedata
.name(char
)
65 verify(unicodedata
.lookup(name
) == char
)
67 except (KeyError, ValueError):
71 print "Found", count
, "characters in the unicode name database"
73 # misc. symbol testing
74 print "Testing misc. symbols for unicode character name expansion....",
76 verify(u"\N{PILCROW SIGN}" == u"\u00b6")
77 verify(u"\N{REPLACEMENT CHARACTER}" == u"\uFFFD")
78 verify(u"\N{HALFWIDTH KATAKANA SEMI-VOICED SOUND MARK}" == u"\uFF9F")
79 verify(u"\N{FULLWIDTH LATIN SMALL LETTER A}" == u"\uFF41")
83 # strict error testing:
84 print "Testing unicode character name expansion strict error handling....",
86 unicode("\N{blah}", 'unicode-escape', 'strict')
90 raise AssertionError, "failed to raise an exception when given a bogus character name"
93 unicode("\N{" + "x" * 100000 + "}", 'unicode-escape', 'strict')
97 raise AssertionError, "failed to raise an exception when given a very " \
98 "long bogus character name"
101 unicode("\N{SPACE", 'unicode-escape', 'strict')
105 raise AssertionError, "failed to raise an exception for a missing closing brace."
108 unicode("\NSPACE", 'unicode-escape', 'strict')
112 raise AssertionError, "failed to raise an exception for a missing opening brace."