Pillow/Tests/check_large_memory_numpy.py

45 lines
1.1 KiB
Python
Raw Normal View History

import sys
from PIL import Image
from .helper import PillowTestCase, unittest
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
2013-12-14 09:02:27 +04:00
try:
import numpy as np
2015-12-09 08:24:32 +03:00
except ImportError:
raise unittest.SkipTest("numpy not installed")
2013-12-14 09:02:27 +04:00
YDIM = 32769
XDIM = 48000
2013-12-14 09:02:27 +04:00
2019-06-13 18:53:42 +03:00
@unittest.skipIf(sys.maxsize <= 2 ** 32, "requires 64-bit system")
class LargeMemoryNumpyTest(PillowTestCase):
def _write_png(self, xdim, ydim):
dtype = np.uint8
a = np.zeros((xdim, ydim), dtype=dtype)
2019-06-13 18:53:42 +03:00
f = self.tempfile("temp.png")
im = Image.fromarray(a, "L")
im.save(f)
2013-12-14 09:02:27 +04:00
def test_large(self):
""" succeeded prepatch"""
self._write_png(XDIM, YDIM)
2013-12-14 09:02:27 +04:00
def test_2gpx(self):
"""failed prepatch"""
self._write_png(XDIM, XDIM)
2019-06-13 18:53:42 +03:00
if __name__ == "__main__":
unittest.main()