Pillow/Tests/check_large_memory_numpy.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

44 lines
1.0 KiB
Python
Raw Normal View History

from __future__ import annotations
2024-01-20 14:23:03 +03:00
2023-06-27 07:43:58 +03:00
import sys
2024-01-23 13:42:36 +03:00
from pathlib import Path
2023-06-27 07:43:58 +03:00
2020-03-28 04:51:28 +03:00
import pytest
from PIL import Image
2013-12-14 09:02:27 +04:00
# 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).
2013-12-14 09:02:27 +04:00
2019-06-13 18:53:42 +03:00
2020-03-28 04:51:28 +03:00
np = pytest.importorskip("numpy", reason="NumPy not installed")
2013-12-14 09:02:27 +04:00
YDIM = 32769
XDIM = 48000
2013-12-14 09:02:27 +04:00
2023-06-27 07:43:58 +03:00
pytestmark = pytest.mark.skipif(sys.maxsize <= 2**32, reason="requires 64-bit system")
2024-01-23 13:42:36 +03:00
def _write_png(tmp_path: Path, xdim: int, ydim: int) -> None:
2020-03-28 04:51:28 +03:00
dtype = np.uint8
a = np.zeros((xdim, ydim), dtype=dtype)
f = str(tmp_path / "temp.png")
im = Image.fromarray(a, "L")
im.save(f)
2013-12-14 09:02:27 +04:00
2024-01-23 13:42:36 +03:00
def test_large(tmp_path: Path) -> None:
2021-08-12 14:50:09 +03:00
"""succeeded prepatch"""
2020-03-28 04:51:28 +03:00
_write_png(tmp_path, XDIM, YDIM)
2024-01-23 13:42:36 +03:00
def test_2gpx(tmp_path: Path) -> None:
2020-03-28 04:51:28 +03:00
"""failed prepatch"""
_write_png(tmp_path, XDIM, XDIM)