Commit Graph

51 Commits

Author SHA1 Message Date
Hugo
a4bf9fa036 Convert most PillowTestCase methods to pytest 2020-02-02 12:26:01 +02:00
Alexander
ac92836e81 Change default resize resampling filter 2019-12-07 18:08:19 +03:00
Andrew Murray
c0048ad7de Use context managers 2019-11-26 07:03:23 +11:00
Jon Dufresne
33dabf986f Import unittest from stdlib rather than helper.py
The unittest in helper.py has not offered an interesting abstraction
since dbe9f85c7d so import from the more
typical stdlib location.
2019-11-20 18:42:52 -08:00
Jon Dufresne
4cd4adddc3 Improve handling of file resources
Follow Python's file object semantics. User code is responsible for
closing resources (usually through a context manager) in a deterministic
way.

To achieve this, remove __del__ functions. These functions used to
closed open file handlers in an attempt to silence Python
ResourceWarnings. However, using __del__ has the following drawbacks:

- __del__ isn't called until the object's reference count reaches 0.
  Therefore, resource handlers remain open or in use longer than
  necessary.

- The __del__ method isn't guaranteed to execute on system exit. See the
  Python documentation:

  https://docs.python.org/3/reference/datamodel.html#object.__del__

  > It is not guaranteed that __del__() methods are called for objects
  > that still exist when the interpreter exits.

- Exceptions that occur inside __del__ are ignored instead of raised.
  This has the potential of hiding bugs. This is also in the Python
  documentation:

  > Warning: Due to the precarious circumstances under which __del__()
  > methods are invoked, exceptions that occur during their execution
  > are ignored, and a warning is printed to sys.stderr instead.

Instead, always close resource handlers when they are no longer in use.
This will close the file handler at a specified point in the user's code
and not wait until the interpreter chooses to. It is always guaranteed
to run. And, if an exception occurs while closing the file handler, the
bug will not be ignored.

Now, when code receives a ResourceWarning, it will highlight an area
that is mishandling resources. It should not simply be silenced, but
fixed by closing resources with a context manager.

All warnings that were emitted during tests have been cleaned up. To
enable warnings, I passed the `-Wa` CLI option to Python. This exposed
some mishandling of resources in ImageFile.__init__() and
SpiderImagePlugin.loadImageSeries(), they too were fixed.
2019-10-12 08:27:17 -07:00
Andrew Murray
87c43b66a5 Corrected negative seeks 2019-09-30 18:31:18 +10:00
Hugo van Kemenade
8e3c4e3658
Merge pull request #3965 from radarhere/truncated
Raise the same error if a truncated image is loaded a second time
2019-09-20 22:53:52 +03:00
Andrew Murray
5a668779e9 Added tests 2019-09-08 21:27:55 +10:00
Andrew Murray
023dcf27c2 Raise the same error if a truncated image is loaded a second time 2019-07-13 08:37:17 +10:00
Jon Dufresne
d50445ff30 Introduce isort to automate import ordering and formatting
Similar to the recent adoption of Black. isort is a Python utility to
sort imports alphabetically and automatically separate into sections. By
using isort, contributors can quickly and automatically conform to the
projects style without thinking. Just let the tool do it.

Uses the configuration recommended by the Black to avoid conflicts of
style.

Rewrite TestImageQt.test_deprecated to no rely on import order.
2019-07-06 16:11:35 -07:00
Hugo
5631718a8d Format with Black 2019-06-13 18:54:46 +03:00
Andrew Murray
3caec4344e Added get_ifd method to access embedded IFDs 2019-03-28 21:13:12 +11:00
Andrew Murray
d5db62be7b Added EXIF class 2019-03-28 21:13:12 +11:00
Jon Dufresne
4de5477b61 Remove unnecessary unittest.main() boilerplate from test files
With the introduction and use of pytest, it is simple and easy to
execute specific tests in isolation through documented command line
arguments. Either by specifying the module path or through the `-k
EXPRESSION` argument. There is no longer any need to provide the
boilerplate:

    if __name__ == '__main__':
        unittest.main()

To every test file. It is simply noise.

The pattern remains in test files that aren't named with `test_*` as
those files are not discovered and executed by pytest by default.
2019-02-03 10:10:16 -08:00
Jon Dufresne
7da17ad41e Improve pytest configuration to allow specific tests as CLI args
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.
2019-01-13 09:00:12 -08:00
Hugo
d69ef6a529 Remove redundant parentheses 2018-10-24 22:29:56 +03:00
Hugo
619e5fde8d Remove unused local variables 2018-10-24 22:29:01 +03:00
Andrew Murray
0adeb82e98 Changed Image size property to be read-only by default 2018-09-30 13:45:18 +10:00
Andrew Murray
c2189235af Line too long 2018-07-02 19:26:02 +10:00
Andrew Murray
6793b5bbd5 Added ImageFile get_format_mimetype method 2018-06-30 21:08:41 +10:00
Andrew Murray
2202196162 Flake8 blank line fixes 2018-03-04 21:36:33 +11:00
Andrew Murray
97662294f0 Added context manager support 2017-10-07 23:18:23 +11:00
Andrew Murray
9e843a2d9b Changed format of lambda calls 2017-09-01 21:05:40 +10:00
Joshua Blum
a6874f01ac Add test 2017-05-13 12:07:16 -04:00
Andrew Murray
37b293f593 Flake8 fixes 2017-04-20 21:14:23 +10:00
wiredfool
d718d351b1 Testing empty extents 2017-03-11 16:43:44 +00:00
wiredfool
382833061e Trigger set_as_raw error 2017-03-11 16:30:28 +00:00
wiredfool
d70de6eb2d UnitTest PyDecoder 2017-03-11 15:35:03 +00:00
homm
1ba4e9e5ba remove end of file banner from all files 2016-07-10 14:11:28 +03:00
homm
f46d65d0a4 test for this 2015-09-15 20:12:16 +03:00
homm
430e9922eb test for loading truncated image and raising proper exception 2015-09-08 17:43:12 +03:00
Andrew Murray
a06b59bd52 Added various tests 2015-07-03 15:03:25 +10:00
Andrew Murray
ca89d431ba To avoid modifications, copy image when saving in GifImagePlugin 2015-05-13 16:39:25 +10:00
Andrew Murray
ee34d6843b Further health fixes 2015-04-24 18:24:52 +10:00
Andrew Murray
d1c182cadc Various Flake8 fixes 2015-04-24 09:26:52 +10:00
Eric Soroos
1a91078154 Test failure explanation on PPC 2014-09-29 22:28:11 -07:00
hugovk
8dad2b0c63 Replace some lena() with hopper(), and temporarily disable fail-fast so we can see all failures 2014-09-05 13:03:56 +03:00
hugovk
0c12058e37 Use unique class names to match filenames 2014-07-20 01:17:20 +03:00
hugovk
cf04a9a0d2 Remove unused tearDownModule 2014-07-07 20:03:50 +03:00
hugovk
3ec505958e Convert old tests to use unittest 2014-06-10 12:10:47 +03:00
hugovk
c9a4272af6 Replace python-imaging with python-pillow (but yet not Coveralls) 2014-06-03 13:02:44 +03:00
wiredfool
82d7524add made has_ghostscript a method, using it from test_imagefile 2014-04-04 13:33:54 -07:00
wiredfool
36323d1140 Make ICO files work with the ImageFile.Parser interface, fixes #522 2014-02-16 20:58:06 -08:00
wiredfool
8ce2faa8c9 enable eps test in test_imagefile, test passes 2014-01-21 23:17:47 -08:00
Alex Clark
bb1b3a532c Cleanup WS, courtesy of @Arfrever
find * -type f "-(" -name "*.bdf" -o -name "*.c" -o -name "*.h" -o -name "*.py" -o -name "*.rst" -o -name "*.txt" "-)" -exec sed -e "s/[[:space:]]*$//" -i {} \;
2013-06-30 18:42:19 -04:00
Michał Górny
6cdc8b08db test_imagefile: handle missing PNG & JPEG encoders gracefully. 2013-04-21 10:13:33 +02:00
Alex Clark
d0d92de8ab Punt 2013-03-08 09:32:08 -05:00
Brian Crowell
2972b2178e py3k: Add PCX to roundtrip test
For some reason, the PCX codec round-trips now.
2013-01-10 08:47:00 -06:00
Brian Crowell
4f7d784a71 py3k: Actually fix the EPS encoder
The EPS encoder wasn't part of Gohlke's test suite, so the previous "fixes"
there were only expected syntactic ones. This gives a cleaner fix to the
encoder.

The decoder doesn't work in round-trip due to a missing eps_decoder method
on the core module, but it's clear it worked at some point.
2013-01-10 08:47:00 -06:00
Brian Crowell
8035b1a76a py3k: FIX: TGA missing o8 declaration
Plus, TGA was eligible for a round-trip test in test_imagefile. It has one
now.
2013-01-10 08:46:59 -06:00