11from __future__ import annotations
22
33import os
4- from glob import glob
5- from itertools import product
64from pathlib import Path
75
86import pytest
1513_TGA_DIR_COMMON = os .path .join (_TGA_DIR , "common" )
1614
1715
18- _MODES = ("L" , "LA" , "P" , "RGB" , "RGBA" )
1916_ORIGINS = ("tl" , "bl" )
2017
2118_ORIGIN_TO_ORIENTATION = {"tl" : 1 , "bl" : - 1 }
2219
2320
24- @pytest .mark .parametrize ("mode" , _MODES )
25- def test_sanity (mode : str , tmp_path : Path ) -> None :
21+ @pytest .mark .parametrize (
22+ "size_mode" ,
23+ (
24+ ("1x1" , "L" ),
25+ ("200x32" , "L" ),
26+ ("200x32" , "LA" ),
27+ ("200x32" , "P" ),
28+ ("200x32" , "RGB" ),
29+ ("200x32" , "RGBA" ),
30+ ),
31+ )
32+ @pytest .mark .parametrize ("origin" , _ORIGINS )
33+ @pytest .mark .parametrize ("rle" , (True , False ))
34+ def test_sanity (
35+ size_mode : tuple [str , str ], origin : str , rle : str , tmp_path : Path
36+ ) -> None :
2637 def roundtrip (original_im : Image .Image ) -> None :
2738 out = tmp_path / "temp.tga"
2839
@@ -36,33 +47,26 @@ def roundtrip(original_im: Image.Image) -> None:
3647
3748 assert_image_equal (saved_im , original_im )
3849
39- png_paths = glob (os .path .join (_TGA_DIR_COMMON , f"*x*_{ mode .lower ()} .png" ))
40-
41- for png_path in png_paths :
42- with Image .open (png_path ) as reference_im :
43- assert reference_im .mode == mode
44-
45- path_no_ext = os .path .splitext (png_path )[0 ]
46- for origin , rle in product (_ORIGINS , (True , False )):
47- tga_path = "{}_{}_{}.tga" .format (
48- path_no_ext , origin , "rle" if rle else "raw"
49- )
50-
51- with Image .open (tga_path ) as original_im :
52- assert original_im .format == "TGA"
53- assert original_im .get_format_mimetype () == "image/x-tga"
54- if rle :
55- assert original_im .info ["compression" ] == "tga_rle"
56- assert (
57- original_im .info ["orientation" ]
58- == _ORIGIN_TO_ORIENTATION [origin ]
59- )
60- if mode == "P" :
61- assert original_im .getpalette () == reference_im .getpalette ()
62-
63- assert_image_equal (original_im , reference_im )
64-
65- roundtrip (original_im )
50+ size , mode = size_mode
51+ png_path = os .path .join (_TGA_DIR_COMMON , size + "_" + mode .lower () + ".png" )
52+ with Image .open (png_path ) as reference_im :
53+ assert reference_im .mode == mode
54+
55+ path_no_ext = os .path .splitext (png_path )[0 ]
56+ tga_path = "{}_{}_{}.tga" .format (path_no_ext , origin , "rle" if rle else "raw" )
57+
58+ with Image .open (tga_path ) as original_im :
59+ assert original_im .format == "TGA"
60+ assert original_im .get_format_mimetype () == "image/x-tga"
61+ if rle :
62+ assert original_im .info ["compression" ] == "tga_rle"
63+ assert original_im .info ["orientation" ] == _ORIGIN_TO_ORIENTATION [origin ]
64+ if mode == "P" :
65+ assert original_im .getpalette () == reference_im .getpalette ()
66+
67+ assert_image_equal (original_im , reference_im )
68+
69+ roundtrip (original_im )
6670
6771
6872def test_palette_depth_8 () -> None :
0 commit comments