annotate Lib/test/test_stringprep.py @ 51749:1408feec0084 3.0

Merged revisions 69798 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/py3k ................ r69798 | benjamin.peterson | 2009-02-19 22:02:38 -0600 (Thu, 19 Feb 2009) | 13 lines Merged revisions 69769,69776 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r69769 | georg.brandl | 2009-02-19 02:30:06 -0600 (Thu, 19 Feb 2009) | 1 line #5310, #3558: fix operator precedence table. ........ r69776 | georg.brandl | 2009-02-19 10:34:51 -0600 (Thu, 19 Feb 2009) | 2 lines #5317: update IronPython URL. ........ ................
author Benjamin Peterson <benjamin@python.org>
date Fri, 20 Feb 2009 04:05:32 +0000
parents 9c930a32cebb
children 0bb232078b8c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28692
06d137a427e9 New file.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1 # To fully test this module, we would need a copy of the stringprep tables.
06d137a427e9 New file.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
2 # Since we don't have them, this test checks only a few codepoints.
06d137a427e9 New file.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
3
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
4 import unittest
47201
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 41575
diff changeset
5 from test import support
28692
06d137a427e9 New file.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
6
06d137a427e9 New file.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
7 from stringprep import *
06d137a427e9 New file.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
8
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
9 class StringprepTests(unittest.TestCase):
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
10 def test(self):
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
11 self.failUnless(in_table_a1("\u0221"))
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
12 self.failIf(in_table_a1("\u0222"))
28692
06d137a427e9 New file.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
13
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
14 self.failUnless(in_table_b1("\u00ad"))
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
15 self.failIf(in_table_b1("\u00ae"))
28692
06d137a427e9 New file.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
16
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
17 self.failUnless(map_table_b2("\u0041"), "\u0061")
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
18 self.failUnless(map_table_b2("\u0061"), "\u0061")
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
19
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
20 self.failUnless(map_table_b3("\u0041"), "\u0061")
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
21 self.failUnless(map_table_b3("\u0061"), "\u0061")
28692
06d137a427e9 New file.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
22
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
23 self.failUnless(in_table_c11("\u0020"))
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
24 self.failIf(in_table_c11("\u0021"))
28692
06d137a427e9 New file.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
25
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
26 self.failUnless(in_table_c12("\u00a0"))
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
27 self.failIf(in_table_c12("\u00a1"))
28692
06d137a427e9 New file.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
28
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
29 self.failUnless(in_table_c12("\u00a0"))
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
30 self.failIf(in_table_c12("\u00a1"))
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
31
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
32 self.failUnless(in_table_c11_c12("\u00a0"))
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
33 self.failIf(in_table_c11_c12("\u00a1"))
28692
06d137a427e9 New file.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
34
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
35 self.failUnless(in_table_c21("\u001f"))
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
36 self.failIf(in_table_c21("\u0020"))
28692
06d137a427e9 New file.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
37
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
38 self.failUnless(in_table_c22("\u009f"))
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
39 self.failIf(in_table_c22("\u00a0"))
28692
06d137a427e9 New file.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
40
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
41 self.failUnless(in_table_c21_c22("\u009f"))
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
42 self.failIf(in_table_c21_c22("\u00a0"))
28692
06d137a427e9 New file.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
43
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
44 self.failUnless(in_table_c3("\ue000"))
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
45 self.failIf(in_table_c3("\uf900"))
28692
06d137a427e9 New file.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
46
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
47 self.failUnless(in_table_c4("\uffff"))
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
48 self.failIf(in_table_c4("\u0000"))
28692
06d137a427e9 New file.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
49
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
50 self.failUnless(in_table_c5("\ud800"))
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
51 self.failIf(in_table_c5("\ud7ff"))
28692
06d137a427e9 New file.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
52
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
53 self.failUnless(in_table_c6("\ufff9"))
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
54 self.failIf(in_table_c6("\ufffe"))
28692
06d137a427e9 New file.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
55
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
56 self.failUnless(in_table_c7("\u2ff0"))
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
57 self.failIf(in_table_c7("\u2ffc"))
28692
06d137a427e9 New file.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
58
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
59 self.failUnless(in_table_c8("\u0340"))
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
60 self.failIf(in_table_c8("\u0342"))
28692
06d137a427e9 New file.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
61
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
62 # C.9 is not in the bmp
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
63 # self.failUnless(in_table_c9(u"\U000E0001"))
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
64 # self.failIf(in_table_c8(u"\U000E0002"))
28692
06d137a427e9 New file.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
65
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
66 self.failUnless(in_table_d1("\u05be"))
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
67 self.failIf(in_table_d1("\u05bf"))
28692
06d137a427e9 New file.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
68
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
69 self.failUnless(in_table_d2("\u0041"))
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
70 self.failIf(in_table_d2("\u0040"))
28692
06d137a427e9 New file.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
71
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
72 # This would generate a hash of all predicates. However, running
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
73 # it is quite expensive, and only serves to detect changes in the
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
74 # unicode database. Instead, stringprep.py asserts the version of
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
75 # the database.
28692
06d137a427e9 New file.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
76
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
77 # import hashlib
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
78 # predicates = [k for k in dir(stringprep) if k.startswith("in_table")]
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
79 # predicates.sort()
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
80 # for p in predicates:
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
81 # f = getattr(stringprep, p)
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
82 # # Collect all BMP code points
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
83 # data = ["0"] * 0x10000
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
84 # for i in range(0x10000):
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
85 # if f(unichr(i)):
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
86 # data[i] = "1"
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
87 # data = "".join(data)
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
88 # h = hashlib.sha1()
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
89 # h.update(data)
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
90 # print p, h.hexdigest()
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
91
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
92 def test_main():
47201
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 41575
diff changeset
93 support.run_unittest(StringprepTests)
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
94
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
95 if __name__ == '__main__':
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
96 test_main()