mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-13 05:06:49 +03:00
Merge pull request #6904 from Yay295/imagepath_tests
More ImagePath tests
This commit is contained in:
commit
6c800dda6a
|
@ -38,48 +38,65 @@ def test_path():
|
||||||
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
|
|
||||||
p = ImagePath.Path([0, 1])
|
|
||||||
assert list(p) == [(0.0, 1.0)]
|
|
||||||
p = ImagePath.Path([0.0, 1.0])
|
|
||||||
assert list(p) == [(0.0, 1.0)]
|
|
||||||
p = ImagePath.Path([0, 1])
|
|
||||||
assert list(p) == [(0.0, 1.0)]
|
|
||||||
p = ImagePath.Path([(0, 1)])
|
|
||||||
assert list(p) == [(0.0, 1.0)]
|
|
||||||
p = ImagePath.Path(p)
|
|
||||||
assert list(p) == [(0.0, 1.0)]
|
|
||||||
p = ImagePath.Path(p.tolist(0))
|
|
||||||
assert list(p) == [(0.0, 1.0)]
|
|
||||||
p = ImagePath.Path(p.tolist(1))
|
|
||||||
assert list(p) == [(0.0, 1.0)]
|
|
||||||
p = ImagePath.Path(array.array("f", [0, 1]))
|
|
||||||
assert list(p) == [(0.0, 1.0)]
|
|
||||||
|
|
||||||
arr = array.array("f", [0, 1])
|
@pytest.mark.parametrize(
|
||||||
p = ImagePath.Path(arr.tobytes())
|
"coords",
|
||||||
|
(
|
||||||
|
(0, 1),
|
||||||
|
[0, 1],
|
||||||
|
(0.0, 1.0),
|
||||||
|
[0.0, 1.0],
|
||||||
|
((0, 1),),
|
||||||
|
[(0, 1)],
|
||||||
|
((0.0, 1.0),),
|
||||||
|
[(0.0, 1.0)],
|
||||||
|
array.array("f", [0, 1]),
|
||||||
|
array.array("f", [0, 1]).tobytes(),
|
||||||
|
ImagePath.Path((0, 1)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
def test_path_constructors(coords):
|
||||||
|
# Arrange / Act
|
||||||
|
p = ImagePath.Path(coords)
|
||||||
|
|
||||||
|
# Assert
|
||||||
assert list(p) == [(0.0, 1.0)]
|
assert list(p) == [(0.0, 1.0)]
|
||||||
|
|
||||||
|
|
||||||
def test_invalid_coords():
|
@pytest.mark.parametrize(
|
||||||
# Arrange
|
"coords",
|
||||||
coords = ["a", "b"]
|
(
|
||||||
|
("a", "b"),
|
||||||
# Act / Assert
|
([0, 1],),
|
||||||
|
[[0, 1]],
|
||||||
|
([0.0, 1.0],),
|
||||||
|
[[0.0, 1.0]],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
def test_invalid_path_constructors(coords):
|
||||||
|
# Act
|
||||||
with pytest.raises(ValueError) as e:
|
with pytest.raises(ValueError) as e:
|
||||||
ImagePath.Path(coords)
|
ImagePath.Path(coords)
|
||||||
|
|
||||||
|
# Assert
|
||||||
assert str(e.value) == "incorrect coordinate type"
|
assert str(e.value) == "incorrect coordinate type"
|
||||||
|
|
||||||
|
|
||||||
def test_path_odd_number_of_coordinates():
|
@pytest.mark.parametrize(
|
||||||
# Arrange
|
"coords",
|
||||||
coords = [0]
|
(
|
||||||
|
(0,),
|
||||||
# Act / Assert
|
[0],
|
||||||
|
(0, 1, 2),
|
||||||
|
[0, 1, 2],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
def test_path_odd_number_of_coordinates(coords):
|
||||||
|
# Act
|
||||||
with pytest.raises(ValueError) as e:
|
with pytest.raises(ValueError) as e:
|
||||||
ImagePath.Path(coords)
|
ImagePath.Path(coords)
|
||||||
|
|
||||||
|
# Assert
|
||||||
assert str(e.value) == "wrong number of coordinates"
|
assert str(e.value) == "wrong number of coordinates"
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user