66
77from PIL import Image , JpegXlImagePlugin , features
88
9- from .helper import (
10- assert_image_similar_tofile ,
11- skip_unless_feature ,
12- )
9+ from .helper import assert_image_similar_tofile , skip_unless_feature
1310
1411try :
1512 from PIL import _jpegxl
16-
17- HAVE_JPEGXL = True
1813except ImportError :
19- HAVE_JPEGXL = False
14+ pass
2015
2116# cjxl v0.9.2 41b8cdab
2217# hopper.jxl: cjxl hopper.png hopper.jxl -q 75 -e 8
2318# 16_bit_binary.jxl: cjxl 16_bit_binary.pgm 16_bit_binary.jxl -q 100 -e 9
2419
2520
2621class TestUnsupportedJpegXl :
27- def test_unsupported (self ) -> None :
28- if HAVE_JPEGXL :
29- JpegXlImagePlugin .SUPPORTED = False
22+ def test_unsupported (self , monkeypatch : pytest .MonkeyPatch ) -> None :
23+ monkeypatch .setattr (JpegXlImagePlugin , "SUPPORTED" , False )
3024
31- file_path = "Tests/images/hopper.jxl"
3225 with pytest .raises (OSError ):
33- with Image .open (file_path ):
26+ with Image .open ("Tests/images/hopper.jxl" ):
3427 pass
3528
36- if HAVE_JPEGXL :
37- JpegXlImagePlugin .SUPPORTED = True
38-
3929
4030@skip_unless_feature ("jpegxl" )
4131class TestFileJpegXl :
42- def setup_method (self ) -> None :
43- self .rgb_mode = "RGB"
44- self .i16_mode = "I;16"
45-
4632 def test_version (self ) -> None :
4733 _jpegxl .JpegXlDecoderVersion ()
4834 version = features .version_module ("jpegxl" )
@@ -56,30 +42,30 @@ def test_read_rgb(self) -> None:
5642 """
5743
5844 with Image .open ("Tests/images/hopper.jxl" ) as image :
59- assert image .mode == self . rgb_mode
45+ assert image .mode == "RGB"
6046 assert image .size == (128 , 128 )
6147 assert image .format == "JPEG XL"
6248 image .load ()
6349 image .getdata ()
6450
6551 # generated with:
6652 # djxl hopper.jxl hopper_jxl_bits.ppm
67- assert_image_similar_tofile (image , "Tests/images/hopper_jxl_bits.ppm" , 1.0 )
53+ assert_image_similar_tofile (image , "Tests/images/hopper_jxl_bits.ppm" , 1 )
6854
6955 def test_read_i16 (self ) -> None :
7056 """
7157 Can we read 16-bit Grayscale Jpeg XL image?
7258 """
7359
7460 with Image .open ("Tests/images/jxl/16bit_subcutaneous.cropped.jxl" ) as image :
75- assert image .mode == self . i16_mode
61+ assert image .mode == "I;16"
7662 assert image .size == (128 , 64 )
7763 assert image .format == "JPEG XL"
7864 image .load ()
7965 image .getdata ()
8066
8167 assert_image_similar_tofile (
82- image , "Tests/images/jxl/16bit_subcutaneous.cropped.png" , 1.0
68+ image , "Tests/images/jxl/16bit_subcutaneous.cropped.png" , 1
8369 )
8470
8571 def test_JpegXlDecode_with_invalid_args (self ) -> None :
0 commit comments