|
@ -18,51 +18,68 @@ LANGUAGES = { |
|
|
# Set to True if you want to create missing rendered files |
|
|
# Set to True if you want to create missing rendered files |
|
|
CREATE_MISSING_RENDERED_FILE = False |
|
|
CREATE_MISSING_RENDERED_FILE = False |
|
|
|
|
|
|
|
|
class TestParsingRendering(unittest.TestCase): |
|
|
def load_tests(loader, tests, pattern): |
|
|
|
|
|
""" |
|
|
|
|
|
Add all `*.source` files to the test suite. |
|
|
|
|
|
""" |
|
|
|
|
|
del loader, tests, pattern |
|
|
|
|
|
suite = unittest.TestSuite() |
|
|
|
|
|
for source in sorted(glob.glob(os.path.join( |
|
|
|
|
|
os.path.dirname(__file__), |
|
|
|
|
|
'*.source', |
|
|
|
|
|
))): |
|
|
|
|
|
single_test = TestSingleParsingRendering('run_test') |
|
|
|
|
|
setattr(single_test, 'filename', source) |
|
|
|
|
|
suite.addTest(single_test) |
|
|
|
|
|
return suite |
|
|
|
|
|
|
|
|
|
|
|
class TestSingleParsingRendering(unittest.TestCase): |
|
|
"""Test parsing and rendering""" |
|
|
"""Test parsing and rendering""" |
|
|
|
|
|
|
|
|
maxDiff = None |
|
|
maxDiff = None |
|
|
|
|
|
|
|
|
def test_all(self): |
|
|
def run_test(self): |
|
|
"""Test all `*.source` files. |
|
|
"""Test the self.filename (.source) file. |
|
|
|
|
|
|
|
|
For any given `foo.source`, it is parsed as a chordpro file, and |
|
|
For any given `foo.source`, it is parsed as a chordpro file, and |
|
|
should be rendered as `foo.sgc` with the chordpro renderer, and |
|
|
should be rendered as `foo.sgc` with the chordpro renderer, and |
|
|
`foo.tex` with the latex renderer. |
|
|
`foo.tex` with the latex renderer. |
|
|
""" |
|
|
""" |
|
|
|
|
|
if not hasattr(self, 'filename'): |
|
|
|
|
|
return self.skipTest("No file to test") |
|
|
|
|
|
|
|
|
|
|
|
source = getattr(self, 'filename') |
|
|
config = DEFAULT_CONFIG.copy() |
|
|
config = DEFAULT_CONFIG.copy() |
|
|
config.update({ |
|
|
config.update({ |
|
|
'encoding': 'utf8', |
|
|
'encoding': 'utf8', |
|
|
}) |
|
|
}) |
|
|
for source in sorted(glob.glob(os.path.join( |
|
|
base = source[:-len(".source")] |
|
|
os.path.dirname(__file__), |
|
|
for dest in LANGUAGES: |
|
|
'*.source', |
|
|
destname = "{}.{}".format(base, dest) |
|
|
))): |
|
|
if not os.path.exists(destname): |
|
|
base = source[:-len(".source")] |
|
|
if CREATE_MISSING_RENDERED_FILE: |
|
|
for dest in LANGUAGES: |
|
|
print("Creating " + destname) |
|
|
destname = "{}.{}".format(base, dest) |
|
|
with open(destname, 'w', encoding='utf8') as expectfile: |
|
|
if not os.path.exists(destname): |
|
|
chordproname = "{}.source".format(base) |
|
|
if CREATE_MISSING_RENDERED_FILE: |
|
|
config['filename'] = chordproname |
|
|
print("Creating " + destname) |
|
|
expectfile.write( |
|
|
with open(destname, 'w', encoding='utf8') as expectfile: |
|
|
ChordproSong(None, chordproname, config).render( |
|
|
chordproname = "{}.source".format(base) |
|
|
output=chordproname, |
|
|
config['filename'] = chordproname |
|
|
output_format=LANGUAGES[dest], |
|
|
expectfile.write( |
|
|
|
|
|
ChordproSong(None, chordproname, config).render( |
|
|
|
|
|
output=chordproname, |
|
|
|
|
|
output_format=LANGUAGES[dest], |
|
|
|
|
|
) |
|
|
|
|
|
) |
|
|
|
|
|
continue |
|
|
|
|
|
with open(destname, 'r', encoding='utf8') as expectfile: |
|
|
|
|
|
chordproname = "{}.source".format(base) |
|
|
|
|
|
config['filename'] = chordproname |
|
|
|
|
|
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().strip(), |
|
|
|
|
|
) |
|
|
) |
|
|
|
|
|
) |
|
|
|
|
|
continue |
|
|
|
|
|
with open(destname, 'r', encoding='utf8') as expectfile: |
|
|
|
|
|
chordproname = "{}.source".format(base) |
|
|
|
|
|
config['filename'] = chordproname |
|
|
|
|
|
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().strip(), |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|