mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-26 01:04:29 +03:00
Simplify: remove class
This commit is contained in:
parent
9e3ad5e997
commit
2b319f2ce4
|
@ -6,75 +6,75 @@ import pytest
|
||||||
from PIL import Image, ImagePath
|
from PIL import Image, ImagePath
|
||||||
|
|
||||||
|
|
||||||
class TestImagePath:
|
def test_path():
|
||||||
def test_path(self):
|
|
||||||
|
|
||||||
p = ImagePath.Path(list(range(10)))
|
p = ImagePath.Path(list(range(10)))
|
||||||
|
|
||||||
# sequence interface
|
# sequence interface
|
||||||
assert len(p) == 5
|
assert len(p) == 5
|
||||||
assert p[0] == (0.0, 1.0)
|
assert p[0] == (0.0, 1.0)
|
||||||
assert p[-1] == (8.0, 9.0)
|
assert p[-1] == (8.0, 9.0)
|
||||||
assert list(p[:1]) == [(0.0, 1.0)]
|
assert list(p[:1]) == [(0.0, 1.0)]
|
||||||
with pytest.raises(TypeError) as cm:
|
with pytest.raises(TypeError) as cm:
|
||||||
p["foo"]
|
p["foo"]
|
||||||
assert str(cm.value) == "Path indices must be integers, not str"
|
assert str(cm.value) == "Path indices must be integers, not str"
|
||||||
assert list(p) == [(0.0, 1.0), (2.0, 3.0), (4.0, 5.0), (6.0, 7.0), (8.0, 9.0)]
|
assert list(p) == [(0.0, 1.0), (2.0, 3.0), (4.0, 5.0), (6.0, 7.0), (8.0, 9.0)]
|
||||||
|
|
||||||
# method sanity check
|
# method sanity check
|
||||||
assert p.tolist() == [
|
assert p.tolist() == [
|
||||||
(0.0, 1.0),
|
(0.0, 1.0),
|
||||||
(2.0, 3.0),
|
(2.0, 3.0),
|
||||||
(4.0, 5.0),
|
(4.0, 5.0),
|
||||||
(6.0, 7.0),
|
(6.0, 7.0),
|
||||||
(8.0, 9.0),
|
(8.0, 9.0),
|
||||||
]
|
]
|
||||||
assert p.tolist(1) == [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]
|
assert p.tolist(1) == [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]
|
||||||
|
|
||||||
assert p.getbbox() == (0.0, 1.0, 8.0, 9.0)
|
assert p.getbbox() == (0.0, 1.0, 8.0, 9.0)
|
||||||
|
|
||||||
assert p.compact(5) == 2
|
assert p.compact(5) == 2
|
||||||
assert list(p) == [(0.0, 1.0), (4.0, 5.0), (8.0, 9.0)]
|
assert list(p) == [(0.0, 1.0), (4.0, 5.0), (8.0, 9.0)]
|
||||||
|
|
||||||
p.transform((1, 0, 1, 0, 1, 1))
|
p.transform((1, 0, 1, 0, 1, 1))
|
||||||
assert list(p) == [(1.0, 2.0), (5.0, 6.0), (9.0, 10.0)]
|
assert list(p) == [(1.0, 2.0), (5.0, 6.0), (9.0, 10.0)]
|
||||||
|
|
||||||
# alternative constructors
|
# alternative constructors
|
||||||
p = ImagePath.Path([0, 1])
|
p = ImagePath.Path([0, 1])
|
||||||
assert list(p) == [(0.0, 1.0)]
|
assert list(p) == [(0.0, 1.0)]
|
||||||
p = ImagePath.Path([0.0, 1.0])
|
p = ImagePath.Path([0.0, 1.0])
|
||||||
assert list(p) == [(0.0, 1.0)]
|
assert list(p) == [(0.0, 1.0)]
|
||||||
p = ImagePath.Path([0, 1])
|
p = ImagePath.Path([0, 1])
|
||||||
assert list(p) == [(0.0, 1.0)]
|
assert list(p) == [(0.0, 1.0)]
|
||||||
p = ImagePath.Path([(0, 1)])
|
p = ImagePath.Path([(0, 1)])
|
||||||
assert list(p) == [(0.0, 1.0)]
|
assert list(p) == [(0.0, 1.0)]
|
||||||
p = ImagePath.Path(p)
|
p = ImagePath.Path(p)
|
||||||
assert list(p) == [(0.0, 1.0)]
|
assert list(p) == [(0.0, 1.0)]
|
||||||
p = ImagePath.Path(p.tolist(0))
|
p = ImagePath.Path(p.tolist(0))
|
||||||
assert list(p) == [(0.0, 1.0)]
|
assert list(p) == [(0.0, 1.0)]
|
||||||
p = ImagePath.Path(p.tolist(1))
|
p = ImagePath.Path(p.tolist(1))
|
||||||
assert list(p) == [(0.0, 1.0)]
|
assert list(p) == [(0.0, 1.0)]
|
||||||
p = ImagePath.Path(array.array("f", [0, 1]))
|
p = ImagePath.Path(array.array("f", [0, 1]))
|
||||||
assert list(p) == [(0.0, 1.0)]
|
assert list(p) == [(0.0, 1.0)]
|
||||||
|
|
||||||
arr = array.array("f", [0, 1])
|
arr = array.array("f", [0, 1])
|
||||||
if hasattr(arr, "tobytes"):
|
if hasattr(arr, "tobytes"):
|
||||||
p = ImagePath.Path(arr.tobytes())
|
p = ImagePath.Path(arr.tobytes())
|
||||||
else:
|
else:
|
||||||
p = ImagePath.Path(arr.tostring())
|
p = ImagePath.Path(arr.tostring())
|
||||||
assert list(p) == [(0.0, 1.0)]
|
assert list(p) == [(0.0, 1.0)]
|
||||||
|
|
||||||
def test_overflow_segfault(self):
|
|
||||||
# Some Pythons fail getting the argument as an integer, and it falls
|
|
||||||
# through to the sequence. Seeing this on 32-bit Windows.
|
|
||||||
with pytest.raises((TypeError, MemoryError)):
|
|
||||||
# post patch, this fails with a memory error
|
|
||||||
x = evil()
|
|
||||||
|
|
||||||
# This fails due to the invalid malloc above,
|
def test_overflow_segfault():
|
||||||
# and segfaults
|
# Some Pythons fail getting the argument as an integer, and it falls
|
||||||
for i in range(200000):
|
# through to the sequence. Seeing this on 32-bit Windows.
|
||||||
x[i] = b"0" * 16
|
with pytest.raises((TypeError, MemoryError)):
|
||||||
|
# post patch, this fails with a memory error
|
||||||
|
x = evil()
|
||||||
|
|
||||||
|
# This fails due to the invalid malloc above,
|
||||||
|
# and segfaults
|
||||||
|
for i in range(200000):
|
||||||
|
x[i] = b"0" * 16
|
||||||
|
|
||||||
|
|
||||||
class evil:
|
class evil:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user