Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions Tests/test_image_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def convert(im: Image.Image, mode: str) -> None:

def test_unsupported_conversion() -> None:
im = hopper()
with pytest.raises(ValueError):
with pytest.raises(ValueError, match="image has wrong mode"):
im.convert("INVALID")


Expand Down Expand Up @@ -305,26 +305,33 @@ def test_matrix_illegal_conversion() -> None:
assert im.mode != "RGB"

# Act / Assert
with pytest.raises(ValueError):
with pytest.raises(ValueError, match="illegal conversion"):
im.convert(mode="CMYK", matrix=rgb2xyz_matrix)


def test_matrix_wrong_mode() -> None:
# Arrange
im = hopper("L")
assert im.mode == "L"

# Act / Assert
with pytest.raises(ValueError):
with pytest.raises(ValueError, match="image has wrong mode"):
im.convert(mode="L", matrix=rgb2xyz_matrix)


def test_matrix_truncated() -> None:
# Arrange
im = hopper()

# Act / Assert
with pytest.raises(TypeError, match="matrix must be tuple of length 4 or 12"):
im.convert(mode="L", matrix=(0,))


@pytest.mark.parametrize("mode", ("RGB", "L"))
def test_matrix_xyz(mode: str) -> None:
# Arrange
im = hopper("RGB")
im.info["transparency"] = (255, 0, 0)
assert im.mode == "RGB"

# Act
# Convert an RGB image to the CIE XYZ colour space
Expand All @@ -350,7 +357,6 @@ def test_matrix_identity() -> None:
0, 1, 0, 0,
0, 0, 1, 0,
) # fmt: skip
assert im.mode == "RGB"

# Act
# Convert with an identity matrix
Expand Down
1 change: 1 addition & 0 deletions src/_imaging.c
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,7 @@ _convert_matrix(ImagingObject *self, PyObject *args) {
m + 10,
m + 11
)) {
PyErr_SetString(PyExc_TypeError, "matrix must be tuple of length 4 or 12");
return NULL;
}
}
Expand Down
Loading