Commit Graph

74 Commits

Author SHA1 Message Date
pre-commit-ci[bot]
24183d652e [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2023-02-06 19:27:19 +00:00
Andrew Murray
886fcbe3d6 Do not open images with zero or negative height 2022-05-04 21:25:40 +10:00
Hugo van Kemenade
d3c9a6504e Variable in function should be snake_case 2022-04-10 23:55:16 +03:00
Andrew Murray
a606fd85a3 Run encoder cleanup method after errors as well 2022-02-28 14:12:56 +11:00
Andrew Murray
a0e1fde1ed Added PyEncoder 2022-02-25 16:07:01 +11:00
Andrew Murray
afb7728b8c Moved unrelated tests out of TestPyDecoder 2022-02-25 09:41:39 +11:00
Andrew Murray
f8e4e9c2dd Added enums 2022-01-15 09:02:31 +11:00
Andrew Murray
d8f2fb50a4
Merge pull request #5404 from radarhere/feed
Changed error type to allow for incremental WebP parsing
2021-12-29 07:33:56 +11:00
Andrew Murray
5c05fe4d9b Fixed raising OSError in _safe_read when size is greater than SAFEBLOCK 2021-12-07 11:40:44 +11:00
Andrew Murray
e444e7ab6d Removed ImageFile.raise_ioerror 2021-10-18 11:06:02 +11:00
Andrew Murray
bd298b128c Fixed default numresolution for small JPEG2000 images 2021-06-14 11:23:56 +10:00
Andrew Murray
35107e9637 Changed failure to create decoder to OSError for Parser 2021-04-14 20:01:56 +10:00
Andrew Murray
0af193afc0 Added test 2020-08-24 21:32:55 +10:00
Hugo van Kemenade
dd87dd50c0 Update to isort 5 with Black profile support 2020-08-08 22:39:29 +03:00
Andrew Murray
9432bba6d1 Moved tests 2020-07-02 20:28:00 +10:00
Rodrigo Benenson
83125b5ae4
Checks over exif instead of reloeaded_exif
test_imagefile.py checks exif instead of reloaded_exif; making the tests pass when they should not.
2020-04-28 18:58:26 +02:00
Andrew Murray
a0641b87c2 Assert that warning is raised 2020-04-20 19:27:09 +10:00
Hugo
270bc4fc60 Don't show own deprecation warning in test logs 2020-04-19 13:59:40 +03:00
Andrew Murray
7bb51a4aca Raise DeprecationWarning on raise_ioerror 2020-04-10 12:57:29 +03: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
a4bf9fa036 Convert most PillowTestCase methods to pytest 2020-02-02 12:26:01 +02:00
Alexander
ac92836e81 Change default resize resampling filter 2019-12-07 18:08:19 +03: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
Andrew Murray
87c43b66a5 Corrected negative seeks 2019-09-30 18:31:18 +10: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
5a668779e9 Added tests 2019-09-08 21:27:55 +10: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
5631718a8d Format with Black 2019-06-13 18:54:46 +03:00
Andrew Murray
3caec4344e Added get_ifd method to access embedded IFDs 2019-03-28 21:13:12 +11:00
Andrew Murray
d5db62be7b Added EXIF class 2019-03-28 21:13:12 +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
d69ef6a529 Remove redundant parentheses 2018-10-24 22:29:56 +03:00
Hugo
619e5fde8d Remove unused local variables 2018-10-24 22:29:01 +03:00
Andrew Murray
0adeb82e98 Changed Image size property to be read-only by default 2018-09-30 13:45:18 +10:00
Andrew Murray
c2189235af Line too long 2018-07-02 19:26:02 +10:00
Andrew Murray
6793b5bbd5 Added ImageFile get_format_mimetype method 2018-06-30 21:08:41 +10:00
Andrew Murray
2202196162 Flake8 blank line fixes 2018-03-04 21:36:33 +11:00
Andrew Murray
97662294f0 Added context manager support 2017-10-07 23:18:23 +11:00
Andrew Murray
9e843a2d9b Changed format of lambda calls 2017-09-01 21:05:40 +10:00
Joshua Blum
a6874f01ac Add test 2017-05-13 12:07:16 -04:00
Andrew Murray
37b293f593 Flake8 fixes 2017-04-20 21:14:23 +10:00
wiredfool
d718d351b1 Testing empty extents 2017-03-11 16:43:44 +00:00
wiredfool
382833061e Trigger set_as_raw error 2017-03-11 16:30:28 +00:00