From b73027c865b29ff199bca0b086b9eacca1404062 Mon Sep 17 00:00:00 2001 From: Louis Date: Wed, 23 Sep 2015 19:38:37 +0200 Subject: [PATCH] Clarified signature of `patacrep.songs.ChordproSong.render()` --- patacrep/songs/__init__.py | 6 +++--- patacrep/songs/chordpro/__init__.py | 6 ++---- patacrep/songs/latex/__init__.py | 2 ++ test/test_chordpro/test_parser.py | 1 - 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/patacrep/songs/__init__.py b/patacrep/songs/__init__.py index 0b7cabeb..0eb0b7e2 100644 --- a/patacrep/songs/__init__.py +++ b/patacrep/songs/__init__.py @@ -165,16 +165,16 @@ class Song: def __repr__(self): return repr((self.titles, self.data, self.fullpath)) - def render(self, output, output_format): + def render(self, output_format, output=None, *args, **kwargs): """Return the code rendering this song. Arguments: - - output: Name of the output file. - output_format: Format of the output file (latex, chordpro...) + - output: Name of the output file, or `None` if irrelevant. """ method = "render_{}".format(output_format) if hasattr(self, method): - return getattr(self, method)(output) + return getattr(self, method)(output, *args, **kwargs) raise NotImplementedError() def _parse(self, config): # pylint: disable=no-self-use diff --git a/patacrep/songs/chordpro/__init__.py b/patacrep/songs/chordpro/__init__.py index bcaa68bd..3ba87169 100644 --- a/patacrep/songs/chordpro/__init__.py +++ b/patacrep/songs/chordpro/__init__.py @@ -36,9 +36,7 @@ class ChordproSong(Song): 'song': song, } - def render(self, output, output_format, content=None, template="song"): # pylint: disable=arguments-differ - if content is None: - content = self.cached['song'].content + def render(self, output_format, output=None, template="song"): context = { 'language': self.languages[0], "titles": self.titles, @@ -46,7 +44,7 @@ class ChordproSong(Song): "metadata": self.data, "render": self._render_ast, "config": self.config, - "content": content, + "content": self.cached['song'].content, } jinjaenv = Environment(loader=FileSystemLoader( diff --git a/patacrep/songs/latex/__init__.py b/patacrep/songs/latex/__init__.py index a0d9c945..805f77f2 100644 --- a/patacrep/songs/latex/__init__.py +++ b/patacrep/songs/latex/__init__.py @@ -30,6 +30,8 @@ class LatexSong(Song): def render_latex(self, output): """Return the code rendering the song.""" + if output is None: + raise ValueError(output) path = files.path2posix(files.relpath( self.fullpath, os.path.dirname(output) diff --git a/test/test_chordpro/test_parser.py b/test/test_chordpro/test_parser.py index 2bdd15aa..796fdb2a 100644 --- a/test/test_chordpro/test_parser.py +++ b/test/test_chordpro/test_parser.py @@ -48,7 +48,6 @@ class TestParsingRendering(unittest.TestCase): with self.subTest(base=os.path.basename(base), format=dest): self.assertMultiLineEqual( ChordproSong(None, chordproname, config).render( - output=chordproname, output_format=LANGUAGES[dest], ).strip(), expectfile.read().strip(),