test_block_3.py 826 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import gc
  2. import lz4.block
  3. import pytest
  4. test_data = [
  5. (b'a' * 1024 * 1024),
  6. ]
  7. @pytest.fixture(
  8. params=test_data,
  9. ids=[
  10. 'data' + str(i) for i in range(len(test_data))
  11. ]
  12. )
  13. def data(request):
  14. return request.param
  15. def test_block_decompress_mem_usage(data):
  16. tracemalloc = pytest.importorskip('tracemalloc')
  17. tracemalloc.start()
  18. compressed = lz4.block.compress(data)
  19. prev_snapshot = None
  20. for i in range(1000):
  21. decompressed = lz4.block.decompress(compressed) # noqa: F841
  22. if i % 100 == 0:
  23. gc.collect()
  24. snapshot = tracemalloc.take_snapshot()
  25. if prev_snapshot:
  26. stats = snapshot.compare_to(prev_snapshot, 'lineno')
  27. assert stats[0].size_diff < (1024 * 8)
  28. prev_snapshot = snapshot