|
@ -3,10 +3,10 @@ |
|
|
# pylint: disable=too-few-public-methods |
|
|
# pylint: disable=too-few-public-methods |
|
|
|
|
|
|
|
|
import glob |
|
|
import glob |
|
|
|
|
|
import logging |
|
|
import os |
|
|
import os |
|
|
import subprocess |
|
|
import subprocess |
|
|
import unittest |
|
|
import unittest |
|
|
import logging |
|
|
|
|
|
|
|
|
|
|
|
from patacrep.encoding import open_read |
|
|
from patacrep.encoding import open_read |
|
|
|
|
|
|
|
@ -30,7 +30,7 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest): |
|
|
|
|
|
|
|
|
@classmethod |
|
|
@classmethod |
|
|
def _iter_testmethods(cls): |
|
|
def _iter_testmethods(cls): |
|
|
"""Iterate over songbook files to test.""" |
|
|
"""Iterate over dynamically generated test methods.""" |
|
|
for songbook in sorted(glob.glob(os.path.join( |
|
|
for songbook in sorted(glob.glob(os.path.join( |
|
|
os.path.dirname(__file__), |
|
|
os.path.dirname(__file__), |
|
|
'*.sb', |
|
|
'*.sb', |
|
@ -40,19 +40,20 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest): |
|
|
if not os.path.exists(control): |
|
|
if not os.path.exists(control): |
|
|
continue |
|
|
continue |
|
|
yield ( |
|
|
yield ( |
|
|
"test_{}".format(os.path.basename(base)), |
|
|
"test_generation_{}".format(os.path.basename(base)), |
|
|
[base], |
|
|
cls._create_generation_test(base), |
|
|
|
|
|
) |
|
|
|
|
|
yield ( |
|
|
|
|
|
"test_compilation_{}".format(os.path.basename(base)), |
|
|
|
|
|
cls._create_compilation_test(base), |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
@classmethod |
|
|
@classmethod |
|
|
def _create_test(cls, base): |
|
|
def _create_generation_test(cls, base): |
|
|
"""Return a function testing that `base` compiles.""" |
|
|
"""Return a function testing that `base.tex` is correctly generated.""" |
|
|
|
|
|
|
|
|
def test_compile(self): |
|
|
|
|
|
"""Test that `base` is correctly compiled.""" |
|
|
|
|
|
if base is None: |
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_generation(self): |
|
|
|
|
|
"""Test that `base.tex` is correctly generated.""" |
|
|
songbook = "{}.sb".format(base) |
|
|
songbook = "{}.sb".format(base) |
|
|
|
|
|
|
|
|
# Check tex generation |
|
|
# Check tex generation |
|
@ -83,15 +84,26 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest): |
|
|
expected, |
|
|
expected, |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
test_generation.__doc__ = ( |
|
|
|
|
|
"Test that '{base}' is correctly generated." |
|
|
|
|
|
).format(base=os.path.basename(base)) |
|
|
|
|
|
return test_generation |
|
|
|
|
|
|
|
|
|
|
|
@classmethod |
|
|
|
|
|
def _create_compilation_test(cls, base): |
|
|
|
|
|
"""Return a function testing that `base.tex` is correctly compiled.""" |
|
|
|
|
|
@unittest.skipIf('TRAVIS' in os.environ, |
|
|
|
|
|
"Travis does not support lualatex compilation yet") |
|
|
|
|
|
def test_compilation(self): |
|
|
|
|
|
"""Test that `base` is rendered to pdf.""" |
|
|
# Check compilation |
|
|
# Check compilation |
|
|
if 'TRAVIS' not in os.environ: |
|
|
songbook = "{}.sb".format(base) |
|
|
# Travis does not support lualatex compilation yet |
|
|
|
|
|
self.assertEqual(0, self.compile_songbook(songbook)) |
|
|
self.assertEqual(0, self.compile_songbook(songbook)) |
|
|
|
|
|
|
|
|
test_compile.__doc__ = ( |
|
|
test_compilation.__doc__ = ( |
|
|
"Test that '{base}' is correctly compiled." |
|
|
"Test that '{base}' is correctly compiled." |
|
|
).format(base=os.path.basename(base)) |
|
|
).format(base=os.path.basename(base)) |
|
|
return test_compile |
|
|
return test_compilation |
|
|
|
|
|
|
|
|
@staticmethod |
|
|
@staticmethod |
|
|
def compile_songbook(songbook, steps=None): |
|
|
def compile_songbook(songbook, steps=None): |
|
|