1try:
2    extra_coverage
3except NameError:
4    print("SKIP")
5    raise SystemExit
6
7import uerrno
8import uio
9
10data = extra_coverage()
11
12# test hashing of str/bytes that have an invalid hash
13print(data[0], data[1])
14print(hash(data[0]))
15print(hash(data[1]))
16print(hash(bytes(data[0], "utf8")))
17print(hash(str(data[1], "utf8")))
18
19# test streams
20stream = data[2]  # has set_error and set_buf. Write always returns error
21stream.set_error(uerrno.EAGAIN)  # non-blocking error
22print(stream.read())  # read all encounters non-blocking error
23print(stream.read(1))  # read 1 byte encounters non-blocking error
24print(stream.readline())  # readline encounters non-blocking error
25print(stream.readinto(bytearray(10)))  # readinto encounters non-blocking error
26print(stream.write(b"1"))  # write encounters non-blocking error
27print(stream.write1(b"1"))  # write1 encounters non-blocking error
28stream.set_buf(b"123")
29print(stream.read(4))  # read encounters non-blocking error after successful reads
30stream.set_buf(b"123")
31print(stream.read1(4))  # read1 encounters non-blocking error after successful reads
32stream.set_buf(b"123")
33print(stream.readline(4))  # readline encounters non-blocking error after successful reads
34try:
35    print(stream.ioctl(0, 0))  # ioctl encounters non-blocking error; raises OSError
36except OSError:
37    print("OSError")
38stream.set_error(0)
39print(stream.ioctl(0, bytearray(10)))  # successful ioctl call
40
41stream2 = data[3]  # is textio
42print(stream2.read(1))  # read 1 byte encounters non-blocking error with textio stream
43
44# test BufferedWriter with stream errors
45stream.set_error(uerrno.EAGAIN)
46buf = uio.BufferedWriter(stream, 8)
47print(buf.write(bytearray(16)))
48
49# function defined in C++ code
50print("cpp", extra_cpp_coverage())
51
52# test user C module
53import cexample
54
55print(cexample.add_ints(3, 2))
56
57# test user C module mixed with C++ code
58import cppexample
59
60print(cppexample.cppfunc(1, 2))
61
62# test basic import of frozen scripts
63import frzstr1
64
65print(frzstr1.__file__)
66import frzmpy1
67
68print(frzmpy1.__file__)
69
70# test import of frozen packages with __init__.py
71import frzstr_pkg1
72
73print(frzstr_pkg1.__file__, frzstr_pkg1.x)
74import frzmpy_pkg1
75
76print(frzmpy_pkg1.__file__, frzmpy_pkg1.x)
77
78# test import of frozen packages without __init__.py
79from frzstr_pkg2.mod import Foo
80
81print(Foo.x)
82from frzmpy_pkg2.mod import Foo
83
84print(Foo.x)
85
86# test raising exception in frozen script
87try:
88    import frzmpy2
89except ZeroDivisionError:
90    print("ZeroDivisionError")
91
92# test loading a resource from a frozen string
93import uio
94
95buf = uio.resource_stream("frzstr_pkg2", "mod.py")
96print(buf.read(21))
97
98# test for MP_QSTR_NULL regression
99from frzqstr import returns_NULL
100
101print(returns_NULL())
102