add tests for version numbers

This commit is contained in:
nulano 2020-06-15 15:32:30 +02:00 committed by Andrew Murray
parent 6c1ff252d6
commit d5a6b2584e
3 changed files with 47 additions and 2 deletions

View File

@ -1,4 +1,5 @@
import io
import re
import pytest
from PIL import features
@ -21,6 +22,27 @@ def test_check():
assert features.check_feature(feature) == features.check(feature)
def test_version():
# Check the correctness of the convenience function
# and the format of version numbers
def test(name, function):
version = features.version(name)
if not features.check(name):
assert version is None
else:
assert function(name) == version
if name != "PIL":
assert version is None or re.search(r"\d+(\.\d+)*$", version)
for module in features.modules:
test(module, features.version_module)
for codec in features.codecs:
test(codec, features.version_codec)
for feature in features.features:
test(feature, features.version_feature)
@skip_unless_feature("webp")
def test_webp_transparency():
assert features.check("transp_webp") != _webp.WebPDecoderBuggyAlpha()
@ -37,9 +59,22 @@ def test_webp_anim():
assert features.check("webp_anim") == _webp.HAVE_WEBPANIM
@skip_unless_feature("libjpeg_turbo")
def test_libjpeg_turbo_version():
assert re.search(r"\d+\.\d+\.\d+$", features.version("libjpeg_turbo"))
@skip_unless_feature("libimagequant")
def test_libimagequant_version():
assert re.search(r"\d+\.\d+\.\d+$", features.version("libimagequant"))
def test_check_modules():
for feature in features.modules:
assert features.check_module(feature) in [True, False]
def test_check_codecs():
for feature in features.codecs:
assert features.check_codec(feature) in [True, False]
@ -64,6 +99,8 @@ def test_unsupported_codec():
# Act / Assert
with pytest.raises(ValueError):
features.check_codec(codec)
with pytest.raises(ValueError):
features.version_codec(codec)
def test_unsupported_module():
@ -72,6 +109,8 @@ def test_unsupported_module():
# Act / Assert
with pytest.raises(ValueError):
features.check_module(module)
with pytest.raises(ValueError):
features.version_module(module)
def test_pilinfo():

View File

@ -3,11 +3,12 @@ import io
import itertools
import logging
import os
import re
from collections import namedtuple
from ctypes import c_float
import pytest
from PIL import Image, ImageFilter, TiffImagePlugin, TiffTags
from PIL import Image, ImageFilter, TiffImagePlugin, TiffTags, features
from .helper import (
assert_image_equal,
@ -47,6 +48,9 @@ class LibTiffTestCase:
class TestFileLibTiff(LibTiffTestCase):
def test_version(self):
assert re.search(r"\d+\.\d+\.\d+$", features.version_codec("libtiff"))
def test_g4_tiff(self, tmp_path):
"""Test the ordinary file path load path"""

View File

@ -1,7 +1,8 @@
import io
import re
import pytest
from PIL import Image, WebPImagePlugin
from PIL import Image, WebPImagePlugin, features
from .helper import (
assert_image_similar,
@ -38,6 +39,7 @@ class TestFileWebp:
def test_version(self):
_webp.WebPDecoderVersion()
_webp.WebPDecoderBuggyAlpha()
assert re.search(r"\d+\.\d+\.\d+$", features.version_module("webp"))
def test_read_rgb(self):
"""