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. 44
      test/test_compilation/test_compilation.py

10
test/dynamic.py

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

2
test/test_chordpro/test_parser.py

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

44
test/test_compilation/test_compilation.py

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

Loading…
Cancel
Save