Skip to content
Open
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
2 changes: 1 addition & 1 deletion lib/matplotlib/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ def grab_frame(self, **savefig_kwargs):

def _args(self):
"""Assemble list of encoder-specific command-line arguments."""
return NotImplementedError("args needs to be implemented by subclass.")
raise NotImplementedError("args needs to be implemented by subclass.")

@classmethod
def bin_path(cls):
Expand Down
11 changes: 11 additions & 0 deletions lib/matplotlib/tests/test_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,17 @@ def _run(self):
assert writer.dpi == fig.dpi


def test_movie_writer_args_not_implemented():
# MovieWriter._args is a placeholder that subclasses must override; it
# must *raise* NotImplementedError rather than merely returning it, so a
# subclass that forgets to override it fails loudly instead of passing an
# exception instance on as if it were the command-line arguments.
writer = animation.MovieWriter.__new__(animation.MovieWriter)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be clearer here if you did as the comment says and subclass MovieWriter without implementing _args:

Suggested change
writer = animation.MovieWriter.__new__(animation.MovieWriter)
class IncorrectMovieWriter(animation.MovieWriter):
pass
writer = IncorrectMovieWriter()

with pytest.raises(NotImplementedError,
match="args needs to be implemented by subclass"):
writer._args()


@animation.writers.register('null')
class RegisteredNullMovieWriter(NullMovieWriter):

Expand Down
Loading