Tests.helper cleanup

This commit is contained in:
nulano 2019-09-25 11:46:54 +02:00
parent 113a72633a
commit cf1f8b0498
18 changed files with 54 additions and 63 deletions

View File

@ -2,17 +2,15 @@
from __future__ import division
import sys
from PIL import Image
from .helper import PillowTestCase, unittest
from .helper import PillowTestCase, is_win32, unittest
min_iterations = 100
max_iterations = 10000
@unittest.skipIf(sys.platform.startswith("win32"), "requires Unix or macOS")
@unittest.skipIf(is_win32(), "requires Unix or macOS")
class TestImagingLeaks(PillowTestCase):
def _get_mem_usage(self):
from resource import getpagesize, getrusage, RUSAGE_SELF

View File

@ -1,9 +1,8 @@
import sys
from io import BytesIO
from PIL import Image
from .helper import PillowTestCase, unittest
from .helper import PillowTestCase, is_win32, unittest
# Limits for testing the leak
mem_limit = 1024 * 1048576
@ -13,7 +12,7 @@ codecs = dir(Image.core)
test_file = "Tests/images/rgb_trns_ycbc.jp2"
@unittest.skipIf(sys.platform.startswith("win32"), "requires Unix or macOS")
@unittest.skipIf(is_win32(), "requires Unix or macOS")
class TestJpegLeaks(PillowTestCase):
def setUp(self):
if "jpeg2k_encoder" not in codecs or "jpeg2k_decoder" not in codecs:

View File

@ -1,7 +1,6 @@
import sys
from io import BytesIO
from .helper import PillowTestCase, hopper, unittest
from .helper import PillowTestCase, hopper, is_win32, unittest
iterations = 5000
@ -15,7 +14,7 @@ valgrind --tool=massif python test-installed.py -s -v Tests/check_jpeg_leaks.py
"""
@unittest.skipIf(sys.platform.startswith("win32"), "requires Unix or macOS")
@unittest.skipIf(is_win32(), "requires Unix or macOS")
class TestJpegLeaks(PillowTestCase):
"""

View File

@ -368,6 +368,14 @@ def on_ci():
)
def is_win32():
return sys.platform.startswith("win32")
def is_pypy():
return hasattr(sys, "pypy_translation_info")
if sys.platform == "win32":
IMCONVERT = os.environ.get("MAGICK_HOME", "")
if IMCONVERT:

View File

@ -4,9 +4,7 @@ import sys
from PIL import Image
from .helper import PillowTestCase, unittest
is_pypy = hasattr(sys, "pypy_version_info")
from .helper import PillowTestCase, is_pypy, unittest
class TestCoreStats(PillowTestCase):
@ -87,7 +85,7 @@ class TestCoreMemory(PillowTestCase):
stats = Image.core.get_stats()
self.assertGreaterEqual(stats["new_count"], 1)
self.assertGreaterEqual(stats["allocated_blocks"], 64)
if not is_pypy:
if not is_pypy():
self.assertGreaterEqual(stats["freed_blocks"], 64)
def test_get_blocks_max(self):
@ -108,7 +106,7 @@ class TestCoreMemory(PillowTestCase):
if sys.maxsize < 2 ** 32:
self.assertRaises(ValueError, Image.core.set_blocks_max, 2 ** 29)
@unittest.skipIf(is_pypy, "images are not collected")
@unittest.skipIf(is_pypy(), "images are not collected")
def test_set_blocks_max_stats(self):
Image.core.reset_stats()
Image.core.set_blocks_max(128)
@ -123,7 +121,7 @@ class TestCoreMemory(PillowTestCase):
self.assertEqual(stats["freed_blocks"], 0)
self.assertEqual(stats["blocks_cached"], 64)
@unittest.skipIf(is_pypy, "images are not collected")
@unittest.skipIf(is_pypy(), "images are not collected")
def test_clear_cache_stats(self):
Image.core.reset_stats()
Image.core.clear_cache()
@ -153,7 +151,7 @@ class TestCoreMemory(PillowTestCase):
self.assertGreaterEqual(stats["allocated_blocks"], 16)
self.assertGreaterEqual(stats["reused_blocks"], 0)
self.assertEqual(stats["blocks_cached"], 0)
if not is_pypy:
if not is_pypy():
self.assertGreaterEqual(stats["freed_blocks"], 16)

View File

@ -1,10 +1,16 @@
import os
import sys
from io import BytesIO
from PIL import Image, ImageFile, JpegImagePlugin
from .helper import PillowTestCase, cjpeg_available, djpeg_available, hopper, unittest
from .helper import (
PillowTestCase,
cjpeg_available,
djpeg_available,
hopper,
is_win32,
unittest,
)
codecs = dir(Image.core)
@ -654,7 +660,7 @@ class TestFileJpeg(PillowTestCase):
self.assertNotIn("photoshop", im.info)
@unittest.skipUnless(sys.platform.startswith("win32"), "Windows only")
@unittest.skipUnless(is_win32(), "Windows only")
class TestFileCloseW32(PillowTestCase):
def setUp(self):
if "jpeg_encoder" not in codecs or "jpeg_decoder" not in codecs:

View File

@ -1,11 +1,10 @@
import sys
import zlib
from io import BytesIO
from PIL import Image, ImageFile, PngImagePlugin
from PIL._util import py3
from .helper import PillowLeakTestCase, PillowTestCase, hopper, unittest
from .helper import PillowLeakTestCase, PillowTestCase, hopper, is_win32, unittest
try:
from PIL import _webp
@ -650,7 +649,7 @@ class TestFilePng(PillowTestCase):
self.assert_image_similar(im, expected, 0.23)
@unittest.skipIf(sys.platform.startswith("win32"), "requires Unix or macOS")
@unittest.skipIf(is_win32(), "requires Unix or macOS")
class TestTruncatedPngPLeaks(PillowLeakTestCase):
mem_limit = 2 * 1024 # max increase in K
iterations = 100 # Leak is 56k/iteration, this will leak 5.6megs

View File

@ -1,12 +1,11 @@
import logging
import sys
from io import BytesIO
from PIL import Image, TiffImagePlugin, features
from PIL._util import py3
from PIL.TiffImagePlugin import RESOLUTION_UNIT, X_RESOLUTION, Y_RESOLUTION
from .helper import PillowTestCase, hopper, unittest
from .helper import PillowTestCase, hopper, is_win32, unittest
logger = logging.getLogger(__name__)
@ -612,7 +611,7 @@ class TestFileTiff(PillowTestCase):
im.load()
@unittest.skipUnless(sys.platform.startswith("win32"), "Windows only")
@unittest.skipUnless(is_win32(), "Windows only")
class TestFileTiffW32(PillowTestCase):
def test_fd_leak(self):
tmpfile = self.tempfile("temp.tif")

View File

@ -1,13 +1,11 @@
from __future__ import division
import sys
from PIL import Image, ImageDraw, ImageFont, features
from .helper import PillowLeakTestCase, unittest
from .helper import PillowLeakTestCase, is_win32, unittest
@unittest.skipIf(sys.platform.startswith("win32"), "requires Unix or macOS")
@unittest.skipIf(is_win32(), "requires Unix or macOS")
class TestTTypeFontLeak(PillowLeakTestCase):
# fails at iteration 3 in master
iterations = 10

View File

@ -1,11 +1,10 @@
import os
import shutil
import sys
from PIL import Image
from PIL._util import py3
from .helper import PillowTestCase, hopper, unittest
from .helper import PillowTestCase, hopper, is_win32, unittest
class TestImage(PillowTestCase):
@ -150,9 +149,7 @@ class TestImage(PillowTestCase):
im.paste(0, (0, 0, 100, 100))
self.assertFalse(im.readonly)
@unittest.skipIf(
sys.platform.startswith("win32"), "Test requires opening tempfile twice"
)
@unittest.skipIf(is_win32(), "Test requires opening tempfile twice")
def test_readonly_save(self):
temp_file = self.tempfile("temp.bmp")
shutil.copy("Tests/images/rgb32bf-rgba.bmp", temp_file)

View File

@ -3,7 +3,7 @@ import sys
from PIL import Image
from .helper import PillowTestCase, hopper, on_ci, unittest
from .helper import PillowTestCase, hopper, is_win32, on_ci, unittest
# CFFI imports pycparser which doesn't support PYTHONOPTIMIZE=2
# https://github.com/eliben/pycparser/pull/198#issuecomment-317001670
@ -333,7 +333,7 @@ class TestCffi(AccessTest):
class TestEmbeddable(unittest.TestCase):
@unittest.skipIf(
not sys.platform.startswith("win32") or on_ci(),
not is_win32() or on_ci(),
"Failing on AppVeyor / GitHub Actions when run from subprocess, not from shell",
)
def test_embeddable(self):

View File

@ -9,7 +9,7 @@ from io import BytesIO
from PIL import Image, ImageDraw, ImageFont, features
from .helper import PillowTestCase, unittest
from .helper import PillowTestCase, is_pypy, is_win32, unittest
FONT_PATH = "Tests/fonts/FreeMono.ttf"
FONT_SIZE = 20
@ -464,10 +464,7 @@ class TestImageFont(PillowTestCase):
with self.assertRaises(UnicodeEncodeError):
font.getsize(u"")
@unittest.skipIf(
sys.version.startswith("2") or hasattr(sys, "pypy_translation_info"),
"requires CPython 3.3+",
)
@unittest.skipIf(sys.version.startswith("2") or is_pypy(), "requires CPython 3.3+")
def test_unicode_extended(self):
# issue #3777
text = u"A\u278A\U0001F12B"
@ -504,7 +501,7 @@ class TestImageFont(PillowTestCase):
name = font.getname()
self.assertEqual(("FreeMono", "Regular"), name)
@unittest.skipIf(sys.platform.startswith("win32"), "requires Unix or macOS")
@unittest.skipIf(is_win32(), "requires Unix or macOS")
def test_find_linux_font(self):
# A lot of mocking here - this is more for hitting code and
# catching syntax like errors
@ -550,7 +547,7 @@ class TestImageFont(PillowTestCase):
font_directory + "/Duplicate.ttf", "Duplicate"
)
@unittest.skipIf(sys.platform.startswith("win32"), "requires Unix or macOS")
@unittest.skipIf(is_win32(), "requires Unix or macOS")
def test_find_macos_font(self):
# Like the linux test, more cover hitting code rather than testing
# correctness.

View File

@ -1,8 +1,6 @@
import sys
from PIL import Image, ImageShow
from .helper import PillowTestCase, hopper, on_ci, on_github_actions, unittest
from .helper import PillowTestCase, hopper, is_win32, on_ci, on_github_actions, unittest
class TestImageShow(PillowTestCase):
@ -37,7 +35,7 @@ class TestImageShow(PillowTestCase):
ImageShow._viewers.pop(0)
@unittest.skipUnless(
on_ci() and not (sys.platform == "win32" and on_github_actions()),
on_ci() and not (is_win32() and on_github_actions()),
"Only run on CIs; hangs on Windows on GitHub Actions",
)
def test_show(self):

View File

@ -1,8 +1,6 @@
import sys
from PIL import ImageWin
from .helper import PillowTestCase, hopper, unittest
from .helper import PillowTestCase, hopper, is_win32, unittest
class TestImageWin(PillowTestCase):
@ -32,7 +30,7 @@ class TestImageWin(PillowTestCase):
self.assertEqual(wnd2, 50)
@unittest.skipUnless(sys.platform.startswith("win32"), "Windows only")
@unittest.skipUnless(is_win32(), "Windows only")
class TestImageWinDib(PillowTestCase):
def test_dib_image(self):
# Arrange

View File

@ -1,14 +1,13 @@
import ctypes
import sys
from io import BytesIO
from PIL import Image, ImageWin
from .helper import PillowTestCase, hopper
from .helper import PillowTestCase, hopper, is_win32
# see https://github.com/python-pillow/Pillow/pull/1431#issuecomment-144692652
if sys.platform.startswith("win32"):
if is_win32():
import ctypes.wintypes
class BITMAPFILEHEADER(ctypes.Structure):

View File

@ -5,14 +5,12 @@ import subprocess
import sys
from unittest import TestCase
from .helper import on_github_actions, unittest
from .helper import is_pypy, is_win32, on_github_actions, unittest
class TestMain(TestCase):
@unittest.skipIf(
sys.platform == "win32"
and hasattr(sys, "pypy_translation_info")
and on_github_actions(),
is_win32() and is_pypy() and on_github_actions(),
"Failing on Windows on GitHub Actions running PyPy",
)
def test_main(self):

View File

@ -2,7 +2,7 @@ import sys
from PIL import Image
from .helper import PillowTestCase, unittest
from .helper import PillowTestCase, is_win32, unittest
try:
import numpy
@ -10,7 +10,7 @@ except ImportError:
numpy = None
@unittest.skipIf(sys.platform.startswith("win32"), "Win32 does not call map_buffer")
@unittest.skipIf(is_win32(), "Win32 does not call map_buffer")
class TestMap(PillowTestCase):
def test_overflow(self):
# There is the potential to overflow comparisons in map.c

View File

@ -1,5 +1,4 @@
import shutil
import sys
from PIL import GifImagePlugin, Image, JpegImagePlugin
@ -7,6 +6,7 @@ from .helper import (
PillowTestCase,
cjpeg_available,
djpeg_available,
is_win32,
netpbm_available,
unittest,
)
@ -17,7 +17,7 @@ TEST_GIF = "Tests/images/hopper.gif"
test_filenames = ("temp_';", 'temp_";', "temp_'\"|", "temp_'\"||", "temp_'\"&&")
@unittest.skipIf(sys.platform.startswith("win32"), "requires Unix or macOS")
@unittest.skipIf(is_win32(), "requires Unix or macOS")
class TestShellInjection(PillowTestCase):
def assert_save_filename_check(self, src_img, save_func):
for filename in test_filenames: