PageRenderTime 122ms CodeModel.GetById 80ms app.highlight 7ms RepoModel.GetById 24ms app.codeStats 0ms

/Lib/test/test_stringprep.py

http://unladen-swallow.googlecode.com/
Python | 96 lines | 47 code | 26 blank | 23 comment | 1 complexity | 23790c85afeb56ef10cea835d3919343 MD5 | raw file
 1# To fully test this module, we would need a copy of the stringprep tables.
 2# Since we don't have them, this test checks only a few codepoints.
 3
 4import unittest
 5from test import test_support
 6
 7from stringprep import *
 8
 9class StringprepTests(unittest.TestCase):
10    def test(self):
11        self.failUnless(in_table_a1(u"\u0221"))
12        self.failIf(in_table_a1(u"\u0222"))
13
14        self.failUnless(in_table_b1(u"\u00ad"))
15        self.failIf(in_table_b1(u"\u00ae"))
16
17        self.failUnless(map_table_b2(u"\u0041"), u"\u0061")
18        self.failUnless(map_table_b2(u"\u0061"), u"\u0061")
19
20        self.failUnless(map_table_b3(u"\u0041"), u"\u0061")
21        self.failUnless(map_table_b3(u"\u0061"), u"\u0061")
22
23        self.failUnless(in_table_c11(u"\u0020"))
24        self.failIf(in_table_c11(u"\u0021"))
25
26        self.failUnless(in_table_c12(u"\u00a0"))
27        self.failIf(in_table_c12(u"\u00a1"))
28
29        self.failUnless(in_table_c12(u"\u00a0"))
30        self.failIf(in_table_c12(u"\u00a1"))
31
32        self.failUnless(in_table_c11_c12(u"\u00a0"))
33        self.failIf(in_table_c11_c12(u"\u00a1"))
34
35        self.failUnless(in_table_c21(u"\u001f"))
36        self.failIf(in_table_c21(u"\u0020"))
37
38        self.failUnless(in_table_c22(u"\u009f"))
39        self.failIf(in_table_c22(u"\u00a0"))
40
41        self.failUnless(in_table_c21_c22(u"\u009f"))
42        self.failIf(in_table_c21_c22(u"\u00a0"))
43
44        self.failUnless(in_table_c3(u"\ue000"))
45        self.failIf(in_table_c3(u"\uf900"))
46
47        self.failUnless(in_table_c4(u"\uffff"))
48        self.failIf(in_table_c4(u"\u0000"))
49
50        self.failUnless(in_table_c5(u"\ud800"))
51        self.failIf(in_table_c5(u"\ud7ff"))
52
53        self.failUnless(in_table_c6(u"\ufff9"))
54        self.failIf(in_table_c6(u"\ufffe"))
55
56        self.failUnless(in_table_c7(u"\u2ff0"))
57        self.failIf(in_table_c7(u"\u2ffc"))
58
59        self.failUnless(in_table_c8(u"\u0340"))
60        self.failIf(in_table_c8(u"\u0342"))
61
62        # C.9 is not in the bmp
63        # self.failUnless(in_table_c9(u"\U000E0001"))
64        # self.failIf(in_table_c8(u"\U000E0002"))
65
66        self.failUnless(in_table_d1(u"\u05be"))
67        self.failIf(in_table_d1(u"\u05bf"))
68
69        self.failUnless(in_table_d2(u"\u0041"))
70        self.failIf(in_table_d2(u"\u0040"))
71
72        # This would generate a hash of all predicates. However, running
73        # it is quite expensive, and only serves to detect changes in the
74        # unicode database. Instead, stringprep.py asserts the version of
75        # the database.
76
77        # import hashlib
78        # predicates = [k for k in dir(stringprep) if k.startswith("in_table")]
79        # predicates.sort()
80        # for p in predicates:
81        #     f = getattr(stringprep, p)
82        #     # Collect all BMP code points
83        #     data = ["0"] * 0x10000
84        #     for i in range(0x10000):
85        #         if f(unichr(i)):
86        #             data[i] = "1"
87        #     data = "".join(data)
88        #     h = hashlib.sha1()
89        #     h.update(data)
90        #     print p, h.hexdigest()
91
92def test_main():
93    test_support.run_unittest(StringprepTests)
94
95if __name__ == '__main__':
96    test_main()