Browse Source

[chordpro] Firsts LaTeX tests

pull/79/head
Louis 9 years ago
parent
commit
d00fcad19e
  1. 12
      patacrep/content/song.py
  2. 14
      patacrep/songs/chordpro/data/latex/song
  3. 10
      patacrep/songs/chordpro/test/02.sgc.tex
  4. 36
      patacrep/songs/chordpro/test/test_parser.py

12
patacrep/content/song.py

@ -4,6 +4,7 @@ import glob
import jinja2
import logging
import os
import textwrap
from patacrep.content import process_content, ContentError, Content
from patacrep import files, errors
@ -34,7 +35,16 @@ class SongRenderer(Content):
def render(self, context):
"""Return the string that will render the song."""
return self.song.render(output=context['filename'], output_format="latex")
return textwrap.dedent("""\
{separator}
%% {path}
{song}
""").format(
separator="%"*80,
path=self.song.subpath,
song=self.song.render(output=context['filename'], output_format="latex"),
)
#pylint: disable=unused-argument
def parse(keyword, argument, contentlist, config):

14
patacrep/songs/chordpro/data/latex/song

@ -1,12 +1,10 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ((path))
(* if language is defined -*)
\selectlanguage{((language))}
(* endif *)
(*- if metadata.columns is defined *)
\songcolumns{(( metadata.columns ))}
(* endif *)
\beginsong{
(*- for title in titles -*)
@ -33,9 +31,9 @@
(* if (metadata.cov is defined) or (metadata.vcov is defined) *)
\cover
(* endif -*)
(* endif *)
(* for chord in metadata['define'] *)
(*- for chord in metadata['define'] *)
(( render(chord) ))
(* endfor *)
@ -44,5 +42,3 @@
(* endfor *)
\endsong
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

10
patacrep/songs/chordpro/test/02.sgc.tex

@ -0,0 +1,10 @@
\selectlanguage{english}
\beginsong{A directive}[
by={
},
]
\endsong

36
patacrep/songs/chordpro/test/test_parser.py

@ -10,6 +10,10 @@ from patacrep.build import DEFAULT_CONFIG
from patacrep.songs.chordpro import ChordproSong
from patacrep.test import disable_logging
LANGUAGES = {
'tex': 'latex',
'sgc': 'chordpro',
}
class TestParsingRendering(unittest.TestCase):
"""Test parsing and rendering"""
@ -26,17 +30,21 @@ class TestParsingRendering(unittest.TestCase):
'*.source',
))):
base = source[:-len(".source")]
with open("{}.sgc".format(base), 'r', encoding='utf8') as expectfile:
chordproname = "{}.source".format(base)
with disable_logging():
with self.subTest(base=os.path.basename(base)):
self.assertMultiLineEqual(
ChordproSong(None, chordproname, config).render(
output=chordproname,
output_format="chordpro",
).strip(),
expectfile.read().replace(
"DIRNAME",
os.path.dirname(base),
).strip(),
)
for dest in LANGUAGES:
destname = "{}.{}".format(base, dest)
if not os.path.exists(destname):
continue
with open(destname, 'r', encoding='utf8') as expectfile:
chordproname = "{}.source".format(base)
with disable_logging():
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().replace(
"DIRNAME",
os.path.dirname(base),
).strip(),
)

Loading…
Cancel
Save