Commit Graph

146 Commits

Author SHA1 Message Date
Andrew Murray
56f30ef792 Allow explicit zero width to hide outline 2020-01-08 21:55:15 +11:00
Andrew Murray
8e8f63d4a5 Only draw each polygon pixel once 2020-01-05 17:43:51 +11:00
Alexander
ac92836e81 Change default resize resampling filter 2019-12-07 18:08:19 +03:00
Andrew Murray
c0048ad7de Use context managers 2019-11-26 07:03:23 +11:00
Jon Dufresne
33dabf986f Import unittest from stdlib rather than helper.py
The unittest in helper.py has not offered an interesting abstraction
since dbe9f85c7d so import from the more
typical stdlib location.
2019-11-20 18:42:52 -08: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
Andrew Murray
b913fa6a53 Increased tolerance for stroke test comparison 2019-09-11 19:57:45 +10:00
Andrew Murray
da39d40342
Merge pull request #3978 from radarhere/stroke
Added text stroking
2019-09-06 19:14:49 +10:00
Hugo van Kemenade
cb1ebc024b
Merge pull request #4017 from radarhere/floodfill
Do not allow floodfill to extend into negative coordinates
2019-09-05 23:00:33 +03:00
Andrew Murray
23872c0645 Do not allow floodfill to extend into negative coordinates 2019-08-12 06:51:16 +10:00
Andrew Murray
8fff9a2444 Fixed arc drawing bug for a non-whole number of degrees 2019-08-12 06:50:58 +10:00
Andrew Murray
f93a5d0972 Added text stroking 2019-07-29 06:40:03 +10: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
Andrew Murray
e0cbfb2708 Consider I;16 pixel size when drawing 2019-06-23 07:33:55 +10:00
Hugo
5631718a8d Format with Black 2019-06-13 18:54:46 +03:00
Andrew Murray
21c7fd251c Fixed arc gaps 2019-05-03 23:37:37 +10: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
Hugo
d69ef6a529 Remove redundant parentheses 2018-10-24 22:29:56 +03:00
Andrew Murray
1e305380ae
Merge pull request #3094 from hugovk/add-width-to-shapes
Add line width parameter to rectangle and ellipse-based shapes
2018-09-29 23:21:03 +10:00
Andrew Murray
6dd0e48d9a Missing whitespace 2018-09-27 19:43:39 +10:00
Andrew Murray
b5af283732 Added support to floodfill for non-RGB colors 2018-09-26 22:22:17 +10:00
Andrew Murray
f3842460ba Added line joints 2018-09-16 21:29:09 +10:00
Andrew Murray
0411caba67 Catch ValueError when processing the edge of an image 2018-09-01 17:18:13 +10:00
Hugo
f70f952f85
Merge branch 'master' into add-width-to-shapes 2018-07-14 14:58:48 +03:00
Hugo
5d751572cc
Merge pull request #2922 from radarhere/fill_ink
Skip outline if the draw operation fills with the same colour
2018-07-02 22:19:35 +03:00
Hugo
d6e3ef85c2 Add width parameter to arc, chord, ellipse, pieslice 2018-07-02 11:26:42 +03:00
Hugo
9dedbff713 Add width parameter to rectangle 2018-07-02 11:21:30 +03:00
Andrew Murray
8d8d00f304 Changed ellipse point calculations to be more evenly distributed 2018-05-27 15:32:22 +10:00
Hugo
33592b4f73 No need to import sys 2018-05-17 23:21:47 +03:00
Hugo
90ab677d44 Re-enable test for PyPy 2018-05-17 22:18:18 +03:00
Andrew Murray
4d3339b703 Added tests 2018-01-05 11:26:24 +11:00
hugovk
5524d806b4 Failing test for #2783 2017-10-04 11:09:52 +00:00
Andrew Murray
5c2df30ac3 Removed ImageDraw.Draw del calls 2017-09-01 21:06:22 +10:00
Andrew Murray
9e843a2d9b Changed format of lambda calls 2017-09-01 21:05:40 +10:00
nediamond
d1b66e9dfd Added threshold parameter to ImageDraw.floodfill (#2599)
* added thresh option and test

* fixed up, test works and passes

* Update test_imagedraw.py

* Update test_imagedraw.py

* Update ImageDraw.py

* removed pypy skip decorator from thresh test

* Update ImageDraw.py
2017-07-01 10:37:02 +01:00
Hugo
08c72a1720 flake8 2017-05-16 10:33:38 +03:00
hugovk
206e316c0e Test limits of arc/ellipse's start and end 2017-05-15 22:58:51 +03:00
hugovk
f1631e0d05 Test drawing a rectangle bigger than the image 2017-05-15 21:44:28 +03:00
hugovk
5871b7a5ba Test drawing a wide "line" from one point to another just draws a single point 2017-05-15 21:32:54 +03:00
Hugo
ae9181f0a4 Test polygons in RGB and L modes 2017-05-15 18:24:12 +03:00
Hugo
e77c3b3eb2 Test ellipse in RGB and L modes 2017-05-15 18:23:00 +03:00
Hugo
d4a350cd79 Test chord in RGB and L modes 2017-05-15 18:04:33 +03:00
Hugo
3db1944762 Test drawing polygons with sloped and flat lines 2017-05-15 17:09:29 +03:00
Andrew Murray
37b293f593 Flake8 fixes 2017-04-20 21:14:23 +10:00
Andrew Murray
257bc8bd4f Added tests 2017-03-03 19:45:55 +11:00
wiredfool
a4ef743b0f Merge pull request #2220 from jdufresne/image-draw-dep
Remove long deprecated ImageDraw methods
2017-02-22 10:12:05 +00:00
hugovk
96dfd722c3 Test ImageDraw.Outline curve 2017-01-31 08:22:33 +02:00
hugovk
008431fe0e Test ImageDraw.Outline curve 2017-01-30 21:50:48 +02:00
Jon Dufresne
a5d6519d74 Remove long deprecated ImageDraw methods
Deprecated in 89ccf66ff7 since Sep 29,
2015, version 3.0.0.
2016-11-13 10:08:47 -08:00
homm
1ba4e9e5ba remove end of file banner from all files 2016-07-10 14:11:28 +03:00
Andrew Murray
3c2e374824 Added test 2016-06-09 22:28:29 +01:00
Andrew Murray
8f9b3a7372 Changed arcs, chords and pie slices to use floats 2015-12-09 00:28:52 +11:00
Andrew Murray
f0944438ab Removed FIXME from ImageDraw test 2015-12-08 00:03:38 +11:00
wiredfool
89ccf66ff7 Merge pull request #1343 from radarhere/deprecated
Removed deprecated code
2015-09-29 15:38:34 +01:00
Andrew Murray
71c95c8e5f Restored deprecated methods with errors instead 2015-09-19 21:36:19 +10:00
Andrew Murray
c6b13d294f Flake8 fixes 2015-08-25 22:27:18 +10:00
Andrew Murray
94ed100bb2 Removed ImageDraw methods deprecated in PIL 1.1.15 2015-07-13 17:41:26 +10: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
Andrew Murray
a1b71d5ee0 Added test for polygon edge drawing 2015-06-06 00:46:50 +10:00
Andrew Murray
a996033079 Fixed various typos 2015-05-29 14:59:54 +10:00
Andrew Murray
d1c182cadc Various Flake8 fixes 2015-04-24 09:26:52 +10:00
wiredfool
1bb850427d Slightly relax imagedraw tests to pass on x86 2014-09-30 08:33:29 -07:00
Hugo
5e676ea0bd Merge remote-tracking branch 'upstream/master' into flake8
Conflicts:
	Tests/bench_cffi_access.py
	Tests/test_file_palm.py
	Tests/test_format_hsv.py
	Tests/test_image_putdata.py
	Tests/test_locale.py
	Tests/test_mode_i16.py
2014-09-23 16:35:20 +03:00
hugovk
b929873a62 Change some lena() to hopper() 2014-09-05 12:36:24 +03:00
hugovk
42610c0ecd flake8 2014-08-28 17:18:54 +03:00
hugovk
1335006cd7 flake8 2014-08-28 14:44:19 +03:00
hugovk
cf04a9a0d2 Remove unused tearDownModule 2014-07-07 20:03:50 +03:00
wiredfool
e3f9fa0d78 Skip known failing test 2014-07-01 09:07:18 -07:00
wiredfool
a990af1b97 Merge from master 2014-06-24 16:48:38 -07:00
hugovk
b7f14415d8 Constants are now ALL CAPS 2014-06-23 22:51:31 +03:00
Terseus
5522fa472d Fixed variables misprint in ImageDraw tests 2014-06-23 20:07:09 +02:00
hugovk
3ec505958e Convert old tests to use unittest 2014-06-10 12:10:47 +03:00
hugovk
995f367755 Skip test_floodfill_border() on PyPy to avoid fatal error 2014-06-06 08:02:18 +03:00
hugovk
ae37743ac7 Both kinds of bounding box for arc, chord and pieslice. 2014-05-27 23:31:31 +03:00
hugovk
8f92562ec3 Remove old FIXME comment [CI skip] 2014-05-24 17:36:31 +03:00
hugovk
35336e5afd Test arc, chord, pieslice give TypeError when bounding box is [(x0, y0), (x1, y1)] 2014-05-24 17:31:37 +03:00
hugovk
60b2570133 Test ImageDraw's bitmap() 2014-05-13 14:43:48 +03:00
hugovk
5b55cb72d3 Test experimental floodfill with a border 2014-05-12 23:33:05 +03:00
hugovk
961db29ff6 Test experimental floodfill() 2014-05-12 23:27:02 +03:00
hugovk
6b274b4c5e More ImageDraw tests. Some may need redoing after issues #367 and #463 are sorted. 2014-05-12 21:45:16 +03:00
hugovk
84c7d25606 Make sure bounding box in ints (for Py3) 2014-05-12 19:55:18 +03:00
hugovk
92eea7a9cc Tests for ImageDraw 2014-05-12 17:32:04 +03:00
Terseus
113b8c2a76 Removed non-ASCII character from messages 2014-04-09 20:06:58 +02:00
Terseus
b987d90568 Added tests for lines with 1px slope
This tests are designed to guarantee that the wide lines behave exactly
like normal lines drawn with the Bresenham's algorithm.
This tests are somewhat subjective since this is non-defined behavior,
but I think that mimic the Bresenham's algorithm is reliable enough.

Currently the horizontal version of this test **fail**.
2014-04-09 19:34:50 +02:00
Terseus
4b7236f460 Added tests of hor/ver lines 101px wide
These tests should guarantee that the proportion of the width is
maintained with a margin of error < 1%.
2014-04-09 19:34:50 +02:00
Terseus
8228caf14d Added some oblique 45º lines tests
Only the oblique 3 pixels wide lines are defined:
* The oblique 2 pixels wide lines are somewhat hard to define.
* To define the oblique lines wider than 3 pixels we neet to define
  first how the oblique lines should expand their width (realistic or
  exact).
2014-04-09 19:33:46 +02:00
Terseus
92dd58c014 Added descriptive errors to imagedraw tests 2014-04-06 14:03:03 +02:00
Terseus
1c02d467ef Added test for vertical lines.
The behavior is consistent with horizontal lines, see previous commit
for details.
2014-04-04 12:45:47 +02:00
Terseus
fee2faa8dc Added test for horizontal lines
Notice that the expansion of the line width depends on the order of the
points:
  * If the bigger axis value is provided as the *second* point the line
    expand first to the *positive* side of the axis.
  * If the bigger axis value is provided as the *first* point the line
    expand first to the *negative* side of the axis.
  * If the line's width is odd this doesn't matter, as the line will
    expand the same amount to both sides.

This behavior should be consistent in both horizontal and vertical lines.
2014-04-04 12:35:26 +02:00
Terseus
e2cb2195eb Added test for a simple right triangle
The diagonals of the right angled edges must be perfect and the bottom
vertice should be drawn.
2014-04-04 11:46:58 +02:00
Terseus
ec74779b19 Added test for a simple square 2014-04-04 11:28:41 +02:00
Terseus
7de14a51dd Added base method and constants to test_imagedraw
The method `create_base_image_draw` will be used in all the new draw
tests.
2014-04-04 10:47:22 +02:00
Alex Clark
bb1b3a532c Cleanup WS, courtesy of @Arfrever
find * -type f "-(" -name "*.bdf" -o -name "*.c" -o -name "*.h" -o -name "*.py" -o -name "*.rst" -o -name "*.txt" "-)" -exec sed -e "s/[[:space:]]*$//" -i {} \;
2013-06-30 18:42:19 -04: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