move image mode info variables to helper.py

This commit is contained in:
Yay295 2023-01-02 16:55:31 -06:00
parent 139245a3db
commit 5a4b771fb0
2 changed files with 39 additions and 36 deletions

View File

@ -13,7 +13,7 @@ import sysconfig
import tempfile import tempfile
from functools import lru_cache from functools import lru_cache
from io import BytesIO from io import BytesIO
from typing import Any, Callable, Sequence from typing import Any, Callable, NamedTuple, Sequence
import pytest import pytest
from packaging.version import parse as parse_version from packaging.version import parse as parse_version
@ -29,6 +29,40 @@ elif "GITHUB_ACTIONS" in os.environ:
uploader = "github_actions" uploader = "github_actions"
class ImageModeInfo(NamedTuple):
name: str
pixel_size: int
image_modes = (
ImageModeInfo("1", 1),
ImageModeInfo("L", 1),
ImageModeInfo("LA", 4),
ImageModeInfo("La", 4),
ImageModeInfo("P", 1),
ImageModeInfo("PA", 4),
ImageModeInfo("F", 4),
ImageModeInfo("I", 4),
ImageModeInfo("I;16", 2),
ImageModeInfo("I;16L", 2),
ImageModeInfo("I;16B", 2),
ImageModeInfo("I;16N", 2),
ImageModeInfo("RGB", 4),
ImageModeInfo("RGBA", 4),
ImageModeInfo("RGBa", 4),
ImageModeInfo("RGBX", 4),
ImageModeInfo("BGR;15", 2),
ImageModeInfo("BGR;16", 2),
ImageModeInfo("BGR;24", 3),
ImageModeInfo("CMYK", 4),
ImageModeInfo("YCbCr", 4),
ImageModeInfo("HSV", 4),
ImageModeInfo("LAB", 4),
)
image_mode_names = [mode.name for mode in image_modes]
def upload(a: Image.Image, b: Image.Image) -> str | None: def upload(a: Image.Image, b: Image.Image) -> str | None:
if uploader == "show": if uploader == "show":
# local img.show for errors. # local img.show for errors.

View File

@ -8,7 +8,7 @@ import sys
import tempfile import tempfile
import warnings import warnings
from pathlib import Path from pathlib import Path
from typing import IO, NamedTuple from typing import IO
import pytest import pytest
@ -23,51 +23,20 @@ from PIL import (
) )
from .helper import ( from .helper import (
ImageModeInfo,
assert_image_equal, assert_image_equal,
assert_image_equal_tofile, assert_image_equal_tofile,
assert_image_similar_tofile, assert_image_similar_tofile,
assert_not_all_same, assert_not_all_same,
hopper, hopper,
image_mode_names,
image_modes,
is_win32, is_win32,
mark_if_feature_version, mark_if_feature_version,
skip_unless_feature, skip_unless_feature,
) )
class ImageModeInfo(NamedTuple):
name: str
pixel_size: int
image_modes = (
ImageModeInfo("1", 1),
ImageModeInfo("L", 1),
ImageModeInfo("LA", 4),
ImageModeInfo("La", 4),
ImageModeInfo("P", 1),
ImageModeInfo("PA", 4),
ImageModeInfo("F", 4),
ImageModeInfo("I", 4),
ImageModeInfo("I;16", 2),
ImageModeInfo("I;16L", 2),
ImageModeInfo("I;16B", 2),
ImageModeInfo("I;16N", 2),
ImageModeInfo("RGB", 4),
ImageModeInfo("RGBA", 4),
ImageModeInfo("RGBa", 4),
ImageModeInfo("RGBX", 4),
ImageModeInfo("BGR;15", 2),
ImageModeInfo("BGR;16", 2),
ImageModeInfo("BGR;24", 3),
ImageModeInfo("CMYK", 4),
ImageModeInfo("YCbCr", 4),
ImageModeInfo("HSV", 4),
ImageModeInfo("LAB", 4),
)
image_mode_names = [mode.name for mode in image_modes]
class TestImage: class TestImage:
@pytest.mark.parametrize("mode", image_mode_names) @pytest.mark.parametrize("mode", image_mode_names)
def test_image_modes_success(self, mode: str) -> None: def test_image_modes_success(self, mode: str) -> None: