diff --git a/Tests/test_file_jxl.py b/Tests/test_file_jxl.py index 36a9c0aa2..5f50018d6 100644 --- a/Tests/test_file_jxl.py +++ b/Tests/test_file_jxl.py @@ -41,31 +41,31 @@ class TestFileJpegXl: Does it have the bits we expect? """ - with Image.open("Tests/images/hopper.jxl") as image: - assert image.mode == "RGB" - assert image.size == (128, 128) - assert image.format == "JPEG XL" - image.load() - image.getdata() + with Image.open("Tests/images/hopper.jxl") as im: + assert im.mode == "RGB" + assert im.size == (128, 128) + assert im.format == "JPEG XL" + im.load() + im.getdata() # generated with: # djxl hopper.jxl hopper_jxl_bits.ppm - assert_image_similar_tofile(image, "Tests/images/hopper_jxl_bits.ppm", 1) + assert_image_similar_tofile(im, "Tests/images/hopper_jxl_bits.ppm", 1) def test_read_i16(self) -> None: """ Can we read 16-bit Grayscale Jpeg XL image? """ - with Image.open("Tests/images/jxl/16bit_subcutaneous.cropped.jxl") as image: - assert image.mode == "I;16" - assert image.size == (128, 64) - assert image.format == "JPEG XL" - image.load() - image.getdata() + with Image.open("Tests/images/jxl/16bit_subcutaneous.cropped.jxl") as im: + assert im.mode == "I;16" + assert im.size == (128, 64) + assert im.format == "JPEG XL" + im.load() + im.getdata() assert_image_similar_tofile( - image, "Tests/images/jxl/16bit_subcutaneous.cropped.png", 1 + im, "Tests/images/jxl/16bit_subcutaneous.cropped.png", 1 ) def test_JpegXlDecode_with_invalid_args(self) -> None: diff --git a/Tests/test_file_jxl_metadata.py b/Tests/test_file_jxl_metadata.py index d0b26b672..a11dfeefe 100644 --- a/Tests/test_file_jxl_metadata.py +++ b/Tests/test_file_jxl_metadata.py @@ -27,21 +27,20 @@ except ImportError: def test_read_exif_metadata() -> None: - with Image.open("Tests/images/flower.jxl") as image: - assert image.format == "JPEG XL" - exif_data = image.info.get("exif", None) - assert exif_data + with Image.open("Tests/images/flower.jxl") as im: + assert im.format == "JPEG XL" + exif_data = im.info["exif"] - exif = image.getexif() + exif = im.getexif() # Camera make assert exif[271] == "Canon" - with Image.open("Tests/images/flower.jpg") as jpeg_image: - expected_exif = jpeg_image.info["exif"] + with Image.open("Tests/images/flower.jpg") as im_jpeg: + expected_exif = im_jpeg.info["exif"] - # jpeg xl always returns exif without 'Exif\0\0' prefix - assert exif_data == expected_exif[6:] + # jpeg xl always returns exif without 'Exif\0\0' prefix + assert exif_data == expected_exif[6:] def test_read_exif_metadata_without_prefix() -> None: @@ -50,18 +49,16 @@ def test_read_exif_metadata_without_prefix() -> None: assert im.info["exif"][:6] != b"Exif\x00\x00" exif = im.getexif() - assert exif[305] == "Adobe Photoshop CS6 (Macintosh)" + assert exif[305] == "Adobe Photoshop CS6 (Macintosh)" def test_read_icc_profile() -> None: - with Image.open("Tests/images/flower2.jxl") as image: - assert image.format == "JPEG XL" - assert image.info.get("icc_profile", None) + with Image.open("Tests/images/flower2.jxl") as im: + assert im.format == "JPEG XL" + icc = im.info["icc_profile"] - icc = image.info["icc_profile"] - - with Image.open("Tests/images/flower2.jxl") as jpeg_image: - expected_icc = jpeg_image.info["icc_profile"] + with Image.open("Tests/images/flower2.jxl") as im_jpeg: + expected_icc = im_jpeg.info["icc_profile"] assert icc == expected_icc @@ -114,10 +111,10 @@ def test_4_byte_exif(monkeypatch: pytest.MonkeyPatch) -> None: monkeypatch.setattr(JpegXlImagePlugin, "_jpegxl", _mock_jpegxl) - with Image.open("Tests/images/hopper.jxl") as image: - assert "exif" not in image.info + with Image.open("Tests/images/hopper.jxl") as im: + assert "exif" not in im.info def test_read_exif_metadata_empty() -> None: - with Image.open("Tests/images/hopper.jxl") as image: - assert image.getexif() == {} + with Image.open("Tests/images/hopper.jxl") as im: + assert im.getexif() == {} diff --git a/src/_jpegxl.c b/src/_jpegxl.c index 4cb89e7e1..6196a9ea9 100644 --- a/src/_jpegxl.c +++ b/src/_jpegxl.c @@ -635,7 +635,6 @@ setup_module(PyObject *m) { // TODO(oloke) ready object types? PyObject *d = PyModule_GetDict(m); - PyObject *v = PyUnicode_FromString(JpegXlDecoderVersion_str()); PyDict_SetItemString(d, "libjxl_version", v ? v : Py_None); Py_XDECREF(v); @@ -649,10 +648,9 @@ PyInit__jpegxl(void) { static PyModuleDef module_def = { PyModuleDef_HEAD_INIT, - "_jpegxl", /* m_name */ - NULL, /* m_doc */ - -1, /* m_size */ - jpegxlMethods, /* m_methods */ + .m_name = "_jpegxl", + .m_size = -1, + .m_methods = jpegxlMethods, }; m = PyModule_Create(&module_def);