Commit Graph

169 Commits

Author SHA1 Message Date
Hugo
cc63f66575 Merge remote-tracking branch 'upstream/master' into rm-2.7 2019-11-01 13:22:56 +02: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
Hugo
4382413bb4 Remove redundant bytearray 2019-10-07 16:23:43 +03:00
Hugo
538d9e2e5d Upgrade Python syntax with pyupgrade --py3-plus 2019-10-07 14:30:59 +03:00
Andrew Murray
2dbfabe6d5 Simplifications 2019-08-24 08:10:45 +10:00
djy0
0872cb4377 fix comment 2019-08-12 18:54:29 +10:00
djy0
63c15dc3ba format 2019-08-12 18:54:29 +10:00
djy0
3c971bec41 format 2019-08-12 18:54:29 +10:00
djy0
8696f06fbe Update test_file_gif.py 2019-08-12 18:54:29 +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
Andrew Murray
90d3d37164 Do not presume that the background color index is 0 2019-06-29 23:06:45 +10:00
Andrew Murray
97c15a245c Corrected color table size calculation 2019-06-29 23:02:26 +10:00
Andrew Murray
c3e982e0c6
Merge branch 'master' into master 2019-06-29 22:59:17 +10:00
Hugo
d08475442b Format with Black 2019-06-13 18:53:42 +03:00
Andrew Murray
27134340f5 Expand GIF to include frames with extents outside the image size 2019-05-02 19:46:17 +10:00
Riley Lahd
5fb36d2de4 Merge branch 'master' of https://github.com/python-pillow/Pillow 2019-04-09 08:24:52 -06:00
Riley Lahd
ad70fc73cb Linting changes 2019-03-22 08:26:16 -06:00
Riley Lahd
4b2746fc39 Remove disposal 2 duplicate frame exemption and add true delta test 2019-03-22 08:19:01 -06:00
Andrew Murray
7dfbdc01f4 Fixed bug when rewinding to a non-zero frame 2019-03-16 20:02:24 +11:00
Andrew Murray
0b630e06dc Test that background colours read are equal to saved colours 2019-03-15 10:29:33 +11:00
Riley Lahd
85a07bb385 Linting changes 2019-03-14 14:51:13 -06:00
Riley Lahd
96c5a4c543 Add test for disposal mode 2 gifs 2019-03-14 14:40:31 -06: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
bbb3be9a9d
Merge pull request #3187 from radarhere/encoderinfo
Wait until mode is normalized to copy im.info into encoderinfo
2018-12-26 12:56:50 +02:00
Hugo
961fecb35c
Merge pull request #3261 from radarhere/fp
Resolve __fp when closing and deleting
2018-12-13 21:09:23 +02:00
Andrew Murray
b2b737b68b Allow arbitrary number of comment extension subblocks 2018-11-27 21:11:22 +11:00
Andrew Murray
f1b2802eb1 Resolved error for comment extension with zero subblocks 2018-11-27 21:09:28 +11:00
Andrew Murray
47775f3d50 Resolve __fp when closing and deleting 2018-11-17 21:56:06 +11:00
Andrew Murray
a7eb2ea9cc Change tuple background to global color table index when saving 2018-10-02 20:52:07 +10:00
Andrew Murray
fbc121d678 Changed GIF seek to remove previous info items 2018-09-01 09:28:22 +10:00
Andrew Murray
de2fbc9dff Wait until mode is normalized to copy im.info into encoderinfo 2018-08-25 00:55:51 +10:00
Andrew Murray
c2189235af Line too long 2018-07-02 19:26:02 +10:00
Andrew Murray
05c78a13e7 Changed encoderinfo to have priority over info when saving GIF images 2018-04-11 08:57:31 +10:00
Andrew Murray
c13ccf13a1 Added missing whitespace 2018-03-06 19:53:07 +11:00
Andrew Murray
f22f1628eb At least two spaces before inline comment 2018-03-04 21:36:33 +11:00
Andrew Murray
2202196162 Flake8 blank line fixes 2018-03-04 21:36:33 +11:00
Andrew Murray
30b2ddd070 Removed duplicate imports 2018-01-04 15:40:46 +11:00
wiredfool
48260643d7 force range to a tuple, py3 2017-12-21 22:42:34 +00:00
wiredfool
378f74672c Added per-frame disposal, tests 2017-12-21 22:26:58 +00:00
linnil1
5b5d47863e Add dispose test 2017-12-21 22:06:59 +00:00
wiredfool
f5e4338b86
Merge pull request #2813 from wiredfool/issue_2811
Permit LZW code lengths up to 12 bits in GIF decode
2017-11-05 15:02:41 +00:00
Andrew Murray
bc255c97ff Added support for generators when using append_images 2017-11-04 10:46:15 +11:00
Eric Soroos
fcabe1c08c Tests for issue #2811 2017-10-25 13:52:33 +00:00
Andrew Murray
f61b70aa8f Changed EOFError tests 2017-09-30 13:33:06 +10:00
wiredfool
fd8ee8437b Merge pull request #2315 from radarhere/is_animated
If n_frames is known, then use when determining is_animated
2017-09-29 15:26:22 +01:00
Andrew Murray
9e843a2d9b Changed format of lambda calls 2017-09-01 21:05:40 +10:00
Andrew Murray
371933a597 Added tests 2017-09-01 20:36:51 +10:00
Andrew Murray
ce999ff302 If n_frames is known, then use when determining is_animated 2017-08-18 20:20:27 +10:00
Andrew Murray
e8cba27bb1 Changed assert checks to more specific versions 2017-06-03 14:04:54 +10:00
Andrew Murray
37b293f593 Flake8 fixes 2017-04-20 21:14:23 +10:00
wiredfool
4483dfbcb9 py3, pep8 2017-03-08 01:35:15 -08:00
wiredfool
1428e4140a Test for identical handling of getheader/getdata 2017-03-08 01:35:15 -08:00
wiredfool
51b46e00c2 Refactor out passed in palette handling, add ImagePalette as an option, document palette format 2017-03-08 01:35:15 -08:00
wiredfool
6559674032 Test passing in an I mode image 2017-03-08 01:35:15 -08:00
wiredfool
b7689627e8 Add tests for passing in a separate palette while saving a gif 2017-03-08 01:35:15 -08:00
Andrew Murray
9a36a51916 Test from #2375, 0ebb4cd1c0 2017-03-08 01:35:15 -08:00
Andrew Murray
af57ff8d45 Simplified code 2017-03-08 19:41:18 +11:00
Andrew Murray
bc8cd5fabf Added test 2017-03-08 19:41:18 +11:00
Andrew Murray
0b93853fd8 Removed duplicate imports 2017-03-03 21:38:19 +11:00
Andrew Murray
a06dd59df7 Added context managers 2016-12-28 09:54:10 +11:00
wiredfool
944a470a79 Merge pull request #2312 from wiredfool/pr_2298
List of individual frame durations for saving animated gifs. #2298
2016-12-27 12:00:40 +00:00
wiredfool
f36a04570f Merge pull request #2313 from wiredfool/pr_2196
Unified different GIF optimize conditions #2196, Test for #2196
2016-12-27 11:53:50 +00:00
wiredfool
915270ef6f test for issue #2195 2016-12-27 03:33:20 -08:00
wiredfool
e530f2a228 Added tuple option for durations 2016-12-27 03:04:37 -08:00
wiredfool
87092ad4f8 can pass list of integer to set different duration for each frame when saving GIF 2016-12-27 02:44:05 -08:00
Jon Dufresne
ffa5bc2726 Use generator expressions instead of list comprehension
Avoids unnecessary temporary lists in memory.
2016-11-14 18:11:15 -08:00
Jon Dufresne
7992d2a65a Fix BytesWarning discovered while running tests
Discovered using the command:

python -b -m nose -vx Tests/test_*.py
2016-10-22 12:35:44 -07:00
wiredfool
bc66e2b34a py3 fix 2016-09-26 15:15:43 -07:00
wiredfool
a51d3bcdba Speed up Gif save optimization step: don't do it as often and do it in C. Fixes #2093 2016-09-26 14:51:28 -07:00
Andrew Murray
b346ed36f1 Added append_images parameter to GIF saving 2016-09-11 12:04:01 +10:00
homm
1ba4e9e5ba remove end of file banner from all files 2016-07-10 14:11:28 +03:00
Andrew Murray
8298fcce73 Added support for GIF comment extension 2016-05-07 13:57:40 +10:00
Andrew Murray
b8ff91ab3b Corrected version number when saving GIFs 2015-08-21 22:10:13 +10:00
Andrew Murray
f64bc891d4 Changed GifImagePlugin to include use image info params 2015-08-21 22:09:05 +10:00
Anton Vlasenko
1f8a37841c Testing that animated gif preserves all important headers 2015-08-21 21:46:04 +10:00
Anton Vlasenko
a90e72076a Fixing typo to have proper testing 2015-07-23 11:29:26 +02:00
Andrew Murray
309ab1fc3d Various Flake8 fixes 2015-07-03 16:22:56 +10:00
Andrew Murray
a06b59bd52 Added various tests 2015-07-03 15:03:25 +10:00
Andrew Murray
4fbea3e553 Added multiframe GIF test 2015-07-01 09:18:05 +10:00
Alex Clark
be1df0f33c Merge pull request #1320 from radarhere/gifmaker
Merged gifmaker into GifImagePlugin
2015-06-30 08:00:39 -04:00
Andrew Murray
7227b4d01d Added test 2015-06-30 18:07:23 +10:00
Andrew Murray
d20eef450b Added is_animated 2015-06-30 13:25:00 +10:00
Andrew Murray
1111e9fb35 Fixed frame position when seeking past the end of file 2015-06-19 00:49:18 +10:00
wiredfool
30631902d6 Merge pull request #1231 from radarhere/image_palette
Copy image when saving in GifImagePlugin
2015-06-16 11:49:41 -07:00
Andrew Murray
ecb1cef99b Added background color index saving to GifImagePlugin 2015-06-11 11:10:05 +10:00
Andrew Murray
46f439604c Added tests 2015-06-08 01:02:43 +10:00
Hugo
b816c048ad Merge pull request #1172 from radarhere/gif
Added duration and loop set to GifImagePlugin
2015-06-04 13:07:58 +03: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
aa1368f551 Flake8 fixes 2015-04-23 23:41:42 +10:00
Andrew Murray
a5917b3fa3 Added GifImagePlugin tests 2015-04-04 11:45:30 +11:00
homm
43d5d06ce4 rename Image.ANTIALIAS to Image.LANCZOS 2014-11-28 01:41:56 +03:00
hugovk
c859e3bf40 Some landscape.io fixes 2014-11-27 21:43:45 +02:00
Moriyoshi Koizumi
9d60085957 The optimization algorithm is only applicable to the image of mode="P" or "L". 2014-11-06 21:29:27 +09:00
hugovk
1de128d6b6 Merge branch 'master' into flake8 2014-09-14 10:23:51 +03:00
hugovk
78e7fe025e Fix constant name 2014-09-04 09:42:31 +03:00
Hugo
d7f7965aa2 Replace lena.gif with hopper.gif 2014-09-04 08:44:46 +03:00
hugovk
8de95676e0 flake8 2014-08-26 16:47:10 +03:00
Nikita Uvarov
778768c9bc Fixed test_optimize_full_l test case for python2. 2014-08-19 15:00:15 +03:00