mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-14 13:46:57 +03:00
7da17ad41e
The previous test configuration made it difficult to run a single test with the pytest CLI. There were two major issues: - The Tests directory was not a package. It now includes a __init__.py file and imports from other tests modules are done with relative imports. - setup.cfg always specified the Tests directory. So even if a specific test were specified as a CLI arg, this configuration would also always include all tests. This configuration has been removed to allow specifying a single test on the command line. Contributors can now run specific tests with a single command such as: $ tox -e py37 -- Tests/test_file_pdf.py::TestFilePdf.test_rgb This makes it easy and faster to iterate on a single test failure and is very familiar to those that have previously used tox and pytest. When running tox or pytest with no arguments, they still discover and runs all tests in the Tests directory.
45 lines
1.4 KiB
Python
Executable File
45 lines
1.4 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
from __future__ import division
|
|
from .helper import unittest, PillowTestCase
|
|
import sys
|
|
from PIL import Image
|
|
|
|
min_iterations = 100
|
|
max_iterations = 10000
|
|
|
|
|
|
@unittest.skipIf(sys.platform.startswith('win32'), "requires Unix or macOS")
|
|
class TestImagingLeaks(PillowTestCase):
|
|
|
|
def _get_mem_usage(self):
|
|
from resource import getpagesize, getrusage, RUSAGE_SELF
|
|
mem = getrusage(RUSAGE_SELF).ru_maxrss
|
|
return mem * getpagesize() / 1024 / 1024
|
|
|
|
def _test_leak(self, min_iterations, max_iterations, fn, *args, **kwargs):
|
|
mem_limit = None
|
|
for i in range(max_iterations):
|
|
fn(*args, **kwargs)
|
|
mem = self._get_mem_usage()
|
|
if i < min_iterations:
|
|
mem_limit = mem + 1
|
|
continue
|
|
msg = 'memory usage limit exceeded after %d iterations' % (i + 1)
|
|
self.assertLessEqual(mem, mem_limit, msg)
|
|
|
|
def test_leak_putdata(self):
|
|
im = Image.new('RGB', (25, 25))
|
|
self._test_leak(min_iterations, max_iterations,
|
|
im.putdata, im.getdata())
|
|
|
|
def test_leak_getlist(self):
|
|
im = Image.new('P', (25, 25))
|
|
self._test_leak(min_iterations, max_iterations,
|
|
# Pass a new list at each iteration.
|
|
lambda: im.point(range(256)))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|