PyXR

c:\python24\lib \ test \ test_stringprep.py



0001 # To fully test this module, we would need a copy of the stringprep tables.
0002 # Since we don't have them, this test checks only a few codepoints.
0003 
0004 from test.test_support import verify, vereq
0005 import sha
0006 
0007 import stringprep
0008 from stringprep import *
0009 
0010 verify(in_table_a1(u"\u0221"))
0011 verify(not in_table_a1(u"\u0222"))
0012 
0013 verify(in_table_b1(u"\u00ad"))
0014 verify(not in_table_b1(u"\u00ae"))
0015 
0016 verify(map_table_b2(u"\u0041"), u"\u0061")
0017 verify(map_table_b2(u"\u0061"), u"\u0061")
0018 
0019 verify(map_table_b3(u"\u0041"), u"\u0061")
0020 verify(map_table_b3(u"\u0061"), u"\u0061")
0021 
0022 verify(in_table_c11(u"\u0020"))
0023 verify(not in_table_c11(u"\u0021"))
0024 
0025 verify(in_table_c12(u"\u00a0"))
0026 verify(not in_table_c12(u"\u00a1"))
0027 
0028 verify(in_table_c12(u"\u00a0"))
0029 verify(not in_table_c12(u"\u00a1"))
0030 
0031 verify(in_table_c11_c12(u"\u00a0"))
0032 verify(not in_table_c11_c12(u"\u00a1"))
0033 
0034 verify(in_table_c21(u"\u001f"))
0035 verify(not in_table_c21(u"\u0020"))
0036 
0037 verify(in_table_c22(u"\u009f"))
0038 verify(not in_table_c22(u"\u00a0"))
0039 
0040 verify(in_table_c21_c22(u"\u009f"))
0041 verify(not in_table_c21_c22(u"\u00a0"))
0042 
0043 verify(in_table_c3(u"\ue000"))
0044 verify(not in_table_c3(u"\uf900"))
0045 
0046 verify(in_table_c4(u"\uffff"))
0047 verify(not in_table_c4(u"\u0000"))
0048 
0049 verify(in_table_c5(u"\ud800"))
0050 verify(not in_table_c5(u"\ud7ff"))
0051 
0052 verify(in_table_c6(u"\ufff9"))
0053 verify(not in_table_c6(u"\ufffe"))
0054 
0055 verify(in_table_c7(u"\u2ff0"))
0056 verify(not in_table_c7(u"\u2ffc"))
0057 
0058 verify(in_table_c8(u"\u0340"))
0059 verify(not in_table_c8(u"\u0342"))
0060 
0061 # C.9 is not in the bmp
0062 # verify(in_table_c9(u"\U000E0001"))
0063 # verify(not in_table_c8(u"\U000E0002"))
0064 
0065 verify(in_table_d1(u"\u05be"))
0066 verify(not in_table_d1(u"\u05bf"))
0067 
0068 verify(in_table_d2(u"\u0041"))
0069 verify(not in_table_d2(u"\u0040"))
0070 
0071 # This would generate a hash of all predicates. However, running
0072 # it is quite expensive, and only serves to detect changes in the
0073 # unicode database. Instead, stringprep.py asserts the version of
0074 # the database.
0075 
0076 # predicates = [k for k in dir(stringprep) if k.startswith("in_table")]
0077 # predicates.sort()
0078 # for p in predicates:
0079 #     f = getattr(stringprep, p)
0080 #     # Collect all BMP code points
0081 #     data = ["0"] * 0x10000
0082 #     for i in range(0x10000):
0083 #         if f(unichr(i)):
0084 #             data[i] = "1"
0085 #     data = "".join(data)
0086 #     h = sha.sha()
0087 #     h.update(data)
0088 #     print p,h.hexdigest()
0089 

Generated by PyXR 0.9.4
SourceForge.net Logo