test_frame_9.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import os
  2. import lz4.frame
  3. def test_issue_172_1():
  4. """Test reproducer for issue 172
  5. Issue 172 is a reported failure occurring on Windows 10 only. This bug was
  6. due to incorrect handling of Py_ssize_t types when doing comparisons and
  7. using them as a size when allocating memory.
  8. """
  9. input_data = 8 * os.urandom(1024)
  10. with lz4.frame.open('testfile_small', 'wb') as fp:
  11. bytes_written = fp.write(input_data) # noqa: F841
  12. with lz4.frame.open('testfile_small', 'rb') as fp:
  13. data = fp.read(10)
  14. assert len(data) == 10
  15. def test_issue_172_2():
  16. input_data = 9 * os.urandom(1024)
  17. with lz4.frame.open('testfile_small', 'w') as fp:
  18. bytes_written = fp.write(input_data) # noqa: F841
  19. with lz4.frame.open('testfile_small', 'r') as fp:
  20. data = fp.read(10)
  21. assert len(data) == 10
  22. def test_issue_172_3():
  23. input_data = 9 * os.urandom(1024)
  24. with lz4.frame.open('testfile_small', 'wb') as fp:
  25. bytes_written = fp.write(input_data) # noqa: F841
  26. with lz4.frame.open('testfile_small', 'rb') as fp:
  27. data = fp.read(10)
  28. assert len(data) == 10
  29. with lz4.frame.open('testfile_small', 'rb') as fp:
  30. data = fp.read(16 * 1024 - 1)
  31. assert len(data) == 9 * 1024
  32. assert data == input_data