File: test_unicode.py

package info (click to toggle)
serpent 1.42-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 704 kB
  • sloc: java: 4,025; cs: 3,675; python: 1,734; xml: 149; makefile: 38; sh: 11
file content (48 lines) | stat: -rw-r--r-- 1,356 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import sys
import serpent
import platform

teststrings = [
    u"",
    u"abc",
    u"\u20ac",
    u"\x00\x01\x80\x81\xfe\xff\u20ac\u4444\u0240slashu:\\uend.\\u20ac(no euro!)\\U00022001bigone"
]

large = u"".join(chr(i) for i in range(256))
teststrings.append(large)
large = u"".join(chr(i) for i in range(0x20ac+1))
teststrings.append(large)


def main():
    impl=platform.python_implementation()+"_{0}_{1}".format(sys.version_info[0], sys.version_info[1])
    print("IMPL:", impl)

    with open("data_inputs_utf8.txt", "wb") as out:
        for source in teststrings:
            out.write(source.encode("utf-8")+b"\n")

    results = []
    ser = serpent.Serializer()
    with open("data_"+impl+".serpent", "wb") as out:
        for i, source in enumerate(teststrings):
            data = ser.serialize(source)
            out.write(data)
            out.write(b"~\n~\n")
            assert b"\x00" not in data
            results.append(data)

    assert len(results)==len(teststrings)
    for i, source in enumerate(teststrings):
        print(i)
        result = serpent.loads(results[i])
        if source!=result:
            print("ERRROR!!! RESULT AFTER serpent.loads IS NOT CORRECT!")
            print("SOURCE:",repr(source))
            print("RESULT:",repr(result))
            return
    print("OK")

if __name__ == "__main__":
    main()