Commit Graph

119 Commits

Author SHA1 Message Date
Hugo
2cc6a9a974 Convert to use pytest 2020-03-02 16:31:08 +02:00
Hugo
699a9dadf1 Convert asserts 2020-02-22 18:07:04 +02:00
Andrew Murray
8482919a37 Converted most assert statements to pytest 2020-02-23 00:06:21 +11:00
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
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
Hugo
f96763826c Test on new Travis CPUs https://blog.travis-ci.com/2019-11-12-multi-cpu-architecture-ibm-power-ibm-z 2020-01-08 15:43:27 +02: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
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
Andrew Murray
4140cd807b
Merge branch 'master' into rm-2.7 2019-10-12 18:03:58 +11:00
Hugo
865b17d5cf Remove Python 2-compatibility code 2019-10-07 16:23:22 +03:00
Hugo
af770a6c55 Drop support for EOL Python 2.7 2019-10-07 14:30:59 +03:00
nulano
cf1f8b0498 Tests.helper cleanup 2019-09-25 11:58:02 +02: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
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
8a035b8c5d Improved I mode conversion 2019-05-08 21:58:33 +10:00
Andrew Murray
c96cdb5e77 Consistent DPI rounding 2019-03-30 15:03:57 +11:00
Andrew Murray
4a5666f1f4 Added transparency for all PNG greyscale modes 2019-03-27 07:41:33 +11:00
Andrew Murray
ce9dd67540 Added I;16 PNG save 2019-03-12 17:28:42 +11:00
Andrew Murray
8ddcc1de52 Load EXIF from PNG where eXIf chunk is after first IDAT chunk 2019-03-11 21:20:18 +11:00
Andrew Murray
365d5e541a Added EXIF support 2019-03-11 21:19:36 +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
Hugo
d02e2b5392
Merge pull request #3558 from radarhere/png
Allow for unknown PNG chunks after image data
2019-02-03 11:57:21 +02: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
4e0a73b4fa Allow for unknown PNG chunks after image data 2019-01-08 07:21:25 +11:00
Hugo van Kemenade
22b0f53eb9
Merge pull request #3532 from radarhere/png_load_end_idat
PNG: Handle IDAT chunks after image end
2019-01-05 12:08:58 +02:00
Andrew Murray
ea2a0e4654 Handle IDAT chunks after image end 2019-01-03 19:13:19 +11:00
Andrew Murray
97ae0c42b1 Detect whether mimetype is image/png or image/apng 2019-01-02 14:13:10 +11:00
Andrew Murray
21268c87b3
Merge branch 'master' into patch-2 2018-12-27 17:39:40 +11:00
Andrew Murray
f9ce201cf0 Test APNG image for similarity 2018-12-27 12:19:44 +11:00
pirate486743186
8d0b7e6b57 adding apng extension for png 2018-12-26 21:14:27 +01:00
Andrew Murray
22837c37e2 Read textual chunks located after IDAT chunks 2018-12-24 23:58:19 +11:00
Andrew Murray
b637b5f7a2 Close exclusive fp before discarding 2018-11-13 22:13:55 +11:00
Hugo
619e5fde8d Remove unused local variables 2018-10-24 22:29:01 +03:00
Andrew Murray
c2189235af Line too long 2018-07-02 19:26:02 +10:00
Daniel Plakhotich
65c7875ff7 TestFilePng: Fix test_save_l_transparency()
It now really tests the file after saving.
2018-06-14 12:46:35 +03:00
Andrew Murray
b4e6cdadac Added py3 variable to _util 2018-04-20 09:19:13 +10:00
Andrew Murray
b560f5b417 Changed Python version checks in tests to use helper 2018-04-19 19:40:56 +10:00
Hugo
ecc4c7fecc Remove unittest regex deprecation warnings 2018-04-14 21:54:40 +03:00
Andrew Murray
4a781d0013 Replaced MacOS with macOS 2018-03-19 19:38:17 +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
Eric Soroos
a96ac321d5 merge error 2017-12-20 11:45:52 +00:00
Eric Soroos
25d961238c Added sRGB and cHRM chunks to PngInfo, added tests for #2782 2017-12-20 11:35:11 +00:00
Eric Soroos
1ea128c8a7 refactor out get_chunks 2017-12-20 11:33:22 +00:00
Jon Dufresne
8844e2dd71 Make PngImagePlugin.add_text() zip argument type bool
Always used as a bool, but was previously defined as 0/1. Use modern
idiomatic Python by using the bool type for bool arguments.
2017-12-16 09:13:45 -08:00
Andrew Murray
97662294f0 Added context manager support 2017-10-07 23:18:23 +11:00