Commit 2acb54a1 authored by Fredrik Lundh's avatar Fredrik Lundh

improved the ucnhash test a bit

parent ee865c64
test_ucn test_ucn
Testing General Unicode Character Name, and case insensitivity... done. Testing General Unicode Character Name, and case insensitivity... done.
Testing name to code mapping.... done.
Testing code to name mapping for all characters.... done.
Found 10538 characters in the unicode name database
Testing misc. symbols for unicode character name expansion.... done. Testing misc. symbols for unicode character name expansion.... done.
Testing unicode character name expansion strict error handling.... done. Testing unicode character name expansion strict error handling.... done.
...@@ -37,25 +37,30 @@ s = u"\N{LATIN CAPITAL LETTER T}" \ ...@@ -37,25 +37,30 @@ s = u"\N{LATIN CAPITAL LETTER T}" \
u"\N{LATIN SMALL LETTER P}" \ u"\N{LATIN SMALL LETTER P}" \
u"\N{FULL STOP}" u"\N{FULL STOP}"
verify(s == u"The rEd fOx ate the sheep.", s) verify(s == u"The rEd fOx ate the sheep.", s)
print "done."
import ucnhash import ucnhash
# minimal sanity check print "Testing name to code mapping....",
for char in "SPAM": for char in "SPAM":
name = "LATIN SMALL LETTER %s" % char name = "LATIN SMALL LETTER %s" % char
code = ucnhash.getcode(name) code = ucnhash.getcode(name)
verify(ucnhash.getname(code) == name) verify(ucnhash.getname(code) == name)
print "done."
# loop over all characters in the database print "Testing code to name mapping for all characters....",
count = 0
for code in range(65536): for code in range(65536):
try: try:
name = ucnhash.getname(code) name = ucnhash.getname(code)
verify(ucnhash.getcode(name) == code) verify(ucnhash.getcode(name) == code)
count += 1
except ValueError: except ValueError:
pass pass
print "done." print "done."
print "Found", count, "characters in the unicode name database"
# misc. symbol testing # misc. symbol testing
print "Testing misc. symbols for unicode character name expansion....", print "Testing misc. symbols for unicode character name expansion....",
verify(u"\N{PILCROW SIGN}" == u"\u00b6") verify(u"\N{PILCROW SIGN}" == u"\u00b6")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment