Skip to content

Commit 67ddbc8

Browse files
committed
Ensure that ImageNormalize is importable (but not necessarily functional) even if matplotlib is not installed.
1 parent d8f84c5 commit 67ddbc8

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

‎astropy/visualization/mpl_normalize.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
import numpy as np
88
from numpy import ma
99

10-
from matplotlib.colors import Normalize
11-
10+
try:
11+
from matplotlib.colors import Normalize
12+
except ImportError:
13+
class Normalize(object):
14+
def __init__(self, *args, **kwargs):
15+
raise ImportError("matplotlib is required in order to use this class")
1216

1317
__all__ = ['ImageNormalize']
1418

‎astropy/visualization/tests/test_norm.py‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,20 @@
1010
HAS_MATPLOTLIB = True
1111
except:
1212
HAS_MATPLOTLIB = False
13-
else:
14-
from ..mpl_normalize import ImageNormalize
13+
14+
from ..mpl_normalize import ImageNormalize
1515

1616
from ...tests.helper import pytest
1717
from ..stretch import SqrtStretch
1818

1919

20+
@pytest.mark.skipif('HAS_MATPLOTLIB')
21+
def test_error_message():
22+
with pytest.raises(ImportError) as exc:
23+
ImageNormalize()
24+
assert exc.value.args[0] == "matplotlib is required in order to use this class"
25+
26+
2027
@pytest.mark.skipif('not HAS_MATPLOTLIB')
2128
def test_normalize_scalar():
2229

0 commit comments

Comments
 (0)