Commit Graph

68 Commits

Author SHA1 Message Date
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
Jon Dufresne
63729766c4 Remove unnecessary coerce to float
In Python 3, the division operator is floating point division. No longer
need to coerce integers to floating point numbers before division.
2020-01-26 06:33:18 -08: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
5631718a8d Format with Black 2019-06-13 18:54:46 +03:00
Hugo
3ff70c2afc
Merge branch 'master' into imagecms-deprecations 2019-02-13 15:45:28 +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
Hugo
a2a5ebfeb4 Refactor 2019-01-28 15:40:19 +02:00
Hugo
a9070f3ca2 Group deprecation tests 2019-01-28 15:40:19 +02:00
Hugo
3476474359 Add warnings to deprecated CMS profile attributes 2019-01-28 15:40:19 +02:00
Hugo
e1381d2102 Add warnings to deprecated CMS profile attributes 2019-01-28 15:40:19 +02:00
Hugo
a149c13d2e Add warnings to deprecated CMS profile attributes 2019-01-28 15:40:19 +02:00
Hugo
7d157bd825 Add warnings to deprecated CMS profile attributes 2019-01-28 15:40:19 +02:00
Hugo
e7eac4f80b Add warnings to deprecated CMS profile attributes 2019-01-28 15:40:19 +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
Hugo
ceebfc6fe8 flake8: E501 line too long 2018-11-11 19:01:11 +02:00
Hugo
94c94eb1f7 flake8: E128 continuation line under-indented for visual indent 2018-11-11 19:01:11 +02:00
Hugo
717add44b0 flake8: E201 whitespace after '(' 2018-11-11 19:01:11 +02:00
Hugo
eb9aee7048 flake8: F841 local variable is assigned to but never used 2018-11-11 19:01:10 +02:00
Andrew Murray
9b0d4baa8c Continuation line under-indented for visual indent 2018-09-27 20:31:01 +10:00
Andrew Murray
c2189235af Line too long 2018-07-02 19:26:02 +10:00
Andrew Murray
145589ef14 Ambiguous variable name 'l' 2018-07-02 19:21:44 +10:00
Hugo
ecc4c7fecc Remove unittest regex deprecation warnings 2018-04-14 21:54:40 +03:00
Andrew Murray
2202196162 Flake8 blank line fixes 2018-03-04 21:36:33 +11:00
Andrew Murray
9e843a2d9b Changed format of lambda calls 2017-09-01 21:05:40 +10:00
Andrew Murray
371933a597 Added tests 2017-09-01 20:36:51 +10:00
Alexander
349e300d7b use getchannel where is possible 2017-08-09 02:36:07 +03:00
Andrew Murray
e8cba27bb1 Changed assert checks to more specific versions 2017-06-03 14:04:54 +10:00
Andrew Murray
37b293f593 Flake8 fixes 2017-04-20 21:14:23 +10:00
Andrew Murray
18fea70b51 Removed unused variable 2017-03-03 21:38:19 +11:00
Jarkko Pöyry
fa56b3d255 Add tests for CMS transform auxiliary channel preservation. See bug #1662. 2017-01-28 22:04:49 +02:00
Alexander
ba92896a53 remove old version 2016-12-07 04:39:36 +03:00
wiredfool
9440764863 Merge pull request #2131 from wiredfool/imagecms-segfault
Fix for ImageCms Segfault
2016-10-03 06:02:39 -07:00
Tim Graham
0c66b80a95 Fix "invalid escape sequence" warning in Python 3.6
http://bugs.python.org/issue27364
2016-09-27 19:26:57 -04:00
wiredfool
1d068b6e0a Check type of items passed into to ImageCms.ImageCmsProfile, fixes #2037 2016-09-26 14:56:00 -07:00
Andrew Murray
72d5218080 Flake8 fixes 2016-09-03 12:17:22 +10:00
homm
1ba4e9e5ba remove end of file banner from all files 2016-07-10 14:11:28 +03:00
wiredfool
c057c4238e Fix 2 more failing tests on 32 bit due to float precision 2016-06-30 06:38:31 -07:00
AbdealiJK
356926f825 test_imagecms: Reduce precision of extended info
In 32bit computers (when making wheels) it was found that the
precision of the extended information in test_extended_information() was
found to be lesser than what was being tested. This commit adds a helper
function which reduces the precision by truncating (multiplying by
10 ** digits, truncating to int and dividing by 10 ** digits) and then
testing the rtruncated numbers rather than the original numbers.
2016-06-28 21:14:34 +05:30
wiredfool
3926bfb747 Skip test when icc profile is not available, fixes #1887 2016-05-06 08:58:40 -07:00
Marcus Brinkmann
87603266ad Give much more details about ICC profiles. 2016-03-05 04:40:24 +01:00
Andrew Murray
d1c182cadc Various Flake8 fixes 2015-04-24 09:26:52 +10:00
Andrew Murray
192fa39fb7 Fixed duplicate import in test_imagecms 2015-04-01 09:56:12 +11:00
wiredfool
460160a1e3 Updated merge from master 2014-09-26 16:07:52 -07:00
wiredfool
af138af779 Use lcms profile where possible, otherwise skip test if sRGB profile is not available 2014-09-24 21:48:56 -07:00
Hugo
781da7d465 Replace lena.Lab.tif with hopper.Lab.tif + flake8 2014-09-23 13:45:32 +03:00
hugovk
a2e729f487 Replace some lena with hopper 2014-09-14 22:58:23 +03:00