extra_coverage.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. try:
  2. extra_coverage
  3. except NameError:
  4. print("SKIP")
  5. raise SystemExit
  6. import uerrno
  7. import uio
  8. data = extra_coverage()
  9. # test hashing of str/bytes that have an invalid hash
  10. print(data[0], data[1])
  11. print(hash(data[0]))
  12. print(hash(data[1]))
  13. print(hash(bytes(data[0], 'utf8')))
  14. print(hash(str(data[1], 'utf8')))
  15. # test streams
  16. stream = data[2] # has set_error and set_buf. Write always returns error
  17. stream.set_error(uerrno.EAGAIN) # non-blocking error
  18. print(stream.read()) # read all encounters non-blocking error
  19. print(stream.read(1)) # read 1 byte encounters non-blocking error
  20. print(stream.readline()) # readline encounters non-blocking error
  21. print(stream.readinto(bytearray(10))) # readinto encounters non-blocking error
  22. print(stream.write(b'1')) # write encounters non-blocking error
  23. print(stream.write1(b'1')) # write1 encounters non-blocking error
  24. stream.set_buf(b'123')
  25. print(stream.read(4)) # read encounters non-blocking error after successful reads
  26. stream.set_buf(b'123')
  27. print(stream.read1(4)) # read1 encounters non-blocking error after successful reads
  28. stream.set_buf(b'123')
  29. print(stream.readline(4)) # readline encounters non-blocking error after successful reads
  30. try:
  31. print(stream.ioctl(0, 0)) # ioctl encounters non-blocking error; raises OSError
  32. except OSError:
  33. print('OSError')
  34. stream.set_error(0)
  35. print(stream.ioctl(0, bytearray(10))) # successful ioctl call
  36. stream2 = data[3] # is textio
  37. print(stream2.read(1)) # read 1 byte encounters non-blocking error with textio stream
  38. # test BufferedWriter with stream errors
  39. stream.set_error(uerrno.EAGAIN)
  40. buf = uio.BufferedWriter(stream, 8)
  41. print(buf.write(bytearray(16)))
  42. # test basic import of frozen scripts
  43. import frzstr1
  44. import frzmpy1
  45. # test import of frozen packages with __init__.py
  46. import frzstr_pkg1
  47. print(frzstr_pkg1.x)
  48. import frzmpy_pkg1
  49. print(frzmpy_pkg1.x)
  50. # test import of frozen packages without __init__.py
  51. from frzstr_pkg2.mod import Foo
  52. print(Foo.x)
  53. from frzmpy_pkg2.mod import Foo
  54. print(Foo.x)
  55. # test raising exception in frozen script
  56. try:
  57. import frzmpy2
  58. except ZeroDivisionError:
  59. print('ZeroDivisionError')
  60. # test loading a resource from a frozen string
  61. import uio
  62. buf = uio.resource_stream('frzstr_pkg2', 'mod.py')
  63. print(buf.read(21))