ยปCore Development>Code coverage>Lib/test/test_stringprep.py

Python code coverage for Lib/test/test_stringprep.py

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