Pillow/Tests/check_large_memory.py

49 lines
1.1 KiB
Python
Raw Normal View History

2014-07-01 06:19:09 +04:00
import sys
2020-03-28 04:51:28 +03:00
import pytest
from PIL import Image
# This test is not run automatically.
#
# It requires > 2gb memory for the >2 gigapixel image generated in the
# second test. Running this automatically would amount to a denial of
# service on our testing infrastructure. I expect this test to fail
# on any 32-bit machine, as well as any smallish things (like
# Raspberry Pis). It does succeed on a 3gb Ubuntu 12.04x64 VM on Python
2016-02-09 14:02:43 +03:00
# 2.7 and 3.2.
try:
import numpy
except ImportError:
numpy = None
YDIM = 32769
XDIM = 48000
2022-03-04 08:42:24 +03:00
pytestmark = pytest.mark.skipif(sys.maxsize <= 2**32, reason="requires 64-bit system")
2020-03-28 04:51:28 +03:00
def _write_png(tmp_path, xdim, ydim):
f = str(tmp_path / "temp.png")
im = Image.new("L", (xdim, ydim), 0)
im.save(f)
2020-03-28 04:51:28 +03:00
def test_large(tmp_path):
2021-08-12 14:50:09 +03:00
"""succeeded prepatch"""
2020-03-28 04:51:28 +03:00
_write_png(tmp_path, XDIM, YDIM)
2020-03-28 04:51:28 +03:00
def test_2gpx(tmp_path):
"""failed prepatch"""
_write_png(tmp_path, XDIM, XDIM)
2020-03-28 04:51:28 +03:00
@pytest.mark.skipif(numpy is None, reason="Numpy is not installed")
def test_size_greater_than_int():
arr = numpy.ndarray(shape=(16394, 16394))
Image.fromarray(arr)