From d905b5f4c0cf6e42a4c586d6f0cb7dc1c459d70a Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 29 Oct 2015 22:42:01 +0100 Subject: [PATCH] [test] Split compilation test into generation and compilation So that compilation test can be skipped on systems where lualatex is not installed. --- test/dynamic.py | 10 ++---- test/test_chordpro/test_parser.py | 2 +- test/test_compilation/test_compilation.py | 44 ++++++++++++++--------- 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/test/dynamic.py b/test/dynamic.py index 19b721a3..494dfc8f 100644 --- a/test/dynamic.py +++ b/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() diff --git a/test/test_chordpro/test_parser.py b/test/test_chordpro/test_parser.py index 727cabba..f0e94290 100644 --- a/test/test_chordpro/test_parser.py +++ b/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 diff --git a/test/test_compilation/test_compilation.py b/test/test_compilation/test_compilation.py index 11bb197b..dc07107a 100644 --- a/test/test_compilation/test_compilation.py +++ b/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):