2023-12-21 14:13:31 +03:00
|
|
|
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
|
2024-01-19 13:50:27 +03:00
|
|
|
from types import ModuleType
|
2023-06-27 07:43:58 +03:00
|
|
|
|
2020-03-28 04:51:28 +03:00
|
|
|
import pytest
|
2020-08-07 13:28:33 +03:00
|
|
|
|
2019-07-06 23:40:53 +03:00
|
|
|
from PIL import Image
|
|
|
|
|
2013-12-05 08:59:33 +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
|
2015-10-14 16:49:03 +03:00
|
|
|
# on any 32-bit machine, as well as any smallish things (like
|
2014-06-25 13:32:52 +04:00
|
|
|
# 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.
|
2013-12-05 08:59:33 +04:00
|
|
|
|
2019-04-15 10:33:28 +03:00
|
|
|
|
2024-01-19 13:50:27 +03:00
|
|
|
numpy: ModuleType | None
|
2019-04-15 10:33:28 +03:00
|
|
|
try:
|
|
|
|
import numpy
|
|
|
|
except ImportError:
|
|
|
|
numpy = None
|
|
|
|
|
2014-06-25 13:32:52 +04:00
|
|
|
YDIM = 32769
|
|
|
|
XDIM = 48000
|
|
|
|
|
|
|
|
|
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
|
|
|
f = str(tmp_path / "temp.png")
|
|
|
|
im = Image.new("L", (xdim, ydim), 0)
|
|
|
|
im.save(f)
|
|
|
|
|
2014-06-25 13:32:52 +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)
|
2014-06-25 13:32:52 +04:00
|
|
|
|
|
|
|
|
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)
|
2019-04-15 10:33:28 +03:00
|
|
|
|
2014-06-25 13:32:52 +04:00
|
|
|
|
2020-03-28 04:51:28 +03:00
|
|
|
@pytest.mark.skipif(numpy is None, reason="Numpy is not installed")
|
2024-01-19 13:50:27 +03:00
|
|
|
def test_size_greater_than_int() -> None:
|
|
|
|
assert numpy is not None
|
2020-03-28 04:51:28 +03:00
|
|
|
arr = numpy.ndarray(shape=(16394, 16394))
|
|
|
|
Image.fromarray(arr)
|