mirror of https://github.com/patacrep/patacrep.git
Engine for LaTeX songbooks
http://www.patacrep.com
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.8 KiB
56 lines
1.8 KiB
10 years ago
|
"""Tests for the chordpro parser."""
|
||
|
|
||
|
# pylint: disable=too-few-public-methods
|
||
|
|
||
10 years ago
|
import glob
|
||
|
import os
|
||
|
import unittest
|
||
|
|
||
9 years ago
|
from patacrep.build import DEFAULT_CONFIG
|
||
|
from patacrep.songs.chordpro import ChordproSong
|
||
9 years ago
|
|
||
|
from .. import disable_logging
|
||
9 years ago
|
|
||
9 years ago
|
LANGUAGES = {
|
||
|
'tex': 'latex',
|
||
|
'sgc': 'chordpro',
|
||
|
}
|
||
10 years ago
|
|
||
9 years ago
|
class TestParsingRendering(unittest.TestCase):
|
||
|
"""Test parsing and rendering"""
|
||
10 years ago
|
|
||
|
maxDiff = None
|
||
|
|
||
9 years ago
|
def test_all(self):
|
||
9 years ago
|
"""Test of chorpro parser, and several renderers.
|
||
9 years ago
|
|
||
|
For any given `foo.source`, it is parsed as a chordpro file, and
|
||
|
should be rendered as `foo.sgc` with the chordpro renderer, and
|
||
|
`foo.tex` with the latex renderer.
|
||
|
"""
|
||
9 years ago
|
config = DEFAULT_CONFIG.copy()
|
||
|
config.update({
|
||
|
'encoding': 'utf8',
|
||
|
})
|
||
9 years ago
|
for source in sorted(glob.glob(os.path.join(
|
||
|
os.path.dirname(__file__),
|
||
|
'*.source',
|
||
|
))):
|
||
|
base = source[:-len(".source")]
|
||
9 years ago
|
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)
|
||
9 years ago
|
config['filename'] = chordproname
|
||
9 years ago
|
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(),
|
||
9 years ago
|
expectfile.read().strip(),
|
||
9 years ago
|
)
|