Commit Graph

72 Commits

Author SHA1 Message Date
Andrew Murray
c0048ad7de Use context managers 2019-11-26 07:03:23 +11:00
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
538d9e2e5d Upgrade Python syntax with pyupgrade --py3-plus 2019-10-07 14:30:59 +03:00
Hugo van Kemenade
572a93c86f
Corrected tag counts (#4033)
Corrected tag counts
2019-09-05 22:41:16 +03:00
Andrew Murray
35a7d11f43 Fixed typo [ci skip] 2019-08-29 19:02:19 +10:00
Andrew Murray
f08a0966a0 Corrected tag counts 2019-08-19 21:12:16 +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
f87821e010 Format with Black 2019-06-13 18:54:11 +03: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
Andrew Murray
990fb03218 Changed if to elif 2018-11-12 06:14:04 +11:00
Hugo
088d04470e Unnecessary list comprehension - 'tuple' can take a generator 2018-10-24 22:29:56 +03:00
Andrew Murray
a8261a2e89 Line too long 2018-09-27 20:35:00 +10:00
Jon Dufresne
875e8c4bda Avoid catching unexpected exceptions in tests
Instead, allow exceptions to bubble up to the unittest exception
handler.

Prevents replacing the exception trace with a less informative
message. As the exceptions are always unexpected, should not need to
catch them explicitly in tests.
2018-09-04 19:43:20 -07:00
Andrew Murray
c13ccf13a1 Added missing whitespace 2018-03-06 19:53:07 +11: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
Eric Soroos
c12b9fb4dc added test for metadata count warning 2017-09-19 10:35:14 +00:00
Eric Soroos
56e490fe7c Test for issue #2278 2017-09-14 20:05:13 +01:00
Eric Soroos
843f8b2a6b Test for ImageJMetaDataByteCounts, #2006 2017-09-14 20:05:13 +01:00
Eric Soroos
83c57a8063 Specific change for issue #2006, ImageJ Metadata counts are incorrect in TiffTags 2017-09-14 20:05:13 +01:00
Eric Soroos
488691bda4 General fix for issue #2278, #2006, ValueError with out of spec metadata 2017-09-14 20:05:13 +01:00
Andrew Murray
9e843a2d9b Changed format of lambda calls 2017-09-01 21:05:40 +10:00
Andrew Murray
b82151f281 Removed unused division import 2017-01-18 20:06:47 +11:00
Jon Dufresne
dbe9f85c7d Drop support for Python 2.6
* Drop unittest2 requirement
* Use set literals
* Use dict/set comprehension
* Use str.format() automatic numbering
2016-11-22 04:23:55 -08:00
Jon Dufresne
e44bb42ae9 Replace type() equality checks with isinstance 2016-10-31 06:41:43 -07:00
wiredfool
4a90e8f75b Merge pull request #2024 from uploadcare/fix-empty-exif-tags
Skip empty values in ImageFileDirectory
2016-09-29 08:24:44 -07:00
homm
7a4847f457 all literals are bytes 2016-07-12 22:54:15 +03:00
homm
107307dfc9 do not use as_dict anywhere in tests except tests for as_dict warnings 2016-07-12 21:34:15 +03:00
homm
c2b4ff5fa4 skip empty values in ImageFileDirectory 2016-07-12 18:09:02 +03:00
homm
1ba4e9e5ba remove end of file banner from all files 2016-07-10 14:11:28 +03:00
wiredfool
a64c1674a1 Tests for issue #1462, #1834, #1831, #1910 2016-06-26 12:05:05 +01:00
wiredfool
1e2a27f00d Fixed broken test re: https://github.com/python-pillow/Pillow/issues/1462#issuecomment-210487186 2016-06-26 12:02:45 +01:00
Andrew Murray
677b958a7f Health fixes 2016-04-01 21:49:30 +11:00
wiredfool
3ac9396e8c Write round trip for rationals, including nan value 2015-12-29 22:00:36 +00:00
wiredfool
3dd4b39411 Namespace 2015-12-29 21:33:10 +00:00
wiredfool
5e7a5bf237 Limit rationals for expected values in round trip 2015-12-29 21:33:10 +00:00
wiredfool
8ed2d1ed02 Changing the type of the target values 2015-12-27 20:48:47 +00:00
wiredfool
deecbcd3a3 Added a rational class for TiffIFD that allows for 0/0 2015-12-27 10:21:31 +00:00
Andrew Murray
afa4166a57 Updated deprecated asserts 2015-12-16 14:30:17 +11:00
Andrew Murray
c27110ab56 Flake8 fixes 2015-12-10 21:34:02 +11:00
wiredfool
f8a5ded0d6 Test for #1526, load binary tagged iccprofile 2015-11-15 16:41:49 +00:00
wiredfool
5e670e9b70 using test file with known license 2015-10-03 17:04:40 -07:00
wiredfool
157df44e51 Add tag info for iccprofile, fixes #1462 2015-10-03 16:35:53 +01:00
homm
9930b05a33 fix tiff exif loading in case when file is empty or ended 2015-09-15 04:06:51 +03:00
wiredfool
4596df45c1 Versioned interface for TiffTags 2015-09-13 15:15:13 +01:00
wiredfool
2636679868 updating tests for legacy_api api change 2015-09-13 14:08:49 +01:00
wiredfool
0c35194167 rewrite of #1416 working 2015-09-12 10:11:10 +01:00
wiredfool
b1fdff4034 In a twisty maze of bytes, text and arbitrary metadata, py2 and py3. New IFD is putting textdata in type7 metadata and returning bytes, old one put it in type 2 string and returned a string. This may be an issue 2015-09-11 23:44:23 +01:00