Commit Graph

31 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
Hugo
affade7595 Replace unittest with pytest 2020-02-13 12:15:05 +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
Andrew Murray
47b2ae9a63 Raise a specific exception if no data is found for an MPO frame 2019-11-30 11:05:36 +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
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
64910d1921 Parse Nintendo and Fujifilm MakerNote tags 2019-03-28 21:13:12 +11:00
Andrew Murray
a5b62857b0 Change size of MPO image to match frame 2019-03-28 08:33:17 +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
Andrew Murray
47775f3d50 Resolve __fp when closing and deleting 2018-11-17 21:56:06 +11:00
Andrew Murray
f61b70aa8f Changed EOFError tests 2017-09-30 13:33:06 +10:00
Andrew Murray
e8cba27bb1 Changed assert checks to more specific versions 2017-06-03 14:04:54 +10:00
homm
1ba4e9e5ba remove end of file banner from all files 2016-07-10 14:11:28 +03:00
Andrew Murray
d20eef450b Added is_animated 2015-06-30 13:25:00 +10:00
Andrew Murray
1111e9fb35 Fixed frame position when seeking past the end of file 2015-06-19 00:49:18 +10:00
Andrew Murray
46f439604c Added tests 2015-06-08 01:02:43 +10:00
Andrew Murray
ee34d6843b Further health fixes 2015-04-24 18:24:52 +10:00
hugovk
1335006cd7 flake8 2014-08-28 14:44:19 +03:00
Eric W. Brown
b46f5c6b1e Better documented limited MPO save feature.
At present it’s only possible to save the current frame of an MPO, not
the MPO in its entirety. Added testing verifying as much.
2014-07-30 09:17:36 -07:00
Eric W. Brown
3b3f58d1bc Changed PIL to Pillow for newly supported formats. 2014-07-25 14:47:07 -04:00
Eric W. Brown
a5683ab574 Implemented MP attribute breakdown with tests. 2014-07-24 15:00:19 -04:00
Eric W. Brown
8d7266afc5 Fixed typo in new MPO unit test. 2014-07-23 11:36:23 -04:00
Eric W. Brown
832e11bed5 Enabled seeking in MPO files.
Note to self: either put the offset in the load_seek() definition or
the tile definition, not both.
2014-07-23 11:27:46 -04:00
Eric W. Brown
d5909e4946 Basic MPO reading works, seek is partially there. 2014-07-22 13:31:51 -04:00
Eric W. Brown
53b7f6294b First steps toward MPO support.
Allows Pillow to distinguish between JPEGs and MPOs, and provides some
MPO metadata handling. Does not yet handle multiple frames.
2014-07-16 11:36:56 -04:00