Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 51af37f

Browse files
committed
Check file path for animation and raise if it does not exist
1 parent 22d036e commit 51af37f

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

lib/matplotlib/animation.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ def setup(self, fig, outfile, dpi=None):
193193
The DPI (or resolution) for the file. This controls the size
194194
in pixels of the resulting movie file.
195195
"""
196+
# Check that path is valid
197+
Path(outfile).parent.resolve(strict=True)
196198
self.outfile = outfile
197199
self.fig = fig
198200
if dpi is None:
@@ -405,11 +407,7 @@ def setup(self, fig, outfile, dpi=None, frame_prefix=None):
405407
deleted by `finish`; if not *None*, no temporary files are
406408
deleted.
407409
"""
408-
self.fig = fig
409-
self.outfile = outfile
410-
if dpi is None:
411-
dpi = self.fig.dpi
412-
self.dpi = dpi
410+
super().setup(fig, outfile, dpi=dpi)
413411
self._adjust_frame_size()
414412

415413
if frame_prefix is None:

lib/matplotlib/tests/test_animation.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,3 +506,10 @@ def test_disable_cache_warning(anim):
506506
)
507507
assert anim._cache_frame_data is False
508508
anim._init_draw()
509+
510+
511+
def test_movie_writer_invalid_path(anim):
512+
with pytest.raises(FileNotFoundError,
513+
match=re.escape("[Errno 2] No such file or directory: '/foo")):
514+
anim.save("/foo/bar/aardvark/thiscannotreallyexist.mp4",
515+
writer=animation.FFMpegFileWriter())

0 commit comments

Comments
 (0)