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 (size_mode : str , origin : str , rle : str , tmp_path : Path ) -> None :
2635 def roundtrip (original_im : Image .Image ) -> None :
2736 out = tmp_path / "temp.tga"
2837
@@ -36,33 +45,26 @@ def roundtrip(original_im: Image.Image) -> None:
3645
3746 assert_image_equal (saved_im , original_im )
3847
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 )
48+ size , mode = size_mode
49+ png_path = os .path .join (_TGA_DIR_COMMON , size + "_" + mode .lower () + ".png" )
50+ with Image .open (png_path ) as reference_im :
51+ assert reference_im .mode == mode
52+
53+ path_no_ext = os .path .splitext (png_path )[0 ]
54+ tga_path = "{}_{}_{}.tga" .format (path_no_ext , origin , "rle" if rle else "raw" )
55+
56+ with Image .open (tga_path ) as original_im :
57+ assert original_im .format == "TGA"
58+ assert original_im .get_format_mimetype () == "image/x-tga"
59+ if rle :
60+ assert original_im .info ["compression" ] == "tga_rle"
61+ assert original_im .info ["orientation" ] == _ORIGIN_TO_ORIENTATION [origin ]
62+ if mode == "P" :
63+ assert original_im .getpalette () == reference_im .getpalette ()
64+
65+ assert_image_equal (original_im , reference_im )
66+
67+ roundtrip (original_im )
6668
6769
6870def test_palette_depth_8 () -> None :
0 commit comments