Skip to content

Commit 0de9707

Browse files
committed
PLOT: allow and ignore animate arg in plot command outside jupyter env [MPY-317]
1 parent 3b6c7fa commit 0de9707

2 files changed

Lines changed: 7 additions & 15 deletions

File tree

metview/bindings.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,12 +1107,7 @@ def __call__(self, *args, **kwargs):
11071107
# generates a widget allowing the user to select between plot frames
11081108
def plot_to_notebook(*args, **kwargs): # pragma: no cover
11091109

1110-
if not plot.plot_to_jupyter:
1111-
raise EnvironmentError(
1112-
"animate() can only be used after calling setoutput('jupyter')"
1113-
)
1114-
1115-
animation_mode = kwargs.get("animate", "auto") # True, False or "auto"
1110+
animation_mode = kwargs.get("animate", "auto") # True, False or "auto"
11161111

11171112
# create all the widgets first so that the 'waiting' label is at the bottom
11181113
image_widget = widgets.Image(
@@ -1202,7 +1197,6 @@ def plot_frame(frame_index):
12021197
im_file.close()
12031198
image_widget.value = imf
12041199

1205-
12061200
# everything is ready now, so plot the first frame, hide the
12071201
# 'waiting' label and reveal the plot and the frame slider
12081202
plot_frame(1)
@@ -1218,6 +1212,7 @@ def setoutput(*args, **kwargs):
12181212
if "jupyter" in args: # pragma: no cover
12191213
try:
12201214
import IPython
1215+
12211216
get_ipython = IPython.get_ipython
12221217
except ImportError as imperr:
12231218
print("Could not import IPython module - plotting to Jupyter will not work")
@@ -1237,7 +1232,9 @@ def setoutput(*args, **kwargs):
12371232
global widgets
12381233
widgets = __import__("ipywidgets", globals(), locals())
12391234
except ImportError as imperr:
1240-
print("Could not import ipywidgets module - plotting to Jupyter will not work")
1235+
print(
1236+
"Could not import ipywidgets module - plotting to Jupyter will not work"
1237+
)
12411238
raise imperr
12421239

12431240
else:

tests/test_metview.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,8 @@ def test_plot_2():
15101510
"contour_shade_colour_direction": "clockwise",
15111511
}
15121512
degraded_field = mv.read(data=TEST_FIELDSET, grid=[4, 4])
1513-
mv.plot(png, degraded_field, mv.mcont(grid_shade))
1513+
# animate=True just to check that it is allowed and ignored as a param
1514+
mv.plot(png, degraded_field, mv.mcont(grid_shade), animate=True)
15141515
output_name_from_magics = output_name + ".1.png"
15151516
assert os.path.isfile(output_name_from_magics)
15161517
os.remove(output_name_from_magics)
@@ -1557,12 +1558,6 @@ def test_plot_2_pages():
15571558
os.remove(output_name_from_magics)
15581559

15591560

1560-
def test_animate_exception():
1561-
# this should fail because we are not in a Jupyter environment
1562-
with pytest.raises(EnvironmentError):
1563-
mv.plot(animate=True)
1564-
1565-
15661561
def test_macro_error():
15671562
with pytest.raises(Exception):
15681563
TEST_FIELDSET[125]

0 commit comments

Comments
 (0)