Browse Source

Add a test for 'on the fly' compilations

pull/203/head
Oliverpool 9 years ago
parent
commit
f0103c68a9
  1. 2
      patacrep/content/song.py
  2. 133
      test/test_songbook/onthefly/content.onthefly.tex.control
  3. 19
      test/test_songbook/onthefly/content.onthefly.yaml
  4. 59
      test/test_songbook/test_compilation.py

2
patacrep/content/song.py

@ -95,6 +95,8 @@ def parse(keyword, argument, config):
if contentlist: if contentlist:
break break
contentlist = files.recursive_find(songdir.fullpath, plugins.keys()) contentlist = files.recursive_find(songdir.fullpath, plugins.keys())
if contentlist is None:
contentlist = [] # No content was set or found
for elem in contentlist: for elem in contentlist:
before = len(songlist) before = len(songlist)
for songdir in config['_songdir']: for songdir in config['_songdir']:

133
test/test_songbook/onthefly/content.onthefly.tex.control

@ -0,0 +1,133 @@
%% Automatically generated document.
%% You may edit this file but all changes will be overwritten.
%% If you want to change this document, have a look at
%% the templating system.
%%
%% Generated using Songbook <http://www.patacrep.com>
\makeatletter
\def\input@path{ %
{@TEST_FOLDER@/onthefly/../content_datadir/latex/} %
{@DATA_FOLDER@/latex/} %
}
\makeatother
\documentclass[
]{article}
\usepackage[
chorded,
pictures,
diagram,
guitar,
]{patacrep}
\usepackage{lmodern}
\PassOptionsToPackage{english}{babel}
\PassOptionsToPackage{english}{babel}
\usepackage[english]{babel}
\lang{english}
\usepackage{graphicx}
\graphicspath{ %
{@TEST_FOLDER@/onthefly/../content_datadir/} %
{@DATA_FOLDER@/} %
}
\makeatletter
\@ifpackageloaded{hyperref}{}{
\usepackage{url}
\newcommand{\phantomsection}{}
\newcommand{\hyperlink}[2]{#2}
\newcommand{\href}[2]{\expandafter\url\expandafter{#1}}
}
\makeatother
\usepackage{chords}
\title{Guitar songbook}
\author{The Patacrep Team}
\newindex{titleidx}{content.onthefly_title}
\newauthorindex{authidx}{content.onthefly_auth}
\authignoreword{unknown}
\authbyword{by}
\authsepword{and}
\notenamesout{A}{B}{C}{D}{E}{F}{G}
\begin{document}
\maketitle
\showindex{\songindexname}{titleidx}
\showindex{\authorindexname}{authidx}
% list of chords
\ifchorded
\ifdiagram
\phantomsection
\addcontentsline{toc}{section}{\chordlistname}
\chords
\fi
\fi
\phantomsection
\addcontentsline{toc}{section}{\songlistname}
\section{Test of section}
\begin{songs}{titleidx,authidx}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% songs/./song.csg
\selectlanguage{english}
\beginsong{This is a song}[
by={
},
]
\begin{verse}
Foo
\end{verse}
\endsong
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% songs/./song.tsg
\import{@TEST_FOLDER@/content_datadir/songs/}{song.tsg}
\end{songs}
\songsection{Test of song section}
\input{@TEST_FOLDER@/content_datadir/content/foo.tex}
\section{This is an included section}
\end{document}

19
test/test_songbook/onthefly/content.onthefly.yaml

@ -0,0 +1,19 @@
book:
pictures: yes
datadir: ../content_datadir
lang: en
template: default.tex
chords:
repeatchords: no
diagramreminder: all
content:
- section: Test of section
- sort:
- songsection: Test of song section
- cwd:
# relative to datadir
path: ../content
content:
- tex: foo.tex
- include: include.sbc

59
test/test_songbook/test_compilation.py

@ -9,8 +9,13 @@ import sys
import subprocess import subprocess
import unittest import unittest
from patacrep.files import path2posix import yaml
from patacrep.files import path2posix, chdir
from patacrep.songbook import prepare_songbook
from patacrep.build import SongbookBuilder
from .. import logging_reduced
from .. import dynamic # pylint: disable=unused-import from .. import dynamic # pylint: disable=unused-import
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
@ -45,9 +50,23 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest):
"test_pdf_compilation_{}".format(os.path.basename(base)), "test_pdf_compilation_{}".format(os.path.basename(base)),
cls._create_compilation_test(base), cls._create_compilation_test(base),
) )
for songbook in sorted(glob.glob(os.path.join(
os.path.dirname(__file__),
'onthefly',
'*.yaml',
))):
base = os.path.splitext(songbook)[0]
yield (
"test_latex_generation_onthefly_{}".format(os.path.basename(base)),
cls._create_generation_test(base, True),
)
yield (
"test_pdf_compilation_onthefly_{}".format(os.path.basename(base)),
cls._create_compilation_test(base, True),
)
@classmethod @classmethod
def _create_generation_test(cls, base): def _create_generation_test(cls, base, onthefly=False):
"""Return a function testing that `base.tex` is correctly generated.""" """Return a function testing that `base.tex` is correctly generated."""
def test_generation(self): def test_generation(self):
@ -55,7 +74,10 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest):
songbook = "{}.yaml".format(base) songbook = "{}.yaml".format(base)
# Check tex generation # Check tex generation
self.assertEqual(0, self.compile_songbook(songbook, "tex")) if onthefly:
self.compile_songbook_onthefly(base, ['tex'])
else:
self.assertEqual(0, self.compile_songbook(songbook, "tex"))
# Check generated tex # Check generated tex
control = "{}.tex.control".format(base) control = "{}.tex.control".format(base)
@ -93,7 +115,7 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest):
return test_generation return test_generation
@classmethod @classmethod
def _create_compilation_test(cls, base): def _create_compilation_test(cls, base, onthefly=False):
"""Return a function testing that `base.tex` is correctly compiled.""" """Return a function testing that `base.tex` is correctly compiled."""
@unittest.skipIf('TRAVIS' in os.environ, @unittest.skipIf('TRAVIS' in os.environ,
"Travis does not support lualatex compilation yet") "Travis does not support lualatex compilation yet")
@ -101,7 +123,10 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest):
"""Test that `base` is rendered to pdf.""" """Test that `base` is rendered to pdf."""
# Check compilation # Check compilation
songbook = "{}.yaml".format(base) songbook = "{}.yaml".format(base)
self.assertEqual(0, self.compile_songbook(songbook)) if onthefly:
self.compile_songbook_onthefly(base)
else:
self.assertEqual(0, self.compile_songbook(songbook))
test_compilation.__doc__ = ( test_compilation.__doc__ = (
"Test that '{base}' is correctly compiled." "Test that '{base}' is correctly compiled."
@ -130,3 +155,27 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest):
except subprocess.CalledProcessError as error: except subprocess.CalledProcessError as error:
LOGGER.warning(error.output) LOGGER.warning(error.output)
return error.returncode return error.returncode
@staticmethod
def compile_songbook_onthefly(base, steps=None):
"""Compile songbook "on the fly": without a physical songbook file."""
with open(base + ".yaml", mode="r", encoding="utf8") as sbfile:
sbyaml = yaml.load(sbfile)
outputdir = os.path.dirname(base)
outputname = os.path.basename(base)
songbook = prepare_songbook(sbyaml, outputdir, outputname, datadir_prefix=outputdir)
songbook['_error'] = "fix"
songbook['_cache'] = True
sb_builder = SongbookBuilder(songbook)
sb_builder.unsafe = True
with chdir(outputdir):
# Continuous Integration will be verbose
if 'CI' in os.environ:
with logging_reduced(level=logging.DEBUG):
sb_builder.build_steps(steps)
else:
sb_builder.build_steps(steps)

Loading…
Cancel
Save