@@ -109,7 +109,7 @@ def test_palette_not_needed_for_second_frame() -> None:
109
109
assert_image_similar (im , hopper ("L" ).convert ("RGB" ), 8 )
110
110
111
111
112
- def test_strategy () -> None :
112
+ def test_strategy (monkeypatch : pytest . MonkeyPatch ) -> None :
113
113
with Image .open ("Tests/images/iss634.gif" ) as im :
114
114
expected_rgb_always = im .convert ("RGB" )
115
115
@@ -119,35 +119,36 @@ def test_strategy() -> None:
119
119
im .seek (1 )
120
120
expected_different = im .convert ("RGB" )
121
121
122
- try :
123
- GifImagePlugin .LOADING_STRATEGY = GifImagePlugin .LoadingStrategy .RGB_ALWAYS
124
- with Image .open ("Tests/images/iss634.gif" ) as im :
125
- assert im .mode == "RGB"
126
- assert_image_equal (im , expected_rgb_always )
122
+ monkeypatch .setattr (
123
+ GifImagePlugin , "LOADING_STRATEGY" , GifImagePlugin .LoadingStrategy .RGB_ALWAYS
124
+ )
125
+ with Image .open ("Tests/images/iss634.gif" ) as im :
126
+ assert im .mode == "RGB"
127
+ assert_image_equal (im , expected_rgb_always )
127
128
128
- with Image .open ("Tests/images/chi.gif" ) as im :
129
- assert im .mode == "RGBA"
130
- assert_image_equal (im , expected_rgb_always_rgba )
129
+ with Image .open ("Tests/images/chi.gif" ) as im :
130
+ assert im .mode == "RGBA"
131
+ assert_image_equal (im , expected_rgb_always_rgba )
131
132
132
- GifImagePlugin .LOADING_STRATEGY = (
133
- GifImagePlugin .LoadingStrategy .RGB_AFTER_DIFFERENT_PALETTE_ONLY
134
- )
135
- # Stay in P mode with only a global palette
136
- with Image .open ("Tests/images/chi.gif" ) as im :
137
- assert im .mode == "P"
133
+ monkeypatch .setattr (
134
+ GifImagePlugin ,
135
+ "LOADING_STRATEGY" ,
136
+ GifImagePlugin .LoadingStrategy .RGB_AFTER_DIFFERENT_PALETTE_ONLY ,
137
+ )
138
+ # Stay in P mode with only a global palette
139
+ with Image .open ("Tests/images/chi.gif" ) as im :
140
+ assert im .mode == "P"
138
141
139
- im .seek (1 )
140
- assert im .mode == "P"
141
- assert_image_equal (im .convert ("RGB" ), expected_different )
142
+ im .seek (1 )
143
+ assert im .mode == "P"
144
+ assert_image_equal (im .convert ("RGB" ), expected_different )
142
145
143
- # Change to RGB mode when a frame has an individual palette
144
- with Image .open ("Tests/images/iss634.gif" ) as im :
145
- assert im .mode == "P"
146
+ # Change to RGB mode when a frame has an individual palette
147
+ with Image .open ("Tests/images/iss634.gif" ) as im :
148
+ assert im .mode == "P"
146
149
147
- im .seek (1 )
148
- assert im .mode == "RGB"
149
- finally :
150
- GifImagePlugin .LOADING_STRATEGY = GifImagePlugin .LoadingStrategy .RGB_AFTER_FIRST
150
+ im .seek (1 )
151
+ assert im .mode == "RGB"
151
152
152
153
153
154
def test_optimize () -> None :
@@ -555,17 +556,15 @@ def test_dispose_background_transparency() -> None:
555
556
def test_transparent_dispose (
556
557
loading_strategy : GifImagePlugin .LoadingStrategy ,
557
558
expected_colors : tuple [tuple [int | tuple [int , int , int , int ], ...]],
559
+ monkeypatch : pytest .MonkeyPatch ,
558
560
) -> None :
559
- GifImagePlugin .LOADING_STRATEGY = loading_strategy
560
- try :
561
- with Image .open ("Tests/images/transparent_dispose.gif" ) as img :
562
- for frame in range (3 ):
563
- img .seek (frame )
564
- for x in range (3 ):
565
- color = img .getpixel ((x , 0 ))
566
- assert color == expected_colors [frame ][x ]
567
- finally :
568
- GifImagePlugin .LOADING_STRATEGY = GifImagePlugin .LoadingStrategy .RGB_AFTER_FIRST
561
+ monkeypatch .setattr (GifImagePlugin , "LOADING_STRATEGY" , loading_strategy )
562
+ with Image .open ("Tests/images/transparent_dispose.gif" ) as img :
563
+ for frame in range (3 ):
564
+ img .seek (frame )
565
+ for x in range (3 ):
566
+ color = img .getpixel ((x , 0 ))
567
+ assert color == expected_colors [frame ][x ]
569
568
570
569
571
570
def test_dispose_previous () -> None :
@@ -1398,24 +1397,23 @@ def test_lzw_bits() -> None:
1398
1397
),
1399
1398
)
1400
1399
def test_extents (
1401
- test_file : str , loading_strategy : GifImagePlugin .LoadingStrategy
1400
+ test_file : str ,
1401
+ loading_strategy : GifImagePlugin .LoadingStrategy ,
1402
+ monkeypatch : pytest .MonkeyPatch ,
1402
1403
) -> None :
1403
- GifImagePlugin .LOADING_STRATEGY = loading_strategy
1404
- try :
1405
- with Image .open ("Tests/images/" + test_file ) as im :
1406
- assert im .size == (100 , 100 )
1404
+ monkeypatch .setattr (GifImagePlugin , "LOADING_STRATEGY" , loading_strategy )
1405
+ with Image .open ("Tests/images/" + test_file ) as im :
1406
+ assert im .size == (100 , 100 )
1407
1407
1408
- # Check that n_frames does not change the size
1409
- assert im .n_frames == 2
1410
- assert im .size == (100 , 100 )
1408
+ # Check that n_frames does not change the size
1409
+ assert im .n_frames == 2
1410
+ assert im .size == (100 , 100 )
1411
1411
1412
- im .seek (1 )
1413
- assert im .size == (150 , 150 )
1412
+ im .seek (1 )
1413
+ assert im .size == (150 , 150 )
1414
1414
1415
- im .load ()
1416
- assert im .im .size == (150 , 150 )
1417
- finally :
1418
- GifImagePlugin .LOADING_STRATEGY = GifImagePlugin .LoadingStrategy .RGB_AFTER_FIRST
1415
+ im .load ()
1416
+ assert im .im .size == (150 , 150 )
1419
1417
1420
1418
1421
1419
def test_missing_background () -> None :
0 commit comments