Commit Graph

118 Commits

Author SHA1 Message Date
Jon Dufresne
4f185329f4 Streamline test skipping based on supported features
This adds a new test decorator: skip_unless_feature(). The argument is
the same as passed to features.check(). If the feature is not supported,
the test will be skipped.

This removes several kinds of boilerplate copied and pasted around tests
so test feature checking is handled and displayed more consistently.

Refs #4193
2020-02-18 13:07:01 -08:00
Jon Dufresne
98a2081a78 Move safe imports to the top of test files
These modules are safe to import and this better follows PEP 8.

From https://www.python.org/dev/peps/pep-0008/#imports

> Imports are always put at the top of the file, just after any module
> comments and docstrings, and before module globals and constants.
2020-02-17 10:49:27 -08:00
Hugo van Kemenade
098406c304
Merge pull request #4390 from jdufresne/resource-warning
Fix ResourceWarning emitted during tests
2020-02-12 17:10:51 +02:00
Hugo
38bf862185 Replace PillowTestCase.assert_warning with pytest.warns 2020-02-03 11:11:32 +02:00
Hugo
a4bf9fa036 Convert most PillowTestCase methods to pytest 2020-02-02 12:26:01 +02:00
Jon Dufresne
2b84221edf Fix ResourceWarning emitted during tests
Appeared in the form:

    ResourceWarning: unclosed file <_io.BufferedReader name='Tests/images/invalid-exif-without-x-resolution.jpg'>

Enable all warnings to always display during tests to help catch these
warnings earlier.
2020-01-26 16:00:46 -08:00
Alexander
73171f5046 add test image 2020-01-20 17:25:40 +03:00
Andrew Murray
ee30fe1b39
Merge pull request #4147 from beipang2/issue_4146
Use default DPI when exif provides invalid x_resolution
2019-12-25 20:26:27 +11:00
Andrew Murray
2d7cfc4bbc
Merge pull request #4239 from radarhere/photoshop
Handle broken Photoshop data
2019-12-01 07:33:26 +11:00
Andrew Murray
e51be50549 Handle broken Photoshop data 2019-11-30 10:08:32 +11:00
Andrew Murray
c0048ad7de Use context managers 2019-11-26 07:03:23 +11:00
Bei Pang
f53b86b673 Removed TypeError exception check in JpegImagePlugin; Updated comments in test 2019-10-28 09:48:37 -07:00
Bei Pang
bcc766e02d Use default DPI when exif provides invalid x_resolution 2019-10-27 07:50:30 +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
nulano
cf1f8b0498 Tests.helper cleanup 2019-09-25 11:58:02 +02: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
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
f87821e010 Format with Black 2019-06-13 18:54:11 +03:00
Andrew Murray
2274c2afc7 Fixed reading APP13 marker without Photoshop data 2019-04-05 20:02:45 +11:00
Andrew Murray
c96cdb5e77 Consistent DPI rounding 2019-03-30 15:03:57 +11:00
Andrew Murray
636ad68f5e Read Photoshop resolution data 2019-03-06 10:28:45 +11:00
Hugo
dc3c64a0e3
Merge pull request #3631 from jdufresne/test-main
Remove unnecessary unittest.main() boilerplate from test files
2019-02-12 18:12:29 +02:00
Hugo
4ccdbf25cf
Merge pull request #3584 from radarhere/ifd_offset
Seek to IFD offset
2019-02-12 18:10:25 +02: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
Andrew Murray
0481d0ac1e Seek to IFD offset 2019-01-16 06:55:37 +11: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
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
aeab86c005 Too many blank lines 2018-07-02 19:21:44 +10:00
Andrew Murray
6793b5bbd5 Added ImageFile get_format_mimetype method 2018-06-30 21:08:41 +10:00
Andrew Murray
9a3d554c1d Changed Exception tests to be more specific 2018-06-12 04:41:31 +10:00
Hugo
ecc4c7fecc Remove unittest regex deprecation warnings 2018-04-14 21:54:40 +03:00
wiredfool
d173e81798
Merge pull request #3023 from kkopachev/issue-3022
Certain corrupted jpegs can result in no data read
2018-03-21 07:55:17 +00:00
Konstantin Kopachev
5269bbc268
Add truncated jpeg tests 2018-03-07 21:31:51 -08:00
Andrew Murray
c13ccf13a1 Added missing whitespace 2018-03-06 19:53:07 +11:00
Andrew Murray
cca94054aa Changed assert statements to unittest calls 2018-01-17 22:01:37 +11:00
Andrew Murray
30b2ddd070 Removed duplicate imports 2018-01-04 15:40:46 +11: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
Alexander
4d56db3a34 Fix wrong formula for subsampling=2 while JPEG saving 2017-08-27 20:03:36 +03:00
Vytis Banaitis
7c8e0e4457 Fix ZeroDivisionError when EXIF contains invalid DPI (0/0). 2017-08-09 16:16:14 +03:00
wiredfool
908fffdd2c Test for https://github.com/python-pillow/Pillow/issues/2628#issuecomment-315962612 2017-07-18 01:06:54 -07:00
Fran Barba
29c622dd3d Fixed typo biger > bigger 2017-06-29 11:21:19 +02:00
Fran Barba
a7d75c4b21 Applied Hugovk recommendations 2017-06-28 12:12:44 +02:00
Fran Barba
ebaa509d66 Adjust buffer size when icc_profile > MAXBLOCK (issue #148)
We were encountering some errors when saving specific JPEG images.
The error was shown in stderr as:
  IOError: encoder error -2 when writing image file

And on stdout it printed:
    Suspension not allowed here

The problem was the bufsize not contemplating the icc_profile block.
2017-06-28 12:11:33 +02:00
wiredfool
c3e041e9e6 Merge branch 'master' into rm-deprecated-fn 2017-06-13 13:32:38 +01:00
wiredfool
c16ba722f2 Merge pull request #2551 from jdufresne/keys
Remove unnecessary calls to dict.keys()
2017-06-13 13:12:48 +01:00
Andrew Murray
e8cba27bb1 Changed assert checks to more specific versions 2017-06-03 14:04:54 +10:00
Jon Dufresne
d244fbb299 Remove unnecessary calls to dict.keys()
iter(dict) is equivalent to iter(dict.keys()), so simply act on the dict
instead of adding the extra call.

Inspired by Lennart Regebro's PyCon 2017 presentation "Prehistoric
Patterns in Python". Available at:

https://www.youtube.com/watch?v=V5-JH23Vk0I
2017-05-28 09:55:38 -07:00
hugovk
e4d6223c94 Remove deprecated code due for removal in Pillow 4.2 (per PR #2010) 2017-05-27 23:20:03 +03:00