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