Commit Graph

52 Commits

Author SHA1 Message Date
Andrew Murray
c0048ad7de Use context managers 2019-11-26 07:03:23 +11: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
27d6fc7bc5 Improved HSV conversion 2019-08-12 06:50:18 +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
77f946d8bc Format with Black 2019-06-13 18:54:24 +03:00
Andrew Murray
231fe4d62a Revert "Merge pull request #3838 from radarhere/i_conversion"
This reverts commit 41f3e7c8bd, reversing
changes made to 2f84482871.
2019-06-11 19:28:31 +10:00
Andrew Murray
2787b9b991 Added tests 2019-05-08 21:59:16 +10:00
Andrew Murray
8a035b8c5d Improved I mode conversion 2019-05-08 21:58:33 +10:00
Andrew Murray
819b8acd26 Improved PA conversion 2019-03-29 23:13:07 +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
d1ca4916e0 Use more specific assertions 2018-10-24 22:29:01 +03:00
Andrew Murray
a8261a2e89 Line too long 2018-09-27 20:35:00 +10:00
Andrew Murray
e98469ecf6 Added transparency to matrix conversion 2018-08-25 00:54:51 +10:00
Andrew Murray
44a4219283 Added test for converting GIF with RGBA palette to P 2018-07-14 18:55:13 +10:00
Andrew Murray
c2189235af Line too long 2018-07-02 19:26:02 +10:00
Andrew Murray
145589ef14 Ambiguous variable name 'l' 2018-07-02 19:21:44 +10:00
Andrew Murray
2202196162 Flake8 blank line fixes 2018-03-04 21:36:33 +11:00
Metallicow
5e94cd0fc2 Trim trailing whitespace tests dir 2018-01-27 00:07:24 -06:00
wiredfool
2611b2caa5 Merge pull request #2689 from radarhere/tests
Added tests
2017-09-04 11:15:28 +01:00
Andrew Murray
9e843a2d9b Changed format of lambda calls 2017-09-01 21:05:40 +10:00
wiredfool
2ad43c4eeb Merge pull request #2704 from wiredfool/issue_2702
Remove palettes from non-palette modes in _new #2702
2017-08-31 15:09:37 +01:00
wiredfool
f4c56a7179 Merge pull request #2633 from olt/delete-rgb-transparency
Delete transparency info when img.convert'ing RGB/L to RGBA
2017-08-31 15:08:52 +01:00
wiredfool
e422f92e52 Remove palettes from non-palette modes in _new #2702 2017-08-31 06:18:59 -07:00
Alexander
349e300d7b use getchannel where is possible 2017-08-09 02:36:07 +03:00
Oliver Tonnhofer
9e7de70bac Delete transparency info when convert'ing RGB/L to RGBA
info['transparency] was not removed when an RGB or L image
was converted to RGBA. This could result in unexpected behavior
when saving the resulting image.

Other image conversions already delete or update the transparency
info. There is a shortcut for RGB/L to RGBA which missed this.
2017-07-18 15:00:09 +02:00
Andrew Murray
37b293f593 Flake8 fixes 2017-04-20 21:14:23 +10:00
wiredfool
d707cb3692 Tight similarity tests for XYZ conversion 2017-02-20 13:41:28 -08:00
Hugo
04e3f585b0 Test no change with identity matrix 2017-01-30 14:28:00 +02:00
Hugo
7fba16b074 Test for similarity 2017-01-30 14:27:29 +02:00
hugovk
fdf0737fcd Test matrix convert for ValueError: image has wrong mode 2017-01-29 15:55:17 +02:00
hugovk
90dac5f4dc Refactor and test matrix convert with RGB and L modes 2017-01-29 14:24:49 +02:00
hugovk
cea36587ab Test matrix convert 2017-01-29 14:03:38 +02:00
wiredfool
0a922b962f tests for basic operations on 0x0 images 2016-12-31 13:19:29 +00:00
homm
1ba4e9e5ba remove end of file banner from all files 2016-07-10 14:11:28 +03:00
homm
9c3bd46b36 improve test: compare all pixels, do not take color into account 2016-06-30 16:59:04 +03:00
Diederik Veeze
95de0b6d05 Testing for p2la 2016-06-26 13:23:42 +02: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
cf04a9a0d2 Remove unused tearDownModule 2014-07-07 20:03:50 +03:00
hugovk
78003ca473 Update paths to Tests/images/ instead of Images/ 2014-06-23 09:19:29 +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
hugovk
a59bc40c38 flake8 2014-05-17 23:33:50 +03:00
hugovk
55b1accb42 Add (failing) test for #664 2014-05-17 19:08:08 +03:00
wiredfool
182e7782fa Trapping warnings 2014-03-30 09:26:03 -07:00
wiredfool
8adbaf8098 Better tests, fixes for leaking RGB->P transparency 2014-03-26 00:01:10 -07:00
wiredfool
89c24e971c Tests for #510 2014-03-25 23:33:49 -07:00
wiredfool
9518214980 Tests for #544 2014-03-25 21:42:40 -07:00
wiredfool
0ffc1a848a Renamed test tiff files to 16bit*. They are 12bit data in a 16bit format 2013-11-19 14:48:01 -08:00
wiredfool
5b269a6ab7 small test image for I;16 => F conversion 2013-07-08 23:26:45 -07:00