mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-05-30 02:33:07 +03:00
Merge pull request #4438 from jdufresne/warning
Warn on typos passed to features.check()
This commit is contained in:
commit
974233be45
|
@ -44,6 +44,13 @@ def test_check_modules():
|
||||||
assert features.check_codec(feature) in [True, False]
|
assert features.check_codec(feature) in [True, False]
|
||||||
|
|
||||||
|
|
||||||
|
def test_check_warns_on_nonexistent():
|
||||||
|
with pytest.warns(UserWarning) as cm:
|
||||||
|
has_feature = features.check("typo")
|
||||||
|
assert has_feature is False
|
||||||
|
assert str(cm[-1].message) == "Unknown feature 'typo'."
|
||||||
|
|
||||||
|
|
||||||
def test_supported_modules():
|
def test_supported_modules():
|
||||||
assert isinstance(features.get_supported_modules(), list)
|
assert isinstance(features.get_supported_modules(), list)
|
||||||
assert isinstance(features.get_supported_codecs(), list)
|
assert isinstance(features.get_supported_codecs(), list)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import collections
|
import collections
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import warnings
|
||||||
|
|
||||||
import PIL
|
import PIL
|
||||||
|
|
||||||
|
@ -76,14 +77,14 @@ def get_supported_features():
|
||||||
|
|
||||||
|
|
||||||
def check(feature):
|
def check(feature):
|
||||||
return (
|
if feature in modules:
|
||||||
feature in modules
|
return check_module(feature)
|
||||||
and check_module(feature)
|
if feature in codecs:
|
||||||
or feature in codecs
|
return check_codec(feature)
|
||||||
and check_codec(feature)
|
if feature in features:
|
||||||
or feature in features
|
return check_feature(feature)
|
||||||
and check_feature(feature)
|
warnings.warn("Unknown feature '%s'." % feature, stacklevel=2)
|
||||||
)
|
return False
|
||||||
|
|
||||||
|
|
||||||
def get_supported():
|
def get_supported():
|
||||||
|
|
Loading…
Reference in New Issue
Block a user