Browse Source

[test] Split compilation test into generation and compilation

So that compilation test can be skipped on systems where lualatex is not
installed.
pull/142/merge
Louis 9 years ago
parent
commit
d905b5f4c0
  1. 10
      test/dynamic.py
  2. 2
      test/test_chordpro/test_parser.py
  3. 42
      test/test_compilation/test_compilation.py

10
test/dynamic.py

@ -13,13 +13,9 @@ class DynamicTest(type):
def __init__(cls, name, bases, nmspc): def __init__(cls, name, bases, nmspc):
super().__init__(name, bases, nmspc) super().__init__(name, bases, nmspc)
for methodname, args in cls._iter_testmethods(): for methodname, testmethod in cls._iter_testmethods():
setattr(cls, methodname, cls._create_test(*args)) setattr(cls, methodname, testmethod)
def _iter_testmethods(cls): def _iter_testmethods(cls):
"""Iterate over test methods.""" """Iterate over dynamically generated test methods."""
raise NotImplementedError()
def _create_test(cls, *args, **kwargs):
"""Create and return a test method."""
raise NotImplementedError() raise NotImplementedError()

2
test/test_chordpro/test_parser.py

@ -58,7 +58,7 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest):
continue continue
yield ( yield (
"test_{}_{}".format(os.path.basename(base), dest), "test_{}_{}".format(os.path.basename(base), dest),
[base, dest], cls._create_test(base, dest),
) )
@classmethod @classmethod

42
test/test_compilation/test_compilation.py

@ -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):

Loading…
Cancel
Save