Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn if an unknown feature is passed to features.check() #4438

Merged
merged 1 commit into from Mar 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions Tests/test_features.py
Expand Up @@ -44,6 +44,13 @@ def test_check_modules():
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():
assert isinstance(features.get_supported_modules(), list)
assert isinstance(features.get_supported_codecs(), list)
Expand Down
17 changes: 9 additions & 8 deletions src/PIL/features.py
@@ -1,6 +1,7 @@
import collections
import os
import sys
import warnings

import PIL

Expand Down Expand Up @@ -76,14 +77,14 @@ def get_supported_features():


def check(feature):
return (
feature in modules
and check_module(feature)
or feature in codecs
and check_codec(feature)
or feature in features
and check_feature(feature)
)
if feature in modules:
return check_module(feature)
if feature in codecs:
return check_codec(feature)
if feature in features:
return check_feature(feature)
warnings.warn("Unknown feature '%s'." % feature, stacklevel=2)
return False


def get_supported():
Expand Down