Commit Graph

46 Commits

Author SHA1 Message Date
Andrew Murray
6863c87c01 Added test for non-colormap 16-bit image 2024-06-26 08:32:57 -05:00
Andrew Murray
3840255486 Invert alpha bit for map depth 16 2024-06-25 10:48:34 -05:00
Hugo van Kemenade
d8c8075061
Merge pull request #7797 from radarhere/tga_palette 2024-03-11 17:37:20 +02:00
Andrew Murray
e39765d755 Added type hints 2024-02-20 15:41:20 +11:00
Andrew Murray
818500b329 Raise an error if map depth is unknown 2024-02-14 07:10:44 +11:00
Andrew Murray
63987b7aba Set mode to L if palette is missing 2024-02-14 06:55:13 +11:00
Hugo van Kemenade
4a4b90c365
Autotype tests (#7756)
* autotyping: --none-return
* autotyping: --scalar-return
* autotyping: --int-param
* autotyping: --float-param
* autotyping: --str-param
* autotyping: --annotate-named-param tmp_path:pathlib.Path
2024-01-31 20:12:58 +11:00
Hugo van Kemenade
53c3cd9f8e isort Tests 2024-01-20 13:23:03 +02:00
Hugo van Kemenade
43b2f61e79 Add 'from __future__ import annotations' using Ruff/isort 2023-12-21 13:13:31 +02:00
Aarni Koskela
43128ce716 Fix up pytest.warns lambda: uses 2023-02-23 16:06:40 +02:00
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
Hugo van Kemenade
50e0c85380
Merge pull request #6500 from radarhere/tga 2022-09-16 16:29:44 +03:00
Andrew Murray
0ed03d4a58 Parametrize tests 2022-08-23 21:41:32 +10:00
Andrew Murray
99e401123b Corrected palette size when saving 2022-08-13 19:46:07 +10:00
Andrew Murray
f0353c5996 When reading past the end of a scan line, reduce bytes left 2022-05-17 11:53:24 +03:00
Andrew Murray
0d729941a8 Handle packets that cross scan lines 2022-02-25 09:41:16 +11:00
Andrew Murray
fc90a9285a Added support for top right and bottom right orientations 2021-11-11 21:53:28 +11:00
Andrew Murray
f45d2e296d Ensure palette string matches RGB mode 2021-06-19 09:16:05 +10:00
Hugo van Kemenade
fc08a72600
Merge pull request #5400 from radarhere/mapdepth_16
Changed mode for TGA 16-bit palette to BGR;15
2021-04-18 13:00:29 +03:00
Andrew Murray
fc64064387 Changed mode for 16-bit palette to BGR;15 2021-04-10 22:11:20 +10:00
Andrew Murray
04df6e3bf1 mapdepth is only 1 byte 2021-04-09 21:38:28 +10:00
Hugo van Kemenade
e0eec1eb56 Merge branch 'master' into rm-3.5 2020-09-01 20:16:46 +03:00
Hugo van Kemenade
10615a7da7 Upgrade Python syntax for 3.6+
Co-authored-by: nulano <nulano@nulano.eu>
2020-07-30 10:09:18 +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
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
dbd3c7c9b9 Test saving with incorrect mode 2020-01-14 21:38:17 +11: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
8f34621c14 Added mime type tests 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
325ca3cede Trim id_section if it is greater than 255 characters 2018-09-08 08:26:32 +10:00
Andrew Murray
9e4c54e10f Added orientation, compression and id_section as keyword arguments 2018-09-08 08:12:26 +10:00
Daniel Plakhotich
adfcbc9478 Add LA to TGA test modes 2018-07-02 00:50:02 +03:00
Hugo
af552801c2
Merge pull request #3186 from danpla/tga-write-rle
TGA: Add support for writing RLE data
2018-07-01 22:00:03 +03:00
Daniel Plakhotich
1d20056234 TGA: Add support for writing RLE data 2018-06-15 23:01:06 +03:00
Daniel Plakhotich
39fae6e077 TGA: Read and write LA data 2018-06-14 12:18:08 +03:00
hugovk
31b05ce82c Test TGA RLE file 2016-04-21 17:49:35 +03:00
Andrew Murray
309ab1fc3d Various Flake8 fixes 2015-07-03 16:22:56 +10:00
Andrew Murray
a06b59bd52 Added various tests 2015-07-03 15:03:25 +10:00
Alexey Buzanov
5dd0d377c9 rename test 2014-08-20 10:39:11 +04:00
Alexey Buzanov
f94b6b4025 flake8 and tests 2014-08-20 10:32:06 +04:00