home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 April / PCWorld_2001-04_cd.bin / Software / TemaCD / webclean / !!!python!!! / BeOpen-Python-2.0.exe / TEST_UCN.PY < prev    next >
Encoding:
Python Source  |  2000-09-28  |  2.4 KB  |  83 lines

  1. """ Test script for the Unicode implementation.
  2.  
  3. Written by Bill Tutt.
  4.  
  5. (c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
  6.  
  7. """#"
  8. print 'Testing General Unicode Character Name, and case insensitivity...',
  9.  
  10. # General and case insensitivity test:
  11. s = u"\N{LATIN CAPITAL LETTER T}" \
  12.     u"\N{LATIN SMALL LETTER H}" \
  13.     u"\N{LATIN SMALL LETTER E}" \
  14.     u"\N{SPACE}" \
  15.     u"\N{LATIN SMALL LETTER R}" \
  16.     u"\N{LATIN CAPITAL LETTER E}" \
  17.     u"\N{LATIN SMALL LETTER D}" \
  18.     u"\N{SPACE}" \
  19.     u"\N{LATIN SMALL LETTER f}" \
  20.     u"\N{LATIN CAPITAL LeTtEr o}" \
  21.     u"\N{LATIN SMaLl LETTER x}" \
  22.     u"\N{SPACE}" \
  23.     u"\N{LATIN SMALL LETTER A}" \
  24.     u"\N{LATIN SMALL LETTER T}" \
  25.     u"\N{LATIN SMALL LETTER E}" \
  26.     u"\N{SPACE}" \
  27.     u"\N{LATIN SMALL LETTER T}" \
  28.     u"\N{LATIN SMALL LETTER H}" \
  29.     u"\N{LATIN SMALL LETTER E}" \
  30.     u"\N{SpAcE}" \
  31.     u"\N{LATIN SMALL LETTER S}" \
  32.     u"\N{LATIN SMALL LETTER H}" \
  33.     u"\N{LATIN SMALL LETTER E}" \
  34.     u"\N{LATIN SMALL LETTER E}" \
  35.     u"\N{LATIN SMALL LETTER P}" \
  36.     u"\N{FULL STOP}"
  37. assert s == u"The rEd fOx ate the sheep.", s
  38. print "done."
  39.  
  40. # misc. symbol testing
  41. print "Testing misc. symbols for unicode character name expansion....",
  42. assert u"\N{PILCROW SIGN}" == u"\u00b6"
  43. assert u"\N{REPLACEMENT CHARACTER}" == u"\uFFFD"
  44. assert u"\N{HALFWIDTH KATAKANA SEMI-VOICED SOUND MARK}" == u"\uFF9F"
  45. assert u"\N{FULLWIDTH LATIN SMALL LETTER A}" == u"\uFF41"
  46. print "done."
  47.  
  48.  
  49. # strict error testing:
  50. print "Testing unicode character name expansion strict error handling....",
  51. k_cchMaxUnicodeName = 83
  52.  
  53. s = "\N{" + "1" * (k_cchMaxUnicodeName + 2) + "}"
  54. try:
  55.   unicode(s, 'unicode-escape', 'strict')
  56. except UnicodeError:
  57.   pass
  58. else:
  59.   raise AssertionError, "failed to raise an exception when presented " \
  60.                         "with a UCN > k_cchMaxUnicodeName"
  61. try:
  62.   unicode("\N{blah}", 'unicode-escape', 'strict')
  63. except UnicodeError:
  64.   pass
  65. else:
  66.   raise AssertionError, "failed to raise an exception when given a bogus character name"
  67.  
  68. try:
  69.   unicode("\N{SPACE", 'unicode-escape', 'strict')
  70. except UnicodeError:
  71.   pass
  72. else:
  73.   raise AssertionError, "failed to raise an exception for a missing closing brace."
  74.  
  75. try:
  76.   unicode("\NSPACE", 'unicode-escape', 'strict')
  77. except UnicodeError:
  78.   pass
  79. else:
  80.   raise AssertionError, "failed to raise an exception for a missing opening brace."
  81. print "done."
  82.  
  83.