|
@ -11,32 +11,26 @@ from patacrep.songs.chordpro import ChordproSong |
|
|
from patacrep.test import disable_logging |
|
|
from patacrep.test import disable_logging |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ParserTxtRenderer(unittest.TestCase): |
|
|
class TestParsingRendering(unittest.TestCase): |
|
|
"""Test parser, and renderer as a txt file.""" |
|
|
"""Test parsing and rendering""" |
|
|
|
|
|
|
|
|
maxDiff = None |
|
|
maxDiff = None |
|
|
|
|
|
|
|
|
def __init__(self, methodname="runTest", basename=None): |
|
|
def test_all(self): |
|
|
super().__init__(methodname) |
|
|
|
|
|
self.basename = basename |
|
|
|
|
|
|
|
|
|
|
|
def shortDescription(self): |
|
|
|
|
|
return "Parsing file '{}.txt'.".format(self.basename) |
|
|
|
|
|
|
|
|
|
|
|
def runTest(self): |
|
|
|
|
|
"""Test txt output (default, debug output).""" |
|
|
|
|
|
# pylint: disable=invalid-name |
|
|
|
|
|
|
|
|
|
|
|
if self.basename is None: |
|
|
|
|
|
return |
|
|
|
|
|
config = DEFAULT_CONFIG.copy() |
|
|
config = DEFAULT_CONFIG.copy() |
|
|
config.update({ |
|
|
config.update({ |
|
|
'encoding': 'utf8', |
|
|
'encoding': 'utf8', |
|
|
'_compiled_authwords': {}, |
|
|
'_compiled_authwords': {}, |
|
|
}) |
|
|
}) |
|
|
with open("{}.txt".format(self.basename), 'r', encoding='utf8') as expectfile: |
|
|
for source in sorted(glob.glob(os.path.join( |
|
|
chordproname = "{}.sgc".format(self.basename) |
|
|
os.path.dirname(__file__), |
|
|
|
|
|
'*.source', |
|
|
|
|
|
))): |
|
|
|
|
|
base = source[:-len(".source")] |
|
|
|
|
|
with open("{}.sgc".format(base), 'r', encoding='utf8') as expectfile: |
|
|
|
|
|
chordproname = "{}.source".format(base) |
|
|
with disable_logging(): |
|
|
with disable_logging(): |
|
|
|
|
|
with self.subTest(base=os.path.basename(base)): |
|
|
self.assertMultiLineEqual( |
|
|
self.assertMultiLineEqual( |
|
|
ChordproSong(None, chordproname, config).render( |
|
|
ChordproSong(None, chordproname, config).render( |
|
|
output=chordproname, |
|
|
output=chordproname, |
|
@ -44,16 +38,6 @@ class ParserTxtRenderer(unittest.TestCase): |
|
|
).strip(), |
|
|
).strip(), |
|
|
expectfile.read().replace( |
|
|
expectfile.read().replace( |
|
|
"DIRNAME", |
|
|
"DIRNAME", |
|
|
os.path.dirname(self.basename), |
|
|
os.path.dirname(base), |
|
|
).strip(), |
|
|
).strip(), |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
def load_tests(__loader, tests, __pattern): |
|
|
|
|
|
"""Load several tests given test files present in the directory.""" |
|
|
|
|
|
# Load all txt files as tests |
|
|
|
|
|
for txt in sorted(glob.glob(os.path.join( |
|
|
|
|
|
os.path.dirname(__file__), |
|
|
|
|
|
'*.txt', |
|
|
|
|
|
))): |
|
|
|
|
|
tests.addTest(ParserTxtRenderer(basename=txt[:-len('.txt')])) |
|
|
|
|
|
return tests |
|
|
|
|
|