Commit Graph

72 Commits

Author SHA1 Message Date
Andrew Murray
72b7ab54bd pre-commit autoupdate --freeze 2022-03-04 16:42:24 +11:00
Andrew Murray
dae1f691c2 Updated checks that no warnings were raised 2022-02-21 13:49:01 +11:00
Hugo van Kemenade
31a96b9c9b Upgrade Python syntax with pyupgrade --py36-plus and format with Black 2021-10-19 15:34:52 +03:00
Andrew Murray
b45fdd0817 Allow saving WebP with icc_profile None 2021-07-10 15:15:10 +10:00
Andrew Murray
4080f160b6 Include code in WebP error 2021-05-07 00:12:03 +10:00
Andrew Murray
1d8c5a820c Use duration from info dictionary when saving 2021-03-17 20:37:31 +11:00
Hugo van Kemenade
1857bf5570
Merge pull request #5259 from radarhere/warns 2021-02-17 21:31:15 +02:00
Andrew Murray
83542c42bf Added context managers 2021-02-11 21:43:54 +11:00
Andrew Murray
4a0569e97f Changed zero length assertions to falsy 2021-02-11 13:48:31 +11:00
Andrew Murray
01be700081 Fixed asserting that no warnings were raised 2021-02-10 23:37:55 +11:00
Hugo van Kemenade
dd87dd50c0 Update to isort 5 with Black profile support 2020-08-08 22:39:29 +03:00
nulano
d5a6b2584e add tests for version numbers 2020-06-21 18:59:01 +10:00
Andrew Murray
f17f1bc607 Added method argument to single frame WebP saving 2020-04-11 20:43:49 +10:00
Hugo
dda6145fce Since Python 3.3 IOError and WindowsError have been merged into OSError 2020-04-10 12:57:29 +03:00
Andrew Murray
7ff2db143d Removed use of PillowTestCase 2020-03-23 07:05:51 +11: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
Andrew Murray
666b726626 Simplified conditions 2019-12-25 15:32:38 +11: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
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
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
6c126ca282 Change color table index background to tuple when saving 2018-11-20 19:50:14 +11:00
Hugo
94c94eb1f7 flake8: E128 continuation line under-indented for visual indent 2018-11-11 19:01:11 +02:00
Hugo
ed10276a6b
Merge pull request #3418 from radarhere/webp_fp
Only close existing fp in WebP if fp is exclusive
2018-10-31 09:16:53 +02:00
Andrew Murray
c7d924fd85 Too many blank lines 2018-10-21 18:11:50 +11:00
Andrew Murray
e84a78d828 Only close existing fp if fp is exclusive 2018-10-19 20:12:08 +11:00
Alexander
e26696cb8a skip old test 2018-10-18 10:33:52 +03:00
Alexander
e7aa44f58c add test for regression 2018-10-18 10:32:17 +03:00
Andrew Murray
82d942c3d8 Added warnings if image file identification fails due to lack of support 2018-09-30 15:34:27 +10:00
Andrew Murray
a8261a2e89 Line too long 2018-09-27 20:35:00 +10:00
Hugo
521ae77bb9
Merge pull request #3298 from kkopachev/webp-rgb
Read/save RGB webp as RGB (instead of RGBX)
2018-09-17 12:05:07 +03:00
Andrew Murray
9d9da79caa Close existing fp before setting new fp 2018-09-08 23:08:17 +10:00
Konstantin Kopachev
84b32a0388
Read/Save RGB webp as RGB (instead of RGBX) 2018-08-09 11:40:10 -07:00
Jason Douglas
cf31e70735 Fixing a typo in comments 2017-10-03 08:05:20 -07:00
Jason Douglas
28bec69e98 - flake8 formatting fixes
- webp => WebP doc and comment changes
2017-10-01 15:23:18 -07:00
Jason Douglas
5b2dd29f44 Fix invalid_args test for older versions of libwebp 2017-09-27 20:21:18 -07:00
Jason Douglas
80b96246c4 Fix tests to support different output modes (RGB vs RGBX) 2017-09-27 19:28:43 -07:00
Jason Douglas
e534991409 - Styling changes to be C89-conformant
- Change WebPAnimEncoder/Decoder to use RGBX mode instead of RGB (since internally it is using RGBA always)
2017-09-27 17:10:25 -07:00
Jason Douglas
cd12a48fe0 - Support non-alpha modes with WebPAnimDecoder
- Support writing metadata chunks with WebPAnimEncoder
- Add XMP metadata support to legacy WebPEncode wrapper
- Cleanup unused mux code in legacy WebPDecode wrapper
- Fix some bugs present when compiled without WebP Mux support
- Fix conversion from L/P/PA modes when saving WebP files
- Update existing tests, and add new ones for WebP animation and metadata support
2017-09-26 20:27:40 -07:00
Andrew Murray
9e843a2d9b Changed format of lambda calls 2017-09-01 21:05:40 +10:00
adw1n
6ce11c9e8c Added tests that call _webp.WebPEncode and _webp.WebPDecode with invalid number of arguments. 2017-05-12 17:11:58 +02:00
homm
1ba4e9e5ba remove end of file banner from all files 2016-07-10 14:11:28 +03:00
Andrew Murray
a06b59bd52 Added various tests 2015-07-03 15:03:25 +10:00
Hugo
ae7b765b53 Fix some Landscape.io errors and warnings 2014-10-01 16:50:33 +03:00