annotate Lib/test/test_ucn.py @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents 1741af48fd9f
children f4d30d1a529e beacf40b5960
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13191
7e71975ea5f0 New test for the ucnhash module.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
1 """ Test script for the Unicode implementation.
7e71975ea5f0 New test for the ucnhash module.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
2
7e71975ea5f0 New test for the ucnhash module.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
3 Written by Bill Tutt.
16200
3484670c37f2 Move uchhash functionality into unicodedata (after the recent
Fredrik Lundh <fredrik@pythonware.com>
parents: 16064
diff changeset
4 Modified for Python 2.0 by Fredrik Lundh (fredrik@pythonware.com)
13191
7e71975ea5f0 New test for the ucnhash module.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
5
7e71975ea5f0 New test for the ucnhash module.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
6 (c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
7e71975ea5f0 New test for the ucnhash module.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
7
7e71975ea5f0 New test for the ucnhash module.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
8 """#"
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
9
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
10 import unittest
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
11
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
12 from test import test_support
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
13
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
14 class UnicodeNamesTest(unittest.TestCase):
15957
c1a8deb15f0e This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents: 15305
diff changeset
15
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
16 def checkletter(self, name, code):
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
17 # Helper that put all \N escapes inside eval'd raw strings,
28231
4cafa5141012 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 28075
diff changeset
18 # to make sure this script runs even if the compiler
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
19 # chokes on \N escapes
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
20 res = eval(ur'u"\N{%s}"' % name)
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
21 self.assertEqual(res, code)
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
22 return res
13191
7e71975ea5f0 New test for the ucnhash module.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
23
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
24 def test_general(self):
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
25 # General and case insensitivity test:
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
26 chars = [
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
27 "LATIN CAPITAL LETTER T",
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
28 "LATIN SMALL LETTER H",
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
29 "LATIN SMALL LETTER E",
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
30 "SPACE",
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
31 "LATIN SMALL LETTER R",
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
32 "LATIN CAPITAL LETTER E",
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
33 "LATIN SMALL LETTER D",
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
34 "SPACE",
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
35 "LATIN SMALL LETTER f",
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
36 "LATIN CAPITAL LeTtEr o",
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
37 "LATIN SMaLl LETTER x",
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
38 "SPACE",
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
39 "LATIN SMALL LETTER A",
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
40 "LATIN SMALL LETTER T",
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
41 "LATIN SMALL LETTER E",
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
42 "SPACE",
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
43 "LATIN SMALL LETTER T",
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
44 "LATIN SMALL LETTER H",
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
45 "LATIN SMALL LETTER E",
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
46 "SpAcE",
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
47 "LATIN SMALL LETTER S",
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
48 "LATIN SMALL LETTER H",
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
49 "LATIN small LETTER e",
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
50 "LATIN small LETTER e",
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
51 "LATIN SMALL LETTER P",
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
52 "FULL STOP"
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
53 ]
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
54 string = u"The rEd fOx ate the sheep."
16031
1bf5d8b4cebe added "getcode" and "getname" methods to the ucnhash module (they're
Fredrik Lundh <fredrik@pythonware.com>
parents: 16029
diff changeset
55
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
56 self.assertEqual(
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
57 u"".join([self.checkletter(*args) for args in zip(chars, string)]),
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
58 string
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
59 )
16031
1bf5d8b4cebe added "getcode" and "getname" methods to the ucnhash module (they're
Fredrik Lundh <fredrik@pythonware.com>
parents: 16029
diff changeset
60
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
61 def test_ascii_letters(self):
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
62 import unicodedata
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
63
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
64 for char in "".join(map(chr, xrange(ord("a"), ord("z")))):
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
65 name = "LATIN SMALL LETTER %s" % char.upper()
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
66 code = unicodedata.lookup(name)
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
67 self.assertEqual(unicodedata.name(code), name)
16031
1bf5d8b4cebe added "getcode" and "getname" methods to the ucnhash module (they're
Fredrik Lundh <fredrik@pythonware.com>
parents: 16029
diff changeset
68
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
69 def test_hangul_syllables(self):
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
70 self.checkletter("HANGUL SYLLABLE GA", u"\uac00")
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
71 self.checkletter("HANGUL SYLLABLE GGWEOSS", u"\uafe8")
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
72 self.checkletter("HANGUL SYLLABLE DOLS", u"\ub3d0")
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
73 self.checkletter("HANGUL SYLLABLE RYAN", u"\ub7b8")
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
74 self.checkletter("HANGUL SYLLABLE MWIK", u"\ubba0")
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
75 self.checkletter("HANGUL SYLLABLE BBWAEM", u"\ubf88")
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
76 self.checkletter("HANGUL SYLLABLE SSEOL", u"\uc370")
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
77 self.checkletter("HANGUL SYLLABLE YI", u"\uc758")
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
78 self.checkletter("HANGUL SYLLABLE JJYOSS", u"\ucb40")
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
79 self.checkletter("HANGUL SYLLABLE KYEOLS", u"\ucf28")
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
80 self.checkletter("HANGUL SYLLABLE PAN", u"\ud310")
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
81 self.checkletter("HANGUL SYLLABLE HWEOK", u"\ud6f8")
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
82 self.checkletter("HANGUL SYLLABLE HIH", u"\ud7a3")
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
83
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
84 import unicodedata
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
85 self.assertRaises(ValueError, unicodedata.name, u"\ud7a4")
26375
d0f2d1f3fc85 Add test cases for Hangul syllables. Update output.
Martin v. Löwis <martin@v.loewis.de>
parents: 24364
diff changeset
86
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
87 def test_cjk_unified_ideographs(self):
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
88 self.checkletter("CJK UNIFIED IDEOGRAPH-3400", u"\u3400")
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
89 self.checkletter("CJK UNIFIED IDEOGRAPH-4DB5", u"\u4db5")
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
90 self.checkletter("CJK UNIFIED IDEOGRAPH-4E00", u"\u4e00")
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
91 self.checkletter("CJK UNIFIED IDEOGRAPH-9FA5", u"\u9fa5")
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
92 self.checkletter("CJK UNIFIED IDEOGRAPH-20000", u"\U00020000")
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
93 self.checkletter("CJK UNIFIED IDEOGRAPH-2A6D6", u"\U0002a6d6")
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
94
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
95 def test_bmp_characters(self):
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
96 import unicodedata
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
97 count = 0
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
98 for code in xrange(0x10000):
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
99 char = unichr(code)
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
100 name = unicodedata.name(char, None)
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
101 if name is not None:
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
102 self.assertEqual(unicodedata.lookup(name), char)
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
103 count += 1
26376
0f2766302ba0 Implement names for CJK unified ideographs. Add name to KeyError output.
Martin v. Löwis <martin@v.loewis.de>
parents: 26375
diff changeset
104
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
105 def test_misc_symbols(self):
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
106 self.checkletter("PILCROW SIGN", u"\u00b6")
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
107 self.checkletter("REPLACEMENT CHARACTER", u"\uFFFD")
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
108 self.checkletter("HALFWIDTH KATAKANA SEMI-VOICED SOUND MARK", u"\uFF9F")
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
109 self.checkletter("FULLWIDTH LATIN SMALL LETTER A", u"\uFF41")
16031
1bf5d8b4cebe added "getcode" and "getname" methods to the ucnhash module (they're
Fredrik Lundh <fredrik@pythonware.com>
parents: 16029
diff changeset
110
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
111 def test_errors(self):
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
112 import unicodedata
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
113 self.assertRaises(TypeError, unicodedata.name)
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
114 self.assertRaises(TypeError, unicodedata.name, u'xx')
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
115 self.assertRaises(TypeError, unicodedata.lookup)
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
116 self.assertRaises(KeyError, unicodedata.lookup, u'unknown')
13191
7e71975ea5f0 New test for the ucnhash module.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
117
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
118 def test_strict_eror_handling(self):
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
119 # bogus character name
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
120 self.assertRaises(
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
121 UnicodeError,
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
122 unicode, "\\N{blah}", 'unicode-escape', 'strict'
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
123 )
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
124 # long bogus character name
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
125 self.assertRaises(
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
126 UnicodeError,
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
127 unicode, "\\N{%s}" % ("x" * 100000), 'unicode-escape', 'strict'
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
128 )
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
129 # missing closing brace
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
130 self.assertRaises(
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
131 UnicodeError,
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
132 unicode, "\\N{SPACE", 'unicode-escape', 'strict'
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
133 )
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
134 # missing opening brace
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
135 self.assertRaises(
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
136 UnicodeError,
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
137 unicode, "\\NSPACE", 'unicode-escape', 'strict'
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
138 )
13191
7e71975ea5f0 New test for the ucnhash module.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
139
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
140 def test_main():
28917
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 28231
diff changeset
141 test_support.run_unittest(UnicodeNamesTest)
16029
55d89a8fe963 refactored the unicodeobject/ucnhash interface, to hide the
Fredrik Lundh <fredrik@pythonware.com>
parents: 15957
diff changeset
142
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
143 if __name__ == "__main__":
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 26376
diff changeset
144 test_main()