Back to index

python3.2  3.2.2
Public Member Functions
test.test_ucn.UnicodeNamesTest Class Reference

List of all members.

Public Member Functions

def checkletter
def test_general
def test_ascii_letters
def test_hangul_syllables
def test_cjk_unified_ideographs
def test_bmp_characters
def test_misc_symbols
def test_errors
def test_strict_error_handling

Detailed Description

Definition at line 14 of file test_ucn.py.


Member Function Documentation

def test.test_ucn.UnicodeNamesTest.checkletter (   self,
  name,
  code 
)

Definition at line 16 of file test_ucn.py.

00016 
00017     def checkletter(self, name, code):
00018         # Helper that put all \N escapes inside eval'd raw strings,
00019         # to make sure this script runs even if the compiler
00020         # chokes on \N escapes
00021         res = eval(r'"\N{%s}"' % name)
00022         self.assertEqual(res, code)
00023         return res

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 61 of file test_ucn.py.

00061 
00062     def test_ascii_letters(self):
00063         import unicodedata
00064 
00065         for char in "".join(map(chr, range(ord("a"), ord("z")))):
00066             name = "LATIN SMALL LETTER %s" % char.upper()
00067             code = unicodedata.lookup(name)
00068             self.assertEqual(unicodedata.name(code), name)

Here is the call graph for this function:

Definition at line 99 of file test_ucn.py.

00099 
00100     def test_bmp_characters(self):
00101         import unicodedata
00102         count = 0
00103         for code in range(0x10000):
00104             char = chr(code)
00105             name = unicodedata.name(char, None)
00106             if name is not None:
00107                 self.assertEqual(unicodedata.lookup(name), char)
00108                 count += 1

Here is the call graph for this function:

Definition at line 87 of file test_ucn.py.

00087 
00088     def test_cjk_unified_ideographs(self):
00089         self.checkletter("CJK UNIFIED IDEOGRAPH-3400", "\u3400")
00090         self.checkletter("CJK UNIFIED IDEOGRAPH-4DB5", "\u4db5")
00091         self.checkletter("CJK UNIFIED IDEOGRAPH-4E00", "\u4e00")
00092         self.checkletter("CJK UNIFIED IDEOGRAPH-9FCB", "\u9fCB")
00093         self.checkletter("CJK UNIFIED IDEOGRAPH-20000", "\U00020000")
00094         self.checkletter("CJK UNIFIED IDEOGRAPH-2A6D6", "\U0002a6d6")
00095         self.checkletter("CJK UNIFIED IDEOGRAPH-2A700", "\U0002A700")
00096         self.checkletter("CJK UNIFIED IDEOGRAPH-2B734", "\U0002B734")
00097         self.checkletter("CJK UNIFIED IDEOGRAPH-2B740", "\U0002B740")
00098         self.checkletter("CJK UNIFIED IDEOGRAPH-2B81D", "\U0002B81D")

Here is the call graph for this function:

Definition at line 115 of file test_ucn.py.

00115 
00116     def test_errors(self):
00117         import unicodedata
00118         self.assertRaises(TypeError, unicodedata.name)
00119         self.assertRaises(TypeError, unicodedata.name, 'xx')
00120         self.assertRaises(TypeError, unicodedata.lookup)
00121         self.assertRaises(KeyError, unicodedata.lookup, 'unknown')

Here is the call graph for this function:

Definition at line 24 of file test_ucn.py.

00024 
00025     def test_general(self):
00026         # General and case insensitivity test:
00027         chars = [
00028             "LATIN CAPITAL LETTER T",
00029             "LATIN SMALL LETTER H",
00030             "LATIN SMALL LETTER E",
00031             "SPACE",
00032             "LATIN SMALL LETTER R",
00033             "LATIN CAPITAL LETTER E",
00034             "LATIN SMALL LETTER D",
00035             "SPACE",
00036             "LATIN SMALL LETTER f",
00037             "LATIN CAPITAL LeTtEr o",
00038             "LATIN SMaLl LETTER x",
00039             "SPACE",
00040             "LATIN SMALL LETTER A",
00041             "LATIN SMALL LETTER T",
00042             "LATIN SMALL LETTER E",
00043             "SPACE",
00044             "LATIN SMALL LETTER T",
00045             "LATIN SMALL LETTER H",
00046             "LATIN SMALL LETTER E",
00047             "SpAcE",
00048             "LATIN SMALL LETTER S",
00049             "LATIN SMALL LETTER H",
00050             "LATIN small LETTER e",
00051             "LATIN small LETTER e",
00052             "LATIN SMALL LETTER P",
00053             "FULL STOP"
00054         ]
00055         string = "The rEd fOx ate the sheep."
00056 
00057         self.assertEqual(
00058             "".join([self.checkletter(*args) for args in zip(chars, string)]),
00059             string
00060         )

Here is the call graph for this function:

Definition at line 69 of file test_ucn.py.

00069 
00070     def test_hangul_syllables(self):
00071         self.checkletter("HANGUL SYLLABLE GA", "\uac00")
00072         self.checkletter("HANGUL SYLLABLE GGWEOSS", "\uafe8")
00073         self.checkletter("HANGUL SYLLABLE DOLS", "\ub3d0")
00074         self.checkletter("HANGUL SYLLABLE RYAN", "\ub7b8")
00075         self.checkletter("HANGUL SYLLABLE MWIK", "\ubba0")
00076         self.checkletter("HANGUL SYLLABLE BBWAEM", "\ubf88")
00077         self.checkletter("HANGUL SYLLABLE SSEOL", "\uc370")
00078         self.checkletter("HANGUL SYLLABLE YI", "\uc758")
00079         self.checkletter("HANGUL SYLLABLE JJYOSS", "\ucb40")
00080         self.checkletter("HANGUL SYLLABLE KYEOLS", "\ucf28")
00081         self.checkletter("HANGUL SYLLABLE PAN", "\ud310")
00082         self.checkletter("HANGUL SYLLABLE HWEOK", "\ud6f8")
00083         self.checkletter("HANGUL SYLLABLE HIH", "\ud7a3")
00084 
00085         import unicodedata
00086         self.assertRaises(ValueError, unicodedata.name, "\ud7a4")

Here is the call graph for this function:

Definition at line 109 of file test_ucn.py.

00109 
00110     def test_misc_symbols(self):
00111         self.checkletter("PILCROW SIGN", "\u00b6")
00112         self.checkletter("REPLACEMENT CHARACTER", "\uFFFD")
00113         self.checkletter("HALFWIDTH KATAKANA SEMI-VOICED SOUND MARK", "\uFF9F")
00114         self.checkletter("FULLWIDTH LATIN SMALL LETTER A", "\uFF41")

Here is the call graph for this function:

Definition at line 122 of file test_ucn.py.

00122 
00123     def test_strict_error_handling(self):
00124         # bogus character name
00125         self.assertRaises(
00126             UnicodeError,
00127             str, b"\\N{blah}", 'unicode-escape', 'strict'
00128         )
00129         # long bogus character name
00130         self.assertRaises(
00131             UnicodeError,
00132             str, bytes("\\N{%s}" % ("x" * 100000), "ascii"), 'unicode-escape', 'strict'
00133         )
00134         # missing closing brace
00135         self.assertRaises(
00136             UnicodeError,
00137             str, b"\\N{SPACE", 'unicode-escape', 'strict'
00138         )
00139         # missing opening brace
00140         self.assertRaises(
00141             UnicodeError,
00142             str, b"\\NSPACE", 'unicode-escape', 'strict'
00143         )

Here is the call graph for this function:


The documentation for this class was generated from the following file: