Pillow/Tests
Alexander Böhn 7b815a5f1d Added an image.entropy() method
This calculates the entropy for the image, based on the histogram.

Because this uses image histogram data directly, the existing C
function underpinning the `image.histogram()` method was abstracted
into a static function to parse extrema tuple arguments, and a new
C function was added to calculate image entropy, making use of the
new static extrema function.

The extrema-parsing function was written by @homm, based on the
macro abstraction I wrote, during the discussion of my first
entropy-method pull request: https://git.io/fhodS

The new `image.entropy()` method is based on `image.histogram()`,
and will accept the same arguments to calculate the histogram data
it will use to assess the entropy of the image.

The algorithm and methodology is based on existing Python code:

* https://git.io/fhmIU

... A test case in the `Tests/` directory, and doctest lines in
`selftest.py`, have both been added and checked.

Changes proposed in this pull request:

* Added “math.h” include to _imaging.c
* The addition of an `image.entropy()` method to the `Image`
  Python class,
* The abstraction of the extrema-parsing logic of of the C
  function `_histogram` into a static function, and
* The use of that static function in both the `_histogram` and
  `_entropy` C functions.
* Minor documentation addenda in the docstrings for both the
  `image.entropy()` and `image.histogram()` methods were also
  added.
* Removed outdated boilerplate from testing code
* Removed unused “unittest” import
2019-06-26 19:15:47 +10:00
..
fonts Do not presume that the last glyph has the max x value 2019-06-19 22:32:01 +10:00
icc Corrected filename [ci skip] 2016-05-03 19:23:51 +10:00
images Do not presume that the last glyph has the max x value 2019-06-19 22:32:01 +10:00
__init__.py Improve pytest configuration to allow specific tests as CLI args 2019-01-13 09:00:12 -08:00
32bit_segfault_check.py Format with Black 2019-06-13 18:53:42 +03:00
bench_cffi_access.py Format with Black 2019-06-13 18:53:42 +03:00
bench_get.py Format with Black 2019-06-13 18:53:42 +03:00
check_fli_overflow.py Format with Black 2019-06-13 18:53:42 +03:00
check_icns_dos.py Format with Black 2019-06-13 18:53:42 +03:00
check_imaging_leaks.py Format with Black 2019-06-13 18:53:42 +03:00
check_j2k_dos.py Format with Black 2019-06-13 18:53:42 +03:00
check_j2k_leaks.py Format with Black 2019-06-13 18:53:42 +03:00
check_j2k_overflow.py Format with Black 2019-06-13 18:53:42 +03:00
check_jpeg_leaks.py Format with Black 2019-06-13 18:53:42 +03:00
check_large_memory_numpy.py Format with Black 2019-06-13 18:53:42 +03:00
check_large_memory.py Format with Black 2019-06-13 18:53:42 +03:00
check_libtiff_segfault.py Format with Black 2019-06-13 18:53:42 +03:00
check_png_dos.py Format with Black 2019-06-13 18:53:42 +03:00
createfontdatachunk.py Remove unused 'sys' import 2018-12-04 23:25:28 +02:00
helper.py Format with Black 2019-06-13 18:53:42 +03:00
import_all.py Format with Black 2019-06-13 18:53:42 +03:00
make_hash.py Format with Black 2019-06-13 18:53:42 +03:00
README.rst Remove unnecessary unittest.main() boilerplate from test files 2019-02-03 10:10:16 -08:00
test_000_sanity.py Format with Black 2019-06-13 18:53:42 +03:00
test_binary.py Format with Black 2019-06-13 18:53:42 +03:00
test_bmp_reference.py Format with Black 2019-06-13 18:53:42 +03:00
test_box_blur.py Format with Black 2019-06-13 18:53:42 +03:00
test_color_lut.py Format with Black 2019-06-13 18:53:42 +03:00
test_core_resources.py Format with Black 2019-06-13 18:53:42 +03:00
test_decompression_bomb.py Format with Black 2019-06-13 18:53:42 +03:00
test_features.py Fixed black formatting 2019-06-22 14:47:56 +10:00
test_file_blp.py Remove unnecessary unittest.main() boilerplate from test files 2019-02-03 10:10:16 -08:00
test_file_bmp.py Format with Black 2019-06-13 18:53:42 +03:00
test_file_bufrstub.py Format with Black 2019-06-13 18:53:42 +03:00
test_file_container.py Format with Black 2019-06-13 18:53:42 +03:00
test_file_cur.py Format with Black 2019-06-13 18:53:42 +03:00
test_file_dcx.py Format with Black 2019-06-13 18:53:42 +03:00
test_file_dds.py Format with Black 2019-06-13 18:53:42 +03:00
test_file_eps.py Format with Black 2019-06-13 18:53:42 +03:00
test_file_fitsstub.py Format with Black 2019-06-13 18:53:42 +03:00
test_file_fli.py Format with Black 2019-06-13 18:53:42 +03:00
test_file_fpx.py Format with Black 2019-06-13 18:53:42 +03:00
test_file_ftex.py Format with Black 2019-06-13 18:53:42 +03:00
test_file_gbr.py Format with Black 2019-06-13 18:53:42 +03:00
test_file_gd.py Format with Black 2019-06-13 18:53:42 +03:00
test_file_gif.py Format with Black 2019-06-13 18:53:42 +03:00
test_file_gimpgradient.py Format with Black 2019-06-13 18:53:42 +03:00
test_file_gimppalette.py Format with Black 2019-06-13 18:54:11 +03:00
test_file_gribstub.py Format with Black 2019-06-13 18:54:11 +03:00
test_file_hdf5stub.py Format with Black 2019-06-13 18:54:11 +03:00
test_file_icns.py Merge remote-tracking branch 'upstream/master' into run-black 2019-06-19 09:29:28 +03:00
test_file_ico.py Format with Black 2019-06-19 09:30:10 +03:00
test_file_im.py Format with Black 2019-06-13 18:54:11 +03:00
test_file_iptc.py Format with Black 2019-06-13 18:54:11 +03:00
test_file_jpeg.py Format with Black 2019-06-13 18:54:11 +03:00
test_file_jpeg2k.py Format with Black 2019-06-13 18:54:11 +03:00
test_file_libtiff_small.py Format with Black 2019-06-13 18:54:11 +03:00
test_file_libtiff.py Format with Black 2019-06-13 18:54:11 +03:00
test_file_mcidas.py Format with Black 2019-06-13 18:54:11 +03:00
test_file_mic.py Format with Black 2019-06-13 18:54:11 +03:00
test_file_mpo.py Format with Black 2019-06-13 18:54:11 +03:00
test_file_msp.py Format with Black 2019-06-13 18:54:11 +03:00
test_file_palm.py Removed duplicate code 2019-05-04 23:05:07 +10:00
test_file_pcd.py Format with Black 2019-06-13 18:54:11 +03:00
test_file_pcx.py Format with Black 2019-06-13 18:54:11 +03:00
test_file_pdf.py Format with Black 2019-06-13 18:54:11 +03:00
test_file_pixar.py Format with Black 2019-06-13 18:54:11 +03:00
test_file_png.py Format with Black 2019-06-13 18:54:11 +03:00
test_file_ppm.py Format with Black 2019-06-13 18:54:11 +03:00
test_file_psd.py Format with Black 2019-06-19 09:30:10 +03:00
test_file_sgi.py Format with Black 2019-06-13 18:54:11 +03:00
test_file_spider.py Format with Black 2019-06-13 18:54:11 +03:00
test_file_sun.py Format with Black 2019-06-13 18:54:11 +03:00
test_file_tar.py Format with Black 2019-06-13 18:54:11 +03:00
test_file_tga.py Format with Black 2019-06-13 18:54:11 +03:00
test_file_tiff_metadata.py Format with Black 2019-06-13 18:54:11 +03:00
test_file_tiff.py Format with Black 2019-06-13 18:54:11 +03:00
test_file_wal.py Format with Black 2019-06-13 18:54:11 +03:00
test_file_webp_alpha.py Format with Black 2019-06-13 18:54:11 +03:00
test_file_webp_animated.py Format with Black 2019-06-13 18:54:11 +03:00
test_file_webp_lossless.py Format with Black 2019-06-13 18:54:11 +03:00
test_file_webp_metadata.py Format with Black 2019-06-13 18:54:11 +03:00
test_file_webp.py Format with Black 2019-06-13 18:54:11 +03:00
test_file_wmf.py Format with Black 2019-06-13 18:54:11 +03:00
test_file_xbm.py Format with Black 2019-06-13 18:54:11 +03:00
test_file_xpm.py Format with Black 2019-06-13 18:54:11 +03:00
test_file_xvthumb.py Format with Black 2019-06-13 18:54:11 +03:00
test_font_bdf.py Format with Black 2019-06-13 18:54:11 +03:00
test_font_leaks.py Format with Black 2019-06-13 18:54:24 +03:00
test_font_pcf.py Format with Black 2019-06-13 18:54:24 +03:00
test_format_hsv.py Format with Black 2019-06-13 18:54:24 +03:00
test_format_lab.py Format with Black 2019-06-13 18:54:24 +03:00
test_image_access.py Format with Black 2019-06-13 18:54:24 +03:00
test_image_array.py Format with Black 2019-06-13 18:54:24 +03:00
test_image_convert.py Format with Black 2019-06-13 18:54:24 +03:00
test_image_copy.py Format with Black 2019-06-13 18:54:24 +03:00
test_image_crop.py Format with Black 2019-06-13 18:54:24 +03:00
test_image_draft.py Format with Black 2019-06-13 18:54:24 +03:00
test_image_entropy.py Added an image.entropy() method 2019-06-26 19:15:47 +10:00
test_image_filter.py Format with Black 2019-06-13 18:54:24 +03:00
test_image_frombytes.py Format with Black 2019-06-13 18:54:24 +03:00
test_image_fromqimage.py Format with Black 2019-06-13 18:54:24 +03:00
test_image_getbands.py Format with Black 2019-06-13 18:54:24 +03:00
test_image_getbbox.py Format with Black 2019-06-13 18:54:24 +03:00
test_image_getcolors.py Format with Black 2019-06-13 18:54:24 +03:00
test_image_getdata.py Format with Black 2019-06-13 18:54:24 +03:00
test_image_getextrema.py Format with Black 2019-06-13 18:54:24 +03:00
test_image_getim.py Format with Black 2019-06-13 18:54:24 +03:00
test_image_getpalette.py Format with Black 2019-06-13 18:54:24 +03:00
test_image_getprojection.py Format with Black 2019-06-13 18:54:24 +03:00
test_image_histogram.py Format with Black 2019-06-13 18:54:24 +03:00
test_image_load.py Format with Black 2019-06-13 18:54:24 +03:00
test_image_mode.py Format with Black 2019-06-19 09:30:10 +03:00
test_image_paste.py Format with Black 2019-06-13 18:54:24 +03:00
test_image_point.py Format with Black 2019-06-13 18:54:24 +03:00
test_image_putalpha.py Format with Black 2019-06-13 18:54:24 +03:00
test_image_putdata.py Format with Black 2019-06-13 18:54:24 +03:00
test_image_putpalette.py Format with Black 2019-06-13 18:54:24 +03:00
test_image_quantize.py Format with Black 2019-06-13 18:54:24 +03:00
test_image_resample.py Format with Black 2019-06-13 18:54:24 +03:00
test_image_resize.py Format with Black 2019-06-13 18:54:24 +03:00
test_image_rotate.py Format with Black 2019-06-13 18:54:24 +03:00
test_image_split.py Format with Black 2019-06-13 18:54:24 +03:00
test_image_thumbnail.py Format with Black 2019-06-13 18:54:24 +03:00
test_image_tobitmap.py Format with Black 2019-06-13 18:54:24 +03:00
test_image_tobytes.py Format with Black 2019-06-13 18:54:24 +03:00
test_image_transform.py Format with Black 2019-06-13 18:54:24 +03:00
test_image_transpose.py Format with Black 2019-06-13 18:54:24 +03:00
test_image.py Format with Black 2019-06-13 18:54:24 +03:00
test_imagechops.py Format with Black 2019-06-13 18:54:46 +03:00
test_imagecms.py Format with Black 2019-06-13 18:54:46 +03:00
test_imagecolor.py Format with Black 2019-06-13 18:54:46 +03:00
test_imagedraw.py Format with Black 2019-06-13 18:54:46 +03:00
test_imagedraw2.py Format with Black 2019-06-13 18:54:46 +03:00
test_imageenhance.py Format with Black 2019-06-13 18:54:46 +03:00
test_imagefile.py Format with Black 2019-06-13 18:54:46 +03:00
test_imagefont_bitmap.py Format with Black 2019-06-13 18:54:46 +03:00
test_imagefont.py Fixed black formatting 2019-06-22 14:47:56 +10:00
test_imagefontctl.py Fixed black formatting 2019-06-22 14:47:56 +10:00
test_imagegrab.py Format with Black 2019-06-13 18:54:46 +03:00
test_imagemath.py Format with Black 2019-06-13 18:54:46 +03:00
test_imagemorph.py Format with Black 2019-06-13 18:54:46 +03:00
test_imageops_usm.py Format with Black 2019-06-13 18:54:46 +03:00
test_imageops.py Format with Black 2019-06-13 18:54:46 +03:00
test_imagepalette.py Format with Black 2019-06-13 18:54:46 +03:00
test_imagepath.py Format with Black 2019-06-13 18:54:46 +03:00
test_imageqt.py Format with Black 2019-06-13 18:54:46 +03:00
test_imagesequence.py Format with Black 2019-06-19 09:30:10 +03:00
test_imageshow.py Merge remote-tracking branch 'upstream/master' into run-black 2019-06-19 09:29:28 +03:00
test_imagestat.py Format with Black 2019-06-13 18:54:46 +03:00
test_imagetk.py Format with Black 2019-06-13 18:54:46 +03:00
test_imagewin_pointers.py Format with Black 2019-06-13 18:54:46 +03:00
test_imagewin.py Format with Black 2019-06-13 18:54:46 +03:00
test_lib_image.py Format with Black 2019-06-13 18:54:46 +03:00
test_lib_pack.py Added CMYK;16B and CMYK;16N unpackers 2019-06-23 11:56:17 +10:00
test_locale.py Format with Black 2019-06-13 18:54:46 +03:00
test_main.py Fixed black formatting 2019-06-22 14:47:56 +10:00
test_map.py Format with Black 2019-06-13 18:54:46 +03:00
test_mode_i16.py Format with Black 2019-06-13 18:54:46 +03:00
test_numpy.py Format with Black 2019-06-13 18:54:46 +03:00
test_pdfparser.py Format with Black 2019-06-13 18:54:46 +03:00
test_pickle.py Format with Black 2019-06-13 18:54:46 +03:00
test_psdraw.py Format with Black 2019-06-13 18:54:46 +03:00
test_pyroma.py Tighten fixed pyroma test 2019-06-02 22:36:05 +03:00
test_qt_image_fromqpixmap.py Format with Black 2019-06-13 18:54:46 +03:00
test_qt_image_toqimage.py Format with Black 2019-06-13 18:54:46 +03:00
test_qt_image_toqpixmap.py Format with Black 2019-06-13 18:54:46 +03:00
test_shell_injection.py Format with Black 2019-06-13 18:54:46 +03:00
test_tiff_ifdrational.py Format with Black 2019-06-13 18:54:46 +03:00
test_uploader.py Format with Black 2019-06-13 18:54:46 +03:00
test_util.py Format with Black 2019-06-13 18:54:46 +03:00
test_webp_leaks.py Format with Black 2019-06-13 18:54:46 +03:00
threaded_save.py Flake8 blank line fixes 2018-03-04 21:36:33 +11:00
versions.py Do not write custom tags with libtiff < 4 2018-11-12 06:14:04 +11:00

Pillow Tests
============

Test scripts are named ``test_xxx.py`` and use the ``unittest`` module. A base class and helper functions can be found in ``helper.py``.

Dependencies
-----------

Install::

    pip install pytest pytest-cov

Execution
---------

To run an individual test::

    pytest Tests/test_image.py

Or::

    pytest -k test_image.py

Run all the tests from the root of the Pillow source distribution::

    pytest

Or with coverage::

    pytest --cov PIL --cov-report term
    coverage html
    open htmlcov/index.html