File: check_large_memory_numpy.py

package info (click to toggle)
pillow 8.1.2%2Bdfsg-0.3%2Bdeb11u2
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 65,628 kB
  • sloc: python: 35,630; ansic: 31,009; makefile: 388; javascript: 114; sh: 77
file content (40 lines) | stat: -rw-r--r-- 938 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import sys

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).


np = pytest.importorskip("numpy", reason="NumPy not installed")

YDIM = 32769
XDIM = 48000


pytestmark = pytest.mark.skipif(sys.maxsize <= 2 ** 32, reason="requires 64-bit system")


def _write_png(tmp_path, xdim, ydim):
    dtype = np.uint8
    a = np.zeros((xdim, ydim), dtype=dtype)
    f = str(tmp_path / "temp.png")
    im = Image.fromarray(a, "L")
    im.save(f)


def test_large(tmp_path):
    """ succeeded prepatch"""
    _write_png(tmp_path, XDIM, YDIM)


def test_2gpx(tmp_path):
    """failed prepatch"""
    _write_png(tmp_path, XDIM, XDIM)