| 1 |
import pytest |
| 2 |
import sys |
| 3 |
import lz4.stream |
| 4 |
import psutil |
| 5 |
import os |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
_4GB = 0xffffffff |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
if os.environ.get('TRAVIS') is not None or sys.maxsize < _4GB or \ |
| 24 |
psutil.virtual_memory().available < _4GB: |
| 25 |
huge = None |
| 26 |
else: |
| 27 |
try: |
| 28 |
huge = b'\0' * _4GB |
| 29 |
except (MemoryError, OverflowError): |
| 30 |
huge = None |
| 31 |
|
| 32 |
|
| 33 |
@pytest.mark.skipif( |
| 34 |
os.environ.get('TRAVIS') is not None, |
| 35 |
reason='Skipping test on Travis due to insufficient memory' |
| 36 |
) |
| 37 |
@pytest.mark.skipif( |
| 38 |
sys.maxsize < _4GB, |
| 39 |
reason='Py_ssize_t too small for this test' |
| 40 |
) |
| 41 |
@pytest.mark.skipif( |
| 42 |
psutil.virtual_memory().available < _4GB or huge is None, |
| 43 |
reason='Insufficient system memory for this test' |
| 44 |
) |
| 45 |
def test_huge_1(): |
| 46 |
data = b'' |
| 47 |
kwargs = { |
| 48 |
'strategy': "double_buffer", |
| 49 |
'buffer_size': lz4.stream.LZ4_MAX_INPUT_SIZE, |
| 50 |
'store_comp_size': 4, |
| 51 |
'dictionary': huge, |
| 52 |
} |
| 53 |
|
| 54 |
if psutil.virtual_memory().available < 3 * kwargs['buffer_size']: |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
pytest.skip('Insufficient system memory for this test') |
| 59 |
|
| 60 |
|
| 61 |
message = r'^Dictionary too large for LZ4 API$' |
| 62 |
|
| 63 |
with pytest.raises(OverflowError, match=message): |
| 64 |
with lz4.stream.LZ4StreamCompressor(**kwargs) as proc: |
| 65 |
proc.compress(data) |
| 66 |
|
| 67 |
with pytest.raises(OverflowError, match=message): |
| 68 |
with lz4.stream.LZ4StreamDecompressor(**kwargs) as proc: |
| 69 |
proc.decompress(data) |
| 70 |
|
| 71 |
|
| 72 |
@pytest.mark.skipif( |
| 73 |
os.environ.get('TRAVIS') is not None, |
| 74 |
reason='Skipping test on Travis due to insufficient memory' |
| 75 |
) |
| 76 |
@pytest.mark.skipif( |
| 77 |
sys.maxsize < 0xffffffff, |
| 78 |
reason='Py_ssize_t too small for this test' |
| 79 |
) |
| 80 |
@pytest.mark.skipif( |
| 81 |
psutil.virtual_memory().available < _4GB or huge is None, |
| 82 |
reason='Insufficient system memory for this test' |
| 83 |
) |
| 84 |
def test_huge_2(): |
| 85 |
data = huge |
| 86 |
kwargs = { |
| 87 |
'strategy': "double_buffer", |
| 88 |
'buffer_size': lz4.stream.LZ4_MAX_INPUT_SIZE, |
| 89 |
'store_comp_size': 4, |
| 90 |
'dictionary': b'', |
| 91 |
} |
| 92 |
|
| 93 |
if psutil.virtual_memory().available < 3 * kwargs['buffer_size']: |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
pytest.skip('Insufficient system memory for this test') |
| 98 |
|
| 99 |
|
| 100 |
message = r'^Input too large for LZ4 API$' |
| 101 |
|
| 102 |
with pytest.raises(OverflowError, match=message): |
| 103 |
with lz4.stream.LZ4StreamCompressor(**kwargs) as proc: |
| 104 |
proc.compress(data) |
| 105 |
|
| 106 |
|
| 107 |
with pytest.raises(lz4.stream.LZ4StreamError): |
| 108 |
with lz4.stream.LZ4StreamDecompressor(**kwargs) as proc: |
| 109 |
proc.decompress(data) |
| 110 |
|
| 111 |
|
| 112 |
@pytest.mark.skipif( |
| 113 |
os.environ.get('TRAVIS') is not None, |
| 114 |
reason='Skipping test on Travis due to insufficient memory' |
| 115 |
) |
| 116 |
@pytest.mark.skipif( |
| 117 |
sys.maxsize < 0xffffffff, |
| 118 |
reason='Py_ssize_t too small for this test' |
| 119 |
) |
| 120 |
@pytest.mark.skipif( |
| 121 |
psutil.virtual_memory().available < _4GB or huge is None, |
| 122 |
reason='Insufficient system memory for this test' |
| 123 |
) |
| 124 |
def test_huge_3(): |
| 125 |
data = huge |
| 126 |
kwargs = { |
| 127 |
'strategy': "double_buffer", |
| 128 |
'buffer_size': lz4.stream.LZ4_MAX_INPUT_SIZE, |
| 129 |
'store_comp_size': 4, |
| 130 |
'dictionary': huge, |
| 131 |
} |
| 132 |
|
| 133 |
if psutil.virtual_memory().available < 3 * kwargs['buffer_size']: |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
pytest.skip('Insufficient system memory for this test') |
| 138 |
|
| 139 |
|
| 140 |
message = r'^Dictionary too large for LZ4 API$' |
| 141 |
|
| 142 |
with pytest.raises(OverflowError, match=message): |
| 143 |
with lz4.stream.LZ4StreamCompressor(**kwargs) as proc: |
| 144 |
proc.compress(data) |
| 145 |
|
| 146 |
with pytest.raises(OverflowError, match=message): |
| 147 |
with lz4.stream.LZ4StreamDecompressor(**kwargs) as proc: |
| 148 |
proc.decompress(data) |
| 149 |
|
| 150 |
|
| 151 |
def test_dummy(): |
| 152 |
pass |