annotate Lib/test/test_unicodedata.py @ 78069:a8aa77458e12 3.2

Add c_size_t and c_ssize_t to the ctypes summary table.
author Antoine Pitrou <solipsis@pitrou.net>
date Thu, 12 Jul 2012 20:31:50 +0200
parents 3c9232a684ae
children 9f41acdb3150
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 """ Test script for the unicodedata module.
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
14875
17b5c43c08a6 Added test suite for the complete Unicode database. The test previously
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
3 Written by Marc-Andre Lemburg (mal@lemburg.com).
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
14875
17b5c43c08a6 Added test suite for the complete Unicode database. The test previously
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
5 (c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
49797
f403d94157b2 Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49125
diff changeset
7 """
f403d94157b2 Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49125
diff changeset
8
f403d94157b2 Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49125
diff changeset
9 import sys
f403d94157b2 Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49125
diff changeset
10 import unittest
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36924
diff changeset
11 import hashlib
49797
f403d94157b2 Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49125
diff changeset
12 import subprocess
f403d94157b2 Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49125
diff changeset
13 import test.support
14875
17b5c43c08a6 Added test suite for the complete Unicode database. The test previously
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
14
14896
ad98c136475e Fixed encoding to use an endianness independent format.
Marc-André Lemburg <mal@egenix.com>
parents: 14875
diff changeset
15 encoding = 'utf-8'
53967
41c09e142bd0 Rename the surrogates handler to surrogatepass.
Martin v. Löwis <martin@v.loewis.de>
parents: 53681
diff changeset
16 errors = 'surrogatepass'
14896
ad98c136475e Fixed encoding to use an endianness independent format.
Marc-André Lemburg <mal@egenix.com>
parents: 14875
diff changeset
17
14875
17b5c43c08a6 Added test suite for the complete Unicode database. The test previously
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
18
17b5c43c08a6 Added test suite for the complete Unicode database. The test previously
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
19 ### Run tests
17b5c43c08a6 Added test suite for the complete Unicode database. The test previously
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
20
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
21 class UnicodeMethodsTest(unittest.TestCase):
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
22
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
23 # update this, if the database changes
65217
cbde81ef4af7 Upgrade to Unicode 6.0.0.
Martin v. Löwis <martin@v.loewis.de>
parents: 64153
diff changeset
24 expectedchecksum = '21b90f1aed00081b81ca7942b22196af090015a0'
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
25
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
26 def test_method_checksum(self):
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36924
diff changeset
27 h = hashlib.sha1()
60086
bf3c48f2417c Merged revisions 79494,79496 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59719
diff changeset
28 for i in range(0x10000):
41585
825d966338ea Rename 'unicode' to 'str' in its tp_name field. Rename 'str' to 'str8'.
Guido van Rossum <guido@python.org>
parents: 41575
diff changeset
29 char = chr(i)
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
30 data = [
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
31 # Predicates (single char)
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
32 "01"[char.isalnum()],
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
33 "01"[char.isalpha()],
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
34 "01"[char.isdecimal()],
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
35 "01"[char.isdigit()],
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
36 "01"[char.islower()],
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
37 "01"[char.isnumeric()],
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
38 "01"[char.isspace()],
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
39 "01"[char.istitle()],
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
40 "01"[char.isupper()],
14875
17b5c43c08a6 Added test suite for the complete Unicode database. The test previously
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
41
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
42 # Predicates (multiple chars)
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
43 "01"[(char + 'abc').isalnum()],
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
44 "01"[(char + 'abc').isalpha()],
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
45 "01"[(char + '123').isdecimal()],
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
46 "01"[(char + '123').isdigit()],
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
47 "01"[(char + 'abc').islower()],
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
48 "01"[(char + '123').isnumeric()],
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
49 "01"[(char + ' \t').isspace()],
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
50 "01"[(char + 'abc').istitle()],
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
51 "01"[(char + 'ABC').isupper()],
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
52
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
53 # Mappings (single char)
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
54 char.lower(),
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
55 char.upper(),
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
56 char.title(),
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
57
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
58 # Mappings (multiple chars)
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
59 (char + 'abc').lower(),
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
60 (char + 'ABC').upper(),
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
61 (char + 'abc').title(),
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
62 (char + 'ABC').title(),
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents:
diff changeset
63
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
64 ]
53681
52a77ef069cd Issue #3672: Reject surrogates in utf-8 codec; add surrogates error
Martin v. Löwis <martin@v.loewis.de>
parents: 53476
diff changeset
65 h.update(''.join(data).encode(encoding, errors))
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
66 result = h.hexdigest()
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
67 self.assertEqual(result, self.expectedchecksum)
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
68
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
69 class UnicodeDatabaseTest(unittest.TestCase):
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
70
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
71 def setUp(self):
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
72 # In case unicodedata is not available, this will raise an ImportError,
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
73 # but the other test cases will still be run
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
74 import unicodedata
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
75 self.db = unicodedata
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
76
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
77 def tearDown(self):
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
78 del self.db
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
79
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
80 class UnicodeFunctionsTest(UnicodeDatabaseTest):
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
81
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
82 # update this, if the database changes
65217
cbde81ef4af7 Upgrade to Unicode 6.0.0.
Martin v. Löwis <martin@v.loewis.de>
parents: 64153
diff changeset
83 expectedchecksum = 'c23dfc0b5eaf3ca2aad32d733de96bb182ccda50'
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
84 def test_function_checksum(self):
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
85 data = []
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36924
diff changeset
86 h = hashlib.sha1()
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents:
diff changeset
87
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
88 for i in range(0x10000):
41585
825d966338ea Rename 'unicode' to 'str' in its tp_name field. Rename 'str' to 'str8'.
Guido van Rossum <guido@python.org>
parents: 41575
diff changeset
89 char = chr(i)
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
90 data = [
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
91 # Properties
63750
eafe07d40eb7 Issue #9337: Make float.__str__ identical to float.__repr__.
Mark Dickinson <dickinsm@gmail.com>
parents: 60086
diff changeset
92 format(self.db.digit(char, -1), '.12g'),
eafe07d40eb7 Issue #9337: Make float.__str__ identical to float.__repr__.
Mark Dickinson <dickinsm@gmail.com>
parents: 60086
diff changeset
93 format(self.db.numeric(char, -1), '.12g'),
eafe07d40eb7 Issue #9337: Make float.__str__ identical to float.__repr__.
Mark Dickinson <dickinsm@gmail.com>
parents: 60086
diff changeset
94 format(self.db.decimal(char, -1), '.12g'),
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
95 self.db.category(char),
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
96 self.db.bidirectional(char),
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
97 self.db.decomposition(char),
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
98 str(self.db.mirrored(char)),
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
99 str(self.db.combining(char)),
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
100 ]
42907
0170418dadea Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42466
diff changeset
101 h.update(''.join(data).encode("ascii"))
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
102 result = h.hexdigest()
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
103 self.assertEqual(result, self.expectedchecksum)
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents:
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: 24364
diff changeset
105 def test_digit(self):
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
106 self.assertEqual(self.db.digit('A', None), None)
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
107 self.assertEqual(self.db.digit('9'), 9)
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
108 self.assertEqual(self.db.digit('\u215b', None), None)
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
109 self.assertEqual(self.db.digit('\u2468'), 9)
47458
e4a186437440 Change all functions that expect one unicode character to accept a pair of
Walter Dörwald <walter@livinglogic.de>
parents: 47201
diff changeset
110 self.assertEqual(self.db.digit('\U00020000', None), None)
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
111
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
112 self.assertRaises(TypeError, self.db.digit)
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
113 self.assertRaises(TypeError, self.db.digit, 'xx')
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
114 self.assertRaises(ValueError, self.db.digit, 'x')
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents:
diff changeset
115
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
116 def test_numeric(self):
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
117 self.assertEqual(self.db.numeric('A',None), None)
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
118 self.assertEqual(self.db.numeric('9'), 9)
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
119 self.assertEqual(self.db.numeric('\u215b'), 0.125)
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
120 self.assertEqual(self.db.numeric('\u2468'), 9.0)
56408
6c91d1803182 Merged revisions 75272-75273 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 55593
diff changeset
121 self.assertEqual(self.db.numeric('\ua627'), 7.0)
47458
e4a186437440 Change all functions that expect one unicode character to accept a pair of
Walter Dörwald <walter@livinglogic.de>
parents: 47201
diff changeset
122 self.assertEqual(self.db.numeric('\U00020000', None), None)
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
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: 24364
diff changeset
124 self.assertRaises(TypeError, self.db.numeric)
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
125 self.assertRaises(TypeError, self.db.numeric, 'xx')
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
126 self.assertRaises(ValueError, self.db.numeric, 'x')
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
127
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
128 def test_decimal(self):
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
129 self.assertEqual(self.db.decimal('A',None), None)
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
130 self.assertEqual(self.db.decimal('9'), 9)
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
131 self.assertEqual(self.db.decimal('\u215b', None), None)
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
132 self.assertEqual(self.db.decimal('\u2468', None), None)
47458
e4a186437440 Change all functions that expect one unicode character to accept a pair of
Walter Dörwald <walter@livinglogic.de>
parents: 47201
diff changeset
133 self.assertEqual(self.db.decimal('\U00020000', None), None)
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
134
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
135 self.assertRaises(TypeError, self.db.decimal)
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
136 self.assertRaises(TypeError, self.db.decimal, 'xx')
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
137 self.assertRaises(ValueError, self.db.decimal, 'x')
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
138
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
139 def test_category(self):
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
140 self.assertEqual(self.db.category('\uFFFE'), 'Cn')
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
141 self.assertEqual(self.db.category('a'), 'Ll')
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
142 self.assertEqual(self.db.category('A'), 'Lu')
47458
e4a186437440 Change all functions that expect one unicode character to accept a pair of
Walter Dörwald <walter@livinglogic.de>
parents: 47201
diff changeset
143 self.assertEqual(self.db.category('\U00020000'), 'Lo')
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents:
diff changeset
144
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
145 self.assertRaises(TypeError, self.db.category)
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
146 self.assertRaises(TypeError, self.db.category, 'xx')
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
147
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
148 def test_bidirectional(self):
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
149 self.assertEqual(self.db.bidirectional('\uFFFE'), '')
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
150 self.assertEqual(self.db.bidirectional(' '), 'WS')
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
151 self.assertEqual(self.db.bidirectional('A'), 'L')
47458
e4a186437440 Change all functions that expect one unicode character to accept a pair of
Walter Dörwald <walter@livinglogic.de>
parents: 47201
diff changeset
152 self.assertEqual(self.db.bidirectional('\U00020000'), 'L')
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
153
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
154 self.assertRaises(TypeError, self.db.bidirectional)
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
155 self.assertRaises(TypeError, self.db.bidirectional, 'xx')
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents:
diff changeset
156
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
157 def test_decomposition(self):
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
158 self.assertEqual(self.db.decomposition('\uFFFE'),'')
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
159 self.assertEqual(self.db.decomposition('\u00bc'), '<fraction> 0031 2044 0034')
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
160
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
161 self.assertRaises(TypeError, self.db.decomposition)
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
162 self.assertRaises(TypeError, self.db.decomposition, 'xx')
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
163
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
164 def test_mirrored(self):
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
165 self.assertEqual(self.db.mirrored('\uFFFE'), 0)
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
166 self.assertEqual(self.db.mirrored('a'), 0)
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
167 self.assertEqual(self.db.mirrored('\u2201'), 1)
47458
e4a186437440 Change all functions that expect one unicode character to accept a pair of
Walter Dörwald <walter@livinglogic.de>
parents: 47201
diff changeset
168 self.assertEqual(self.db.mirrored('\U00020000'), 0)
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
169
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
170 self.assertRaises(TypeError, self.db.mirrored)
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
171 self.assertRaises(TypeError, self.db.mirrored, 'xx')
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents:
diff changeset
172
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
173 def test_combining(self):
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
174 self.assertEqual(self.db.combining('\uFFFE'), 0)
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
175 self.assertEqual(self.db.combining('a'), 0)
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
176 self.assertEqual(self.db.combining('\u20e1'), 230)
47458
e4a186437440 Change all functions that expect one unicode character to accept a pair of
Walter Dörwald <walter@livinglogic.de>
parents: 47201
diff changeset
177 self.assertEqual(self.db.combining('\U00020000'), 0)
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
178
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
179 self.assertRaises(TypeError, self.db.combining)
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
180 self.assertRaises(TypeError, self.db.combining, 'xx')
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
181
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
182 def test_normalize(self):
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
183 self.assertRaises(TypeError, self.db.normalize)
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
184 self.assertRaises(ValueError, self.db.normalize, 'unknown', 'xx')
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
185 self.assertEqual(self.db.normalize('NFKC', ''), '')
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
186 # The rest can be found in test_normalization.py
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
187 # which requires an external file.
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
188
59325
fd8fdd388963 Merged revisions 78647 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 55593
diff changeset
189 def test_pr29(self):
fd8fdd388963 Merged revisions 78647 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 55593
diff changeset
190 # http://www.unicode.org/review/pr-29.html
67184
a4ec20cc9066 Merged revisions 87442 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 66340
diff changeset
191 # See issues #1054943 and #10254.
a4ec20cc9066 Merged revisions 87442 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 66340
diff changeset
192 composed = ("\u0b47\u0300\u0b3e", "\u1100\u0300\u1161",
a4ec20cc9066 Merged revisions 87442 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 66340
diff changeset
193 'Li\u030dt-s\u1e73\u0301',
a4ec20cc9066 Merged revisions 87442 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 66340
diff changeset
194 '\u092e\u093e\u0930\u094d\u0915 \u091c\u093c'
a4ec20cc9066 Merged revisions 87442 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 66340
diff changeset
195 + '\u0941\u0915\u0947\u0930\u092c\u0930\u094d\u0917',
a4ec20cc9066 Merged revisions 87442 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 66340
diff changeset
196 '\u0915\u093f\u0930\u094d\u0917\u093f\u091c\u093c'
a4ec20cc9066 Merged revisions 87442 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 66340
diff changeset
197 + '\u0938\u094d\u0924\u093e\u0928')
a4ec20cc9066 Merged revisions 87442 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 66340
diff changeset
198 for text in composed:
59325
fd8fdd388963 Merged revisions 78647 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 55593
diff changeset
199 self.assertEqual(self.db.normalize('NFC', text), text)
fd8fdd388963 Merged revisions 78647 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 55593
diff changeset
200
67184
a4ec20cc9066 Merged revisions 87442 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 66340
diff changeset
201 def test_issue10254(self):
a4ec20cc9066 Merged revisions 87442 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 66340
diff changeset
202 # Crash reported in #10254
a4ec20cc9066 Merged revisions 87442 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 66340
diff changeset
203 a = 'C\u0338' * 20 + 'C\u0327'
a4ec20cc9066 Merged revisions 87442 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 66340
diff changeset
204 b = 'C\u0338' * 20 + '\xC7'
a4ec20cc9066 Merged revisions 87442 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 66340
diff changeset
205 self.assertEqual(self.db.normalize('NFC', a), b)
a4ec20cc9066 Merged revisions 87442 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 66340
diff changeset
206
32951
024ff0ab4588 SF #989185: Drop unicode.iswide() and unicode.width() and add
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31930
diff changeset
207 def test_east_asian_width(self):
024ff0ab4588 SF #989185: Drop unicode.iswide() and unicode.width() and add
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31930
diff changeset
208 eaw = self.db.east_asian_width
43777
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43664
diff changeset
209 self.assertRaises(TypeError, eaw, b'a')
43947
cbc8b3bd3157 Rename buffer -> bytearray.
Guido van Rossum <guido@python.org>
parents: 43777
diff changeset
210 self.assertRaises(TypeError, eaw, bytearray())
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
211 self.assertRaises(TypeError, eaw, '')
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
212 self.assertRaises(TypeError, eaw, 'ra')
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
213 self.assertEqual(eaw('\x1e'), 'N')
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
214 self.assertEqual(eaw('\x20'), 'Na')
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
215 self.assertEqual(eaw('\uC894'), 'W')
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
216 self.assertEqual(eaw('\uFF66'), 'H')
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
217 self.assertEqual(eaw('\uFF1F'), 'F')
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
218 self.assertEqual(eaw('\u2010'), 'A')
47458
e4a186437440 Change all functions that expect one unicode character to accept a pair of
Walter Dörwald <walter@livinglogic.de>
parents: 47201
diff changeset
219 self.assertEqual(eaw('\U00020000'), 'W')
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
220
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
221 class UnicodeMiscTest(UnicodeDatabaseTest):
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents:
diff changeset
222
49797
f403d94157b2 Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49125
diff changeset
223 def test_failed_import_during_compiling(self):
f403d94157b2 Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49125
diff changeset
224 # Issue 4367
f403d94157b2 Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49125
diff changeset
225 # Decoding \N escapes requires the unicodedata module. If it can't be
f403d94157b2 Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49125
diff changeset
226 # imported, we shouldn't segfault.
f403d94157b2 Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49125
diff changeset
227
f403d94157b2 Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49125
diff changeset
228 # This program should raise a SyntaxError in the eval.
f403d94157b2 Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49125
diff changeset
229 code = "import sys;" \
f403d94157b2 Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49125
diff changeset
230 "sys.modules['unicodedata'] = None;" \
f403d94157b2 Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49125
diff changeset
231 """eval("'\\\\N{SOFT HYPHEN}'")"""
f403d94157b2 Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49125
diff changeset
232 args = [sys.executable, "-c", code]
f403d94157b2 Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49125
diff changeset
233 # We use a subprocess because the unicodedata module may already have
f403d94157b2 Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49125
diff changeset
234 # been loaded in this process.
f403d94157b2 Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49125
diff changeset
235 popen = subprocess.Popen(args, stderr=subprocess.PIPE)
f403d94157b2 Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49125
diff changeset
236 popen.wait()
f403d94157b2 Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49125
diff changeset
237 self.assertEqual(popen.returncode, 1)
f403d94157b2 Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49125
diff changeset
238 error = "SyntaxError: (unicode error) \\N escapes not supported " \
f403d94157b2 Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49125
diff changeset
239 "(can't load unicodedata module)"
58415
f6a626f34840 use assert[Not]In where appropriate
Benjamin Peterson <benjamin@python.org>
parents: 56408
diff changeset
240 self.assertIn(error, popen.stderr.read().decode("ascii"))
65760
ef6dad7517c5 Fix resource warning in test_unicodedata. Patch by Brian Brazil.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65217
diff changeset
241 popen.stderr.close()
49797
f403d94157b2 Merged revisions 67320 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49125
diff changeset
242
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
243 def test_decimal_numeric_consistent(self):
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
244 # Test that decimal and numeric are consistent,
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
245 # i.e. if a character has a decimal value,
35276
4adbd331d335 Fix all wrong instances of "it's".
Georg Brandl <georg@python.org>
parents: 32951
diff changeset
246 # its numeric value should be the same.
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
247 count = 0
41642
a6eb6acfe04a Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41585
diff changeset
248 for i in range(0x10000):
41585
825d966338ea Rename 'unicode' to 'str' in its tp_name field. Rename 'str' to 'str8'.
Guido van Rossum <guido@python.org>
parents: 41575
diff changeset
249 c = chr(i)
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
250 dec = self.db.decimal(c, -1)
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
251 if dec != -1:
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
252 self.assertEqual(dec, self.db.numeric(c))
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
253 count += 1
55593
0bb232078b8c Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents: 53967
diff changeset
254 self.assertTrue(count >= 10) # should have tested at least the ASCII digits
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents:
diff changeset
255
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
256 def test_digit_numeric_consistent(self):
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
257 # Test that digit and numeric are consistent,
28231
4cafa5141012 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 28075
diff changeset
258 # i.e. if a character has a digit value,
35276
4adbd331d335 Fix all wrong instances of "it's".
Georg Brandl <georg@python.org>
parents: 32951
diff changeset
259 # its numeric value should be the same.
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
260 count = 0
41642
a6eb6acfe04a Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41585
diff changeset
261 for i in range(0x10000):
41585
825d966338ea Rename 'unicode' to 'str' in its tp_name field. Rename 'str' to 'str8'.
Guido van Rossum <guido@python.org>
parents: 41575
diff changeset
262 c = chr(i)
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
263 dec = self.db.digit(c, -1)
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
264 if dec != -1:
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
265 self.assertEqual(dec, self.db.numeric(c))
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
266 count += 1
55593
0bb232078b8c Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents: 53967
diff changeset
267 self.assertTrue(count >= 10) # should have tested at least the ASCII digits
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents:
diff changeset
268
42466
3fc3cedc49ca Merged revisions 56753-56781 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41837
diff changeset
269 def test_bug_1704793(self):
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 59327
diff changeset
270 self.assertEqual(self.db.lookup("GOTHIC LETTER FAIHU"), '\U00010346')
42466
3fc3cedc49ca Merged revisions 56753-56781 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41837
diff changeset
271
49125
dc60293b29d5 Merged revisions 66362 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47458
diff changeset
272 def test_ucd_510(self):
dc60293b29d5 Merged revisions 66362 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47458
diff changeset
273 import unicodedata
dc60293b29d5 Merged revisions 66362 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47458
diff changeset
274 # In UCD 5.1.0, a mirrored property changed wrt. UCD 3.2.0
55593
0bb232078b8c Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents: 53967
diff changeset
275 self.assertTrue(unicodedata.mirrored("\u0f3a"))
0bb232078b8c Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents: 53967
diff changeset
276 self.assertTrue(not unicodedata.ucd_3_2_0.mirrored("\u0f3a"))
49125
dc60293b29d5 Merged revisions 66362 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47458
diff changeset
277 # Also, we now have two ways of representing
dc60293b29d5 Merged revisions 66362 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47458
diff changeset
278 # the upper-case mapping: as delta, or as absolute value
55593
0bb232078b8c Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents: 53967
diff changeset
279 self.assertTrue("a".upper()=='A')
0bb232078b8c Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents: 53967
diff changeset
280 self.assertTrue("\u1d79".upper()=='\ua77d')
0bb232078b8c Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents: 53967
diff changeset
281 self.assertTrue(".".upper()=='.')
53402
2f8e535f9a9b Merged revisions 71896 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 49797
diff changeset
282
2f8e535f9a9b Merged revisions 71896 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 49797
diff changeset
283 def test_bug_5828(self):
2f8e535f9a9b Merged revisions 71896 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 49797
diff changeset
284 self.assertEqual("\u1d79".lower(), "\u1d79")
2f8e535f9a9b Merged revisions 71896 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 49797
diff changeset
285 # Only U+0000 should have U+0000 as its upper/lower/titlecase variant
2f8e535f9a9b Merged revisions 71896 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 49797
diff changeset
286 self.assertEqual(
2f8e535f9a9b Merged revisions 71896 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 49797
diff changeset
287 [
2f8e535f9a9b Merged revisions 71896 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 49797
diff changeset
288 c for c in range(sys.maxunicode+1)
2f8e535f9a9b Merged revisions 71896 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 49797
diff changeset
289 if "\x00" in chr(c).lower()+chr(c).upper()+chr(c).title()
2f8e535f9a9b Merged revisions 71896 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 49797
diff changeset
290 ],
2f8e535f9a9b Merged revisions 71896 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 49797
diff changeset
291 [0]
2f8e535f9a9b Merged revisions 71896 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 49797
diff changeset
292 )
2f8e535f9a9b Merged revisions 71896 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 49797
diff changeset
293
53476
951a62b86de8 Merged revisions 71974 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 53452
diff changeset
294 def test_bug_4971(self):
53452
912438655f93 Merged revisions 71949 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 53402
diff changeset
295 # LETTER DZ WITH CARON: DZ, Dz, dz
912438655f93 Merged revisions 71949 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 53402
diff changeset
296 self.assertEqual("\u01c4".title(), "\u01c5")
912438655f93 Merged revisions 71949 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 53402
diff changeset
297 self.assertEqual("\u01c5".title(), "\u01c5")
912438655f93 Merged revisions 71949 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 53402
diff changeset
298 self.assertEqual("\u01c6".title(), "\u01c5")
49125
dc60293b29d5 Merged revisions 66362 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47458
diff changeset
299
60086
bf3c48f2417c Merged revisions 79494,79496 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59719
diff changeset
300 def test_linebreak_7643(self):
bf3c48f2417c Merged revisions 79494,79496 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59719
diff changeset
301 for i in range(0x10000):
bf3c48f2417c Merged revisions 79494,79496 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59719
diff changeset
302 lines = (chr(i) + 'A').splitlines()
bf3c48f2417c Merged revisions 79494,79496 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59719
diff changeset
303 if i in (0x0a, 0x0b, 0x0c, 0x0d, 0x85,
bf3c48f2417c Merged revisions 79494,79496 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59719
diff changeset
304 0x1c, 0x1d, 0x1e, 0x2028, 0x2029):
bf3c48f2417c Merged revisions 79494,79496 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59719
diff changeset
305 self.assertEqual(len(lines), 2,
bf3c48f2417c Merged revisions 79494,79496 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59719
diff changeset
306 r"\u%.4x should be a linebreak" % i)
bf3c48f2417c Merged revisions 79494,79496 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59719
diff changeset
307 else:
bf3c48f2417c Merged revisions 79494,79496 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59719
diff changeset
308 self.assertEqual(len(lines), 1,
bf3c48f2417c Merged revisions 79494,79496 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59719
diff changeset
309 r"\u%.4x should not be a linebreak" % i)
bf3c48f2417c Merged revisions 79494,79496 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59719
diff changeset
310
64146
8f97c64b2333 #5127: Even on narrow unicode builds, the C functions that access the Unicode
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 63750
diff changeset
311 def test_UCS4(self):
8f97c64b2333 #5127: Even on narrow unicode builds, the C functions that access the Unicode
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 63750
diff changeset
312 # unicodedata should work with code points outside the BMP
8f97c64b2333 #5127: Even on narrow unicode builds, the C functions that access the Unicode
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 63750
diff changeset
313 # even on a narrow Unicode build
64150
23a598c01911 Fix stupid typo in test.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 64146
diff changeset
314 self.assertEqual(self.db.category("\U0001012A"), "No")
23a598c01911 Fix stupid typo in test.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 64146
diff changeset
315 self.assertEqual(self.db.numeric("\U0001012A"), 9000)
64153
05a3dfda04ff Add more tests to unicodedata with large code points
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 64150
diff changeset
316 self.assertEqual(self.db.decimal("\U0001D7FD"), 7)
05a3dfda04ff Add more tests to unicodedata with large code points
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 64150
diff changeset
317 self.assertEqual(self.db.digit("\U0001D7FD"), 7)
64146
8f97c64b2333 #5127: Even on narrow unicode builds, the C functions that access the Unicode
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 63750
diff changeset
318
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
319 def test_main():
47201
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 43947
diff changeset
320 test.support.run_unittest(
28917
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 28231
diff changeset
321 UnicodeMiscTest,
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 28231
diff changeset
322 UnicodeMethodsTest,
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 28231
diff changeset
323 UnicodeFunctionsTest
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 28231
diff changeset
324 )
28075
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
325
7fdcc4cfc759 Port test_ucn and test_unicodedata to PyUnit. Add a few tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
326 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: 24364
diff changeset
327 test_main()