Commit Graph

44 Commits

Author SHA1 Message Date
Andrew Murray
55be0ae6f4 Parametrized test 2022-03-14 08:07:13 +11:00
Andrew Murray
4283a604c0 Added support for arbitrary maxval 2022-03-09 22:29:45 +11:00
Andrew Murray
d96830115f Updated tests 2022-03-04 15:22:41 +11:00
Andrew Murray
65edcc4f77 Merge branch 'main' into PPMheaders 2022-03-04 12:30:41 +11:00
Andrew Murray
1b397751ec
Added context managers 2021-08-24 23:43:38 +10:00
Yutao Yuan
0f11d22cce Add tests for saving to stdout 2021-08-10 19:12:20 +08:00
Piolie
8ad5172e88 Fix wrong extension in temp test files 2021-03-21 02:16:39 -03:00
Andrew Murray
41a439da7d Added context managers 2021-03-21 14:42:36 +11:00
Andrew Murray
a5c251029c Replaced various instances of assert_image_equal with assert_image_equal_tofile 2021-02-21 22:15:56 +11:00
Andrew Murray
83542c42bf Added context managers 2021-02-11 21:43:54 +11:00
Piolie
bc5ecfb79c Make minor changes to tests
- add test for maxcolors;
- extend coverage for wrong magic number;
- fix linting.
2021-01-06 14:53:30 -03:00
Piolie
002e0bd697 Add tests for token size and wrong magic number 2021-01-06 01:21:35 -03:00
Piolie
5d0ad5e2e9 Revert exception types to ValueError 2021-01-06 01:21:01 -03:00
Piolie
699afe1e89 Improve PPM tests 2020-12-21 22:39:32 -03:00
Hugo van Kemenade
dd87dd50c0 Update to isort 5 with Black profile support 2020-08-08 22:39: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
09b9198176 Converted to pytest 2020-02-25 20:57:27 +11:00
Andrew Murray
8482919a37 Converted most assert statements to pytest 2020-02-23 00:06:21 +11:00
Hugo
a4bf9fa036 Convert most PillowTestCase methods to pytest 2020-02-02 12:26:01 +02:00
Andrew Murray
c0048ad7de Use context managers 2019-11-26 07:03:23 +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
7d3b8e8cea
Merge branch 'master' into mime-types 2019-03-06 07:08:00 +11:00
Andrew Murray
4be51c46eb Added mime types 2019-03-04 18:17:12 +11:00
Andrew Murray
873603701f Added .pnm test 2019-03-04 15:51:07 +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
Andrew Murray
9e843a2d9b Changed format of lambda calls 2017-09-01 21:05:40 +10:00
Andrew Murray
37b293f593 Flake8 fixes 2017-04-20 21:14:23 +10:00
Andrew Murray
a06dd59df7 Added context managers 2016-12-28 09:54:10 +11:00
Jon Dufresne
a33939f5c3 Remove unused, open files at top level of tests.
The data read from the file was unused. The files remained opened and
were never explicitly closed.

Fixes some instances of warnings during tests:

"ResourceWarning: unclosed file ..."
2016-11-01 06:34:17 -07:00
wiredfool
b3ad80a2bd Image.core.open_ppm has been removed. Test the Storage.c fix with an alternate method. Assert that the ordinary opener rejects the negative size in the PPM file 2016-10-03 07:27:02 -07:00
wiredfool
5d8a0be45a Memory error in Storage.c when accepting negative image size arguments 2016-10-03 07:27:02 -07:00
homm
1ba4e9e5ba remove end of file banner from all files 2016-07-10 14:11:28 +03:00
Andrew Murray
a0d38a3884 Fixed infinite loop on truncated file 2015-08-29 02:05:08 +10:00
Andrew Murray
ee34d6843b Further health fixes 2015-04-24 18:24:52 +10:00
hugovk
b929873a62 Change some lena() to hopper() 2014-09-05 12:36:24 +03:00
hugovk
cf04a9a0d2 Remove unused tearDownModule 2014-07-07 20:03:50 +03:00
hugovk
78003ca473 Update paths to Tests/images/ instead of Images/ 2014-06-23 09:19:29 +03:00
hugovk
3ec505958e Convert old tests to use unittest 2014-06-10 12:10:47 +03:00
wiredfool
2daac27713 Tests for writing hi bit pgm 2014-04-07 22:22:42 -07:00
wiredfool
864fb95cb1 Read test for 16 bit binary pgm file, #602 2014-04-07 22:10:45 -07:00
Brian Crowell
ad784eb808 py3k: Import Christoph Gohlke's test suite
This is Christoph Gohlke's test suite from his personal PIL package found
at http://www.lfd.uci.edu/~gohlke/pythonlibs/.

This is just to bring it in as a separate commit. Future commits will align
it with Pillow.
2013-01-10 08:46:39 -06:00