Skip to content

Commit 358b290

Browse files
authored
Merge pull request #25299 from meeseeksmachine/auto-backport-of-pr-25238-on-v3.7.x
Backport PR #25238 on branch v3.7.x (Check file path for animation and raise if it does not exist)
2 parents e4a3b14 + 08293ca commit 358b290

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/matplotlib/animation.py

+5-1
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,6 +407,8 @@ def setup(self, fig, outfile, dpi=None, frame_prefix=None):
405407
deleted by `finish`; if not *None*, no temporary files are
406408
deleted.
407409
"""
410+
# Check that path is valid
411+
Path(outfile).parent.resolve(strict=True)
408412
self.fig = fig
409413
self.outfile = outfile
410414
if dpi is None:
@@ -423,7 +427,7 @@ def setup(self, fig, outfile, dpi=None, frame_prefix=None):
423427
self.fname_format_str = '%s%%07d.%s'
424428

425429
def __del__(self):
426-
if self._tmpdir:
430+
if hasattr(self, '_tmpdir') and self._tmpdir:
427431
self._tmpdir.cleanup()
428432

429433
@property

lib/matplotlib/tests/test_animation.py

+10
Original file line numberDiff line numberDiff line change
@@ -506,3 +506,13 @@ 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+
if sys.platform == "win32":
513+
match_str = re.escape("[WinError 3] The system cannot find the path specified:")
514+
else:
515+
match_str = re.escape("[Errno 2] No such file or directory: '/foo")
516+
with pytest.raises(FileNotFoundError, match=match_str):
517+
_ = anim.save("/foo/bar/aardvark/thiscannotreallyexist.mp4",
518+
writer=animation.FFMpegFileWriter())

0 commit comments

Comments
 (0)