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

Skip to content

Backport PR #25238 on branch v3.7.x (Check file path for animation and raise if it does not exist) #25299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/matplotlib/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ def setup(self, fig, outfile, dpi=None):
The DPI (or resolution) for the file. This controls the size
in pixels of the resulting movie file.
"""
# Check that path is valid
Path(outfile).parent.resolve(strict=True)
self.outfile = outfile
self.fig = fig
if dpi is None:
Expand Down Expand Up @@ -405,6 +407,8 @@ def setup(self, fig, outfile, dpi=None, frame_prefix=None):
deleted by `finish`; if not *None*, no temporary files are
deleted.
"""
# Check that path is valid
Path(outfile).parent.resolve(strict=True)
self.fig = fig
self.outfile = outfile
if dpi is None:
Expand All @@ -423,7 +427,7 @@ def setup(self, fig, outfile, dpi=None, frame_prefix=None):
self.fname_format_str = '%s%%07d.%s'

def __del__(self):
if self._tmpdir:
if hasattr(self, '_tmpdir') and self._tmpdir:
self._tmpdir.cleanup()

@property
Expand Down
10 changes: 10 additions & 0 deletions lib/matplotlib/tests/test_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,3 +506,13 @@ def test_disable_cache_warning(anim):
)
assert anim._cache_frame_data is False
anim._init_draw()


def test_movie_writer_invalid_path(anim):
if sys.platform == "win32":
match_str = re.escape("[WinError 3] The system cannot find the path specified:")
else:
match_str = re.escape("[Errno 2] No such file or directory: '/foo")
with pytest.raises(FileNotFoundError, match=match_str):
_ = anim.save("/foo/bar/aardvark/thiscannotreallyexist.mp4",
writer=animation.FFMpegFileWriter())