Debian Codegraph @

tests/block/test_block_2.py

raw symbols SCIP
1 import pytest
2 import sys
3 import lz4.block
4 import psutil
5 import os
6
7 # This test requires allocating a big lump of memory. In order to
8 # avoid a massive memory allocation during byte compilation, we have
9 # to declare a variable for the size of the buffer we're going to
10 # create outside the scope of the function below. See:
11 # https://bugs.python.org/issue21074
12 _4GB = 0x100000000 # 4GB
13
14 # This test will be killed on Travis due to the 3GB memory limit
15 # there. Unfortunately psutil reports the host memory, not the memory
16 # available to the container, and so can't be used to detect available
17 # memory, so instead, as an ugly hack for detecting we're on Travis we
18 # check for the TRAVIS environment variable being set. This is quite
19 # fragile.
20
21
22 @pytest.mark.skipif(
23 os.environ.get('TRAVIS') is not None,
24 reason='Skipping test on Travis due to insufficient memory'
25 )
26 @pytest.mark.skipif(
27 sys.maxsize < 0xffffffff,
28 reason='Py_ssize_t too small for this test'
29 )
30 @pytest.mark.skipif(
31 psutil.virtual_memory().available < _4GB,
32 reason='Insufficient system memory for this test'
33 )
34 def test_huge():
35 try:
36 huge = b'\0' * _4GB
37 except MemoryError:
38 pytest.skip('Insufficient system memory for this test')
39
40 with pytest.raises(
41 OverflowError, match='Input too large for LZ4 API'
42 ):
43 lz4.block.compress(huge)
44
45 with pytest.raises(
46 OverflowError, match='Dictionary too large for LZ4 API'
47 ):
48 lz4.block.compress(b'', dict=huge)
49
50 with pytest.raises(
51 OverflowError, match='Input too large for LZ4 API'
52 ):
53 lz4.block.decompress(huge)
54
55 with pytest.raises(
56 OverflowError, match='Dictionary too large for LZ4 API'
57 ):
58 lz4.block.decompress(b'', dict=huge)
59
60
61 def test_dummy():
62 pass