Skip to content

Commit fff4371

Browse files
committed
fix up optional mpl management
1 parent 0279fd4 commit fff4371

File tree

4 files changed

+15
-18
lines changed

4 files changed

+15
-18
lines changed

specparam/plts/aperiodic.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from itertools import cycle
44

55
import numpy as np
6-
import matplotlib.pyplot as plt
76

87
from specparam.sim.gen import gen_freqs
98
from specparam.modutils.dependencies import safe_import, check_dependency

specparam/tests/models/test_group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def test_print(tfg):
232232
tfg.print_results()
233233
assert True
234234

235-
def test_save_model_report(tfg):
235+
def test_save_model_report(tfg, skip_if_no_mpl):
236236

237237
file_name = 'test_group_model_report'
238238
tfg.save_model_report(0, file_name, TEST_REPORTS_PATH)

specparam/tests/plts/test_styles.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
from specparam.tests.tutils import plot_test
44

5+
from specparam.modutils.dependencies import safe_import
6+
57
from specparam.plts.style import *
68

9+
plt = safe_import('.pyplot', 'matplotlib')
10+
711
###################################################################################################
812
###################################################################################################
913

@@ -14,17 +18,14 @@ def test_check_style_options():
1418
def test_style_spectrum_plot(skip_if_no_mpl):
1519

1620
# Create a dummy plot and style it
17-
from specparam.modutils.dependencies import safe_import
18-
plt = safe_import('.pyplot', 'matplotlib')
1921
_, ax = plt.subplots()
2022
style_spectrum_plot(ax, False, False)
2123

2224
# Check that axis labels are added - use as proxy that it ran correctly
2325
assert ax.xaxis.get_label().get_text()
2426
assert ax.yaxis.get_label().get_text()
2527

26-
27-
def test_apply_axis_style():
28+
def test_apply_axis_style(skip_if_no_mpl):
2829

2930
_, ax = plt.subplots()
3031

@@ -38,8 +39,7 @@ def test_apply_axis_style():
3839
assert ax.get_xlim() == xlim
3940
assert ax.get_ylabel() == ylabel
4041

41-
42-
def test_apply_line_style():
42+
def test_apply_line_style(skip_if_no_mpl):
4343

4444
# Check applying style to one line
4545
_, ax = plt.subplots()
@@ -60,8 +60,7 @@ def test_apply_line_style():
6060
for line, alpha in zip(ax.get_lines(), alphas):
6161
assert line.get_alpha() == alpha
6262

63-
64-
def test_apply_custom_style():
63+
def test_apply_custom_style(skip_if_no_mpl):
6564

6665
_, ax = plt.subplots()
6766
ax.set_title('placeholder')
@@ -75,8 +74,7 @@ def test_apply_custom_style():
7574
apply_custom_style(ax, title_fontsize=new_title_fontsize)
7675
assert ax.title.get_size() == new_title_fontsize
7776

78-
79-
def test_apply_style():
77+
def test_apply_style(skip_if_no_mpl):
8078

8179
_, ax = plt.subplots()
8280

@@ -89,9 +87,8 @@ def my_custom_styler(ax, **kwargs):
8987
# Apply plot style passing in a styler
9088
apply_style(ax, custom_styler=my_custom_styler)
9189

92-
9390
@plot_test
94-
def test_style_plot():
91+
def test_style_plot(skip_if_no_mpl):
9592

9693
@style_plot
9794
def example_plot():

specparam/tests/plts/test_utils.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
from specparam.plts.utils import *
1111

12-
mpl = safe_import('matplotlib')
12+
#mpl = safe_import('matplotlib')
13+
plt = safe_import('.pyplot', 'matplotlib')
1314

1415
###################################################################################################
1516
###################################################################################################
@@ -19,7 +20,7 @@ def test_check_ax(skip_if_no_mpl):
1920
figsize = [5., 5.]
2021
ax = check_ax(None, figsize=figsize)
2122

22-
assert isinstance(ax, mpl.axes.Axes)
23+
assert isinstance(ax, plt.axes.Axes)
2324
assert figsize == [ax.get_figure().get_figwidth(),
2425
ax.get_figure().get_figheight()]
2526

@@ -79,7 +80,7 @@ def test_check_plot_kwargs(skip_if_no_mpl):
7980
assert plot_kwargs['alpha'] == 0.5
8081
assert plot_kwargs['linewidth'] == 2
8182

82-
def test_savefig():
83+
def test_savefig(skip_if_no_mpl):
8384

8485
@savefig
8586
def example_plot():
@@ -102,7 +103,7 @@ def example_plot():
102103
example_plot(save_fig=False, file_path=TEST_PLOTS_PATH, file_name='test_savefig_nope.pdf')
103104
assert not os.path.exists(TEST_PLOTS_PATH / 'test_savefig_nope.pdf')
104105

105-
def test_save_figure():
106+
def test_save_figure(skip_if_no_mpl):
106107

107108
plt.plot([1, 2], [3, 4])
108109
save_figure(file_name='test_save_figure.pdf', file_path=TEST_PLOTS_PATH)

0 commit comments

Comments
 (0)