Catch DeprecationWarning from initial import (#29)

Catch DeprecationWarning from initial import
This commit is contained in:
Hugo 2019-02-16 14:50:54 +02:00 committed by GitHub
commit 57e0e61b9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,13 +1,16 @@
from .helper import PillowTestCase, hopper from .helper import PillowTestCase, hopper
from PIL import ImageQt import warnings
deprecated = False
with warnings.catch_warnings():
warnings.filterwarnings("error", category=DeprecationWarning)
try: try:
# Python 3 from PIL import ImageQt
from importlib import reload except DeprecationWarning:
except ImportError: deprecated = True
# Python 2.7 warnings.filterwarnings("ignore", category=DeprecationWarning)
pass from PIL import ImageQt
if ImageQt.qt_is_installed: if ImageQt.qt_is_installed:
from PIL.ImageQt import qRgba from PIL.ImageQt import qRgba
@ -86,5 +89,4 @@ class TestImageQt(PillowQtTestCase, PillowTestCase):
ImageQt.ImageQt(hopper(mode)) ImageQt.ImageQt(hopper(mode))
def test_deprecated(self): def test_deprecated(self):
expected = DeprecationWarning if ImageQt.qt_version in ["4", "side"] else None self.assertEqual(ImageQt.qt_version in ["4", "side"], deprecated)
self.assert_warning(expected, reload, ImageQt)