diff --git a/examples/example-all.yaml.sb b/examples/example-all.yaml.sb new file mode 100644 index 00000000..3a167565 --- /dev/null +++ b/examples/example-all.yaml.sb @@ -0,0 +1,17 @@ +bookoptions: + - "diagram" + - "repeatchords" + - "lilypond" + - "pictures" +booktype: "chorded" +datadir: "." +template: "patacrep.tex" +lang: "fr" +encoding: "utf8" +authwords: + sep: + - "and" + - "et" +content: + - + - "sorted" \ No newline at end of file diff --git a/patacrep/__init__.py b/patacrep/__init__.py index 60e4cd6a..0158a1f6 100644 --- a/patacrep/__init__.py +++ b/patacrep/__init__.py @@ -1,10 +1,11 @@ """Global variables.""" -from pkg_resources import resource_filename import os +import sys + +from pkg_resources import resource_filename # Check Python version -import sys if sys.version_info < (3, 3): print("ERROR: Your Python version is too old. Please use a Python version > 3.3.") sys.exit(1) diff --git a/patacrep/build.py b/patacrep/build.py index 53cb0d34..7ec0d739 100644 --- a/patacrep/build.py +++ b/patacrep/build.py @@ -11,7 +11,7 @@ from subprocess import Popen, PIPE, call, check_call from patacrep import authors, content, errors, files from patacrep.index import process_sxd from patacrep.templates import TexBookRenderer -from patacrep.songs import DataSubpath +from patacrep.songs import DataSubpath, DEFAULT_CONFIG LOGGER = logging.getLogger(__name__) EOL = "\n" @@ -27,14 +27,6 @@ GENERATED_EXTENSIONS = [ "_title.sbx", "_title.sxd", ] -DEFAULT_CONFIG = { - 'template': "default.tex", - 'lang': 'en', - 'content': [], - 'titleprefixwords': [], - 'encoding': None, - 'datadir': [], - } @@ -49,6 +41,7 @@ class Songbook: def __init__(self, raw_songbook, basename): self._raw_config = raw_songbook + self.config = raw_songbook self.basename = basename self._errors = list() self._config = dict() @@ -142,6 +135,10 @@ class Songbook: continue yield from item.iter_errors() + def requires_lilypond(self): + """Tell if lilypond is part of the bookoptions""" + return 'lilypond' in self.config.get('bookoptions', []) + def _log_pipe(pipe): """Log content from `pipe`.""" while 1: @@ -243,9 +240,23 @@ class SongbookBuilder: stderr=PIPE, universal_newlines=True, ) - except Exception as error: + except FileNotFoundError as error: raise errors.ExecutableNotFound(compiler) + # Test if lilypond compiler is accessible + if self.songbook.requires_lilypond(): + lilypond_compiler = 'lilypond' + try: + check_call( + [lilypond_compiler, "--version"], + stdin=PIPE, + stdout=PIPE, + stderr=PIPE, + universal_newlines=True, + ) + except FileNotFoundError as error: + raise errors.ExecutableNotFound(lilypond_compiler) + # Perform compilation try: process = Popen( diff --git a/patacrep/content/__init__.py b/patacrep/content/__init__.py index 6d00689b..ef389bfd 100755 --- a/patacrep/content/__init__.py +++ b/patacrep/content/__init__.py @@ -66,12 +66,13 @@ More documentation in the docstring of ContentItem. """ import glob -import jinja2 import logging import os import re import sys +import jinja2 + from patacrep import files from patacrep.errors import SharedError @@ -123,7 +124,7 @@ class ContentItem: class ContentError(SharedError): """Error in a content plugin.""" def __init__(self, keyword=None, message=None): - super(ContentError, self).__init__() + super().__init__() self.keyword = keyword self.message = message @@ -217,14 +218,12 @@ def process_content(content, config=None): """ contentlist = ContentList() plugins = config.get('_content_plugins', {}) - keyword_re = re.compile(r'^ *(?P\w*) *(\((?P.*)\))? *$') + keyword_re = re.compile(r'^ *(?P[\w\*]*) *(\((?P.*)\))? *$') if not content: content = [["song"]] for elem in content: if isinstance(elem, str): elem = ["song", elem] - if len(content) == 0: - content = ["song"] try: match = keyword_re.match(elem[0]).groupdict() except AttributeError: diff --git a/patacrep/content/cwd.py b/patacrep/content/cwd.py index d3b02aab..07cc407e 100755 --- a/patacrep/content/cwd.py +++ b/patacrep/content/cwd.py @@ -25,8 +25,7 @@ def parse(keyword, config, argument, contentlist): old_songdir = config['_songdir'] config['_songdir'] = ( [DataSubpath(".", argument)] + - [path.clone().join(argument) for path in config['_songdir']] + - config['_songdir'] + [path.clone().join(argument) for path in config['_songdir']] ) processed_content = process_content(contentlist, config) config['_songdir'] = old_songdir diff --git a/patacrep/content/section.py b/patacrep/content/section.py index fe5cd0b1..6aed27c6 100755 --- a/patacrep/content/section.py +++ b/patacrep/content/section.py @@ -37,8 +37,8 @@ def parse(keyword, argument, contentlist, config): their starred versions "part*", "chapter*", ... , "subparagraph*"): the section to use; - argument: unused; - - contentlist: a list of one or two strings, which are the names (short - and long) of the section; + - contentlist: a list of one or two strings, which are the names (long + and short) of the section; - config: configuration dictionary of the current songbook. """ try: diff --git a/patacrep/content/song.py b/patacrep/content/song.py index fe2297b2..a2cce2c0 100755 --- a/patacrep/content/song.py +++ b/patacrep/content/song.py @@ -1,11 +1,12 @@ """Plugin to include songs to the songbook.""" import glob -import jinja2 import logging import os import textwrap +import jinja2 + from patacrep.content import process_content from patacrep.content import ContentError, ContentItem, ContentList from patacrep import files, errors @@ -83,6 +84,8 @@ def parse(keyword, argument, contentlist, config): if not os.path.isdir(songdir.datadir): continue with files.chdir(songdir.datadir): + # Starting with Python 3.5 glob can be recursive: **/*.csg for instance + # for filename in glob.iglob(os.path.join(songdir.subpath, elem), recursive=True): for filename in glob.iglob(os.path.join(songdir.subpath, elem)): LOGGER.debug('Parsing file "{}"…'.format(filename)) extension = filename.split(".")[-1] diff --git a/patacrep/content/sorted.py b/patacrep/content/sorted.py index 41052770..cdb0dcd2 100755 --- a/patacrep/content/sorted.py +++ b/patacrep/content/sorted.py @@ -9,8 +9,9 @@ import logging import unidecode from patacrep import files -from patacrep.content import ContentError, ContentList -from patacrep.content.song import OnlySongsError, process_songs +from patacrep.content import ContentError, ContentList, EmptyContentList +from patacrep.content import process_content +from patacrep.content.song import OnlySongsError LOGGER = logging.getLogger(__name__) @@ -83,9 +84,9 @@ def parse(keyword, config, argument, contentlist): else: sort = DEFAULT_SORT try: - songlist = process_songs(contentlist, config) + songlist = process_content(contentlist, config) except OnlySongsError as error: - return EmptyContentError(errors=[ContentError(keyword, ( + return EmptyContentList(errors=[ContentError(keyword, ( "Content list of this keyword can be only songs (or content " "that result into songs), and the following are not:" + str(error.not_songs) diff --git a/patacrep/errors.py b/patacrep/errors.py index 2b7e7f06..0db5702b 100644 --- a/patacrep/errors.py +++ b/patacrep/errors.py @@ -11,7 +11,7 @@ class SBFileError(SongbookError): """Error during songbook file decoding""" def __init__(self, message=None): - super(SBFileError, self).__init__() + super().__init__() self.message = message def __str__(self): @@ -21,7 +21,7 @@ class TemplateError(SongbookError): """Error during template generation""" def __init__(self, original, message=None): - super(TemplateError, self).__init__() + super().__init__() self.original = original self.message = message @@ -35,7 +35,7 @@ class ExecutableNotFound(SongbookError): """Couldn't find a LaTeX executable.""" def __init__(self, executable): - super(ExecutableNotFound, self).__init__( + super().__init__( ( """Could not find the following executable: {executable}""" ).format(executable=executable) @@ -45,7 +45,7 @@ class StepError(SongbookError): """Error during execution of one compilation step.""" def __init__(self, message): - super(StepError, self).__init__() + super().__init__() self.message = message def __str__(self): @@ -55,7 +55,7 @@ class LatexCompilationError(StepError): """Error during LaTeX compilation.""" def __init__(self, basename): - super(LatexCompilationError, self).__init__( + super().__init__( ( """Error while LaTeX compilation of "{basename}.tex" """ """(see {basename}.log for more information).""" @@ -66,7 +66,7 @@ class StepCommandError(StepError): """Error during custom command compilation.""" def __init__(self, command, code): - super(StepCommandError, self).__init__(( + super().__init__(( """Error while running custom command "{command}": got return""" " code {code}." ).format(command=command, code=code)) @@ -76,7 +76,7 @@ class CleaningError(SongbookError): """Error during cleaning of LaTeX auxiliary files.""" def __init__(self, filename, exception): - super(CleaningError, self).__init__() + super().__init__() self.filename = filename self.exception = exception @@ -90,7 +90,7 @@ class UnknownStep(StepError): """Unknown compilation step.""" def __init__(self, step): - super(UnknownStep, self).__init__( + super().__init__( """Compilation step "{step}" unknown.""".format(step=step) ) diff --git a/patacrep/index.py b/patacrep/index.py index 12035cb2..767c04ba 100644 --- a/patacrep/index.py +++ b/patacrep/index.py @@ -6,8 +6,8 @@ from a file generated by the latex compilation of the songbook (.sxd). """ import locale -import unidecode import re +import unidecode from patacrep import authors from patacrep import encoding @@ -77,7 +77,7 @@ class Index: def add_keyword(self, key, word): """Add 'word' to self.keywords[key].""" - if not key in self.keywords: + if key not in self.keywords: self.keywords[key] = [] self.keywords[key].append(word) @@ -101,9 +101,9 @@ class Index: similar method with processing. """ first = self.get_first_letter(key[0]) - if not first in self.data: + if first not in self.data: self.data[first] = dict() - if not key in self.data[first]: + if key not in self.data[first]: self.data[first][key] = { 'sortingkey': [ unidecode.unidecode(tex2plain(item)).lower() diff --git a/patacrep/latex/lexer.py b/patacrep/latex/lexer.py index 0e60e826..0b5c2ce7 100644 --- a/patacrep/latex/lexer.py +++ b/patacrep/latex/lexer.py @@ -60,7 +60,7 @@ class SimpleLexer: # Define a rule so we can track line numbers @staticmethod def t_endofline(token): - r'\n+' + r'(\r?\n)+' token.lexer.lineno += len(token.value) @staticmethod diff --git a/patacrep/latex/syntax.py b/patacrep/latex/syntax.py index 992c33a1..890ca79c 100644 --- a/patacrep/latex/syntax.py +++ b/patacrep/latex/syntax.py @@ -130,9 +130,12 @@ class LatexParser(Parser): def p_dictionary(symbols): """dictionary : identifier EQUAL braces dictionary_next | identifier EQUAL error dictionary_next + | empty """ symbols[0] = {} - if isinstance(symbols[3], ast.Expression): + if len(symbols) == 2: + pass + elif isinstance(symbols[3], ast.Expression): symbols[0][symbols[1]] = symbols[3] symbols[0].update(symbols[4]) else: diff --git a/patacrep/songbook/__main__.py b/patacrep/songbook/__main__.py index cc56311b..b62dcf73 100644 --- a/patacrep/songbook/__main__.py +++ b/patacrep/songbook/__main__.py @@ -1,12 +1,12 @@ """Command line tool to compile songbooks using the songbook library.""" import argparse -import json import locale import logging import os.path import textwrap import sys +import yaml from patacrep.build import SongbookBuilder, DEFAULT_STEPS from patacrep.utils import yesno @@ -135,13 +135,13 @@ def main(): try: with patacrep.encoding.open_read(songbook_path) as songbook_file: - songbook = json.load(songbook_file) + songbook = yaml.load(songbook_file) if 'encoding' in songbook: with patacrep.encoding.open_read( songbook_path, encoding=songbook['encoding'] ) as songbook_file: - songbook = json.load(songbook_file) + songbook = yaml.load(songbook_file) except Exception as error: # pylint: disable=broad-except LOGGER.error(error) LOGGER.error("Error while loading file '{}'.".format(songbook_path)) diff --git a/patacrep/songs/__init__.py b/patacrep/songs/__init__.py index 9a357163..e1b14c05 100644 --- a/patacrep/songs/__init__.py +++ b/patacrep/songs/__init__.py @@ -14,6 +14,15 @@ from patacrep.songs import errors as song_errors LOGGER = logging.getLogger(__name__) +DEFAULT_CONFIG = { + 'template': "default.tex", + 'lang': 'en', + 'content': [], + 'titleprefixwords': [], + 'encoding': None, + 'datadir': [], + } + def cached_name(datadir, filename): """Return the filename of the cache version of the file.""" fullpath = os.path.abspath(os.path.join(datadir, '.cache', filename)) @@ -95,7 +104,10 @@ class Song: "_version", ] - def __init__(self, subpath, config, *, datadir=None): + def __init__(self, subpath, config=None, *, datadir=None): + if config is None: + config = DEFAULT_CONFIG.copy() + if datadir is None: self.datadir = "" # Only songs in datadirs may be cached diff --git a/patacrep/songs/chordpro/__init__.py b/patacrep/songs/chordpro/__init__.py index cd3d5933..7ce51138 100644 --- a/patacrep/songs/chordpro/__init__.py +++ b/patacrep/songs/chordpro/__init__.py @@ -1,11 +1,12 @@ """Chordpro parser""" -from jinja2 import Environment, FileSystemLoader, contextfunction, ChoiceLoader -import jinja2 import logging import operator import os +from jinja2 import Environment, FileSystemLoader, contextfunction, ChoiceLoader +import jinja2 + from patacrep import encoding, files, pkg_datapath from patacrep.songs import Song from patacrep.songs.chordpro.syntax import parse_song diff --git a/patacrep/songs/chordpro/syntax.py b/patacrep/songs/chordpro/syntax.py index 44a20f4f..7fcf5d4b 100644 --- a/patacrep/songs/chordpro/syntax.py +++ b/patacrep/songs/chordpro/syntax.py @@ -2,11 +2,11 @@ import functools import logging -import ply.yacc as yacc import re +import ply.yacc as yacc + from patacrep.content import ContentError -from patacrep.songs import errors from patacrep.songs.chordpro import ast from patacrep.songs.chordpro.lexer import tokens, ChordProLexer from patacrep.songs.syntax import Parser diff --git a/patacrep/songs/convert/__main__.py b/patacrep/songs/convert/__main__.py index 90276f7b..19d7041e 100644 --- a/patacrep/songs/convert/__main__.py +++ b/patacrep/songs/convert/__main__.py @@ -8,7 +8,7 @@ import logging import sys from patacrep import files -from patacrep.build import DEFAULT_CONFIG +from patacrep.songs import DEFAULT_CONFIG from patacrep.utils import yesno LOGGER = logging.getLogger(__name__) diff --git a/patacrep/templates.py b/patacrep/templates.py index b329cc71..8e4e32fd 100644 --- a/patacrep/templates.py +++ b/patacrep/templates.py @@ -1,11 +1,12 @@ """Template for .tex generation settings and utilities""" +import re +import json + from jinja2 import Environment, FileSystemLoader, ChoiceLoader, \ TemplateNotFound, nodes from jinja2.ext import Extension from jinja2.meta import find_referenced_templates as find_templates -import re -import json from patacrep import errors, files from patacrep.latex import lang2babel diff --git a/setup.py b/setup.py index 63fbbcc8..fd1b48a5 100755 --- a/setup.py +++ b/setup.py @@ -34,7 +34,7 @@ setup( packages=find_packages(exclude=["test*"]), license="GPLv2 or any later version", install_requires=[ - "unidecode", "jinja2", "ply", + "unidecode", "jinja2", "ply", "pyyaml", ], entry_points={ 'console_scripts': [ diff --git a/test/__init__.py b/test/__init__.py index aa4a5a18..d77a9c27 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -9,11 +9,15 @@ import unittest import patacrep @contextlib.contextmanager -def disable_logging(): - """Context locally disabling logging.""" - logging.disable(logging.CRITICAL) +def logging_reduced(module_name=None, level=logging.CRITICAL): + """Temporarly reduce the logging level of a specific module or globally if None + """ + logger = logging.getLogger(module_name) + old_level = logger.getEffectiveLevel() + + logger.setLevel(level) yield - logging.disable(logging.NOTSET) + logger.setLevel(old_level) def suite(): """Return a :class:`TestSuite` object, testing all module :mod:`patacrep`. diff --git a/test/test_compilation/datadir.sb b/test/test_compilation/datadir.sb deleted file mode 100644 index 357c28d7..00000000 --- a/test/test_compilation/datadir.sb +++ /dev/null @@ -1,7 +0,0 @@ -{ -"bookoptions" : [ - "pictures" - ], -"datadir": ["datadir_datadir", "datadir_datadir2"], -"lang": "en" -} diff --git a/test/test_compilation/languages.sb b/test/test_compilation/languages.sb deleted file mode 100644 index e0c55f92..00000000 --- a/test/test_compilation/languages.sb +++ /dev/null @@ -1,3 +0,0 @@ -{ -"datadir": ["languages_datadir"] -} diff --git a/test/test_compilation/syntax.sb b/test/test_compilation/syntax.sb deleted file mode 100644 index fb16ce10..00000000 --- a/test/test_compilation/syntax.sb +++ /dev/null @@ -1,4 +0,0 @@ -{ -"datadir": ["syntax_datadir"], -"lang": "en" -} diff --git a/test/test_compilation/unicode.sb b/test/test_compilation/unicode.sb deleted file mode 100644 index fffed7cc..00000000 --- a/test/test_compilation/unicode.sb +++ /dev/null @@ -1,4 +0,0 @@ -{ -"datadir": ["unicode_datadir"], -"lang": "en" -} diff --git a/test/test_chordpro/__init__.py b/test/test_content/__init__.py similarity index 100% rename from test/test_chordpro/__init__.py rename to test/test_content/__init__.py diff --git a/test/test_content/cwd.control b/test/test_content/cwd.control new file mode 100644 index 00000000..c0a741d2 --- /dev/null +++ b/test/test_content/cwd.control @@ -0,0 +1 @@ +["subdir/chordpro.csg"] \ No newline at end of file diff --git a/test/test_content/cwd.source b/test/test_content/cwd.source new file mode 100644 index 00000000..4dfc53e6 --- /dev/null +++ b/test/test_content/cwd.source @@ -0,0 +1 @@ +[["cwd(subdir)"]] \ No newline at end of file diff --git a/test/test_content/cwd_list.control b/test/test_content/cwd_list.control new file mode 100644 index 00000000..465f29df --- /dev/null +++ b/test/test_content/cwd_list.control @@ -0,0 +1 @@ +["subdir/chordpro.csg", "exsong.sg"] \ No newline at end of file diff --git a/test/test_content/cwd_list.source b/test/test_content/cwd_list.source new file mode 100644 index 00000000..c5700449 --- /dev/null +++ b/test/test_content/cwd_list.source @@ -0,0 +1 @@ +[["cwd(subdir)", "exsong.sg", "intersong.is", "jsonlist.json", "texfile.tex", "texsong.tsg", "chordpro.csg", "subdir/chordpro.csg"], "exsong.sg"] \ No newline at end of file diff --git a/test/test_content/datadir/songs/chordpro.csg b/test/test_content/datadir/songs/chordpro.csg new file mode 100644 index 00000000..c1295968 --- /dev/null +++ b/test/test_content/datadir/songs/chordpro.csg @@ -0,0 +1,51 @@ +{lang : en} +{columns : 2} +{ title : Greensleeves} +{subtitle: Test of the chordpro format} +{artist: Traditionnel} +{artist: Prénom Nom} +{cover : traditionnel.jpg } +{album :Angleterre} + +{partition : greensleeves.ly} + + +A[Am]las, my love, ye [G]do me wrong +To [Am]cast me oft dis[E]curteously +And [Am]I have loved [G]you so long +De[Am]lighting [E]in your [Am]companie + +{start_of_chorus} + [C]Greensleeves was [G]all my joy + [Am]Greensleeves was [E]my delight + [C]Greensleeves was my [G]heart of gold + And [Am]who but [E]Ladie [Am]Greensleeves +{end_of_chorus} + +I [Am]have been ready [G]at your hand +To [Am]grant what ever [E]you would crave +I [Am]have both waged [G]life and land +Your [Am]love and [E]good will [Am]for to have + +I [Am]bought thee kerchers [G]to thy head +That [Am]were wrought fine and [E]gallantly +I [Am]kept thee both at [G]boord and bed +Which [Am]cost my [E]purse well [Am]favouredly + +I [Am]bought thee peticotes [G]of the best +The [Am]cloth so fine as [E]fine might be +I [Am]gave thee jewels [G]for thy chest +And [Am]all this [E]cost I [Am]spent on thee + +{c:test of comment} + +{gc: test of guitar comment} + +{image: traditionnel.jpg} + +Thy [Am]smock of silke, both [G]faire and white +With [Am]gold embrodered [E]gorgeously +Thy [Am]peticote of [G]sendall right +And [Am]this I [E]bought thee [Am]gladly + + diff --git a/test/test_content/datadir/songs/custom_list.json b/test/test_content/datadir/songs/custom_list.json new file mode 100644 index 00000000..5ba82a4c --- /dev/null +++ b/test/test_content/datadir/songs/custom_list.json @@ -0,0 +1 @@ +["exsong.sg", "chordpro.csg", "subdir/chordpro.csg"] \ No newline at end of file diff --git a/test/test_compilation/datadir_datadir/songs/datadir2.sg b/test/test_content/datadir/songs/exsong.sg similarity index 100% rename from test/test_compilation/datadir_datadir/songs/datadir2.sg rename to test/test_content/datadir/songs/exsong.sg diff --git a/test/test_content/datadir/songs/intersong.is b/test/test_content/datadir/songs/intersong.is new file mode 100644 index 00000000..dbeeb547 --- /dev/null +++ b/test/test_content/datadir/songs/intersong.is @@ -0,0 +1,6 @@ +\selectlanguage{french} +\sortassong{}[by={QQ}] +\begin{intersong} + +Lorem ipsum +\end{intersong} diff --git a/test/test_chordpro/00.csg.source b/test/test_content/datadir/songs/jsonlist.json similarity index 100% rename from test/test_chordpro/00.csg.source rename to test/test_content/datadir/songs/jsonlist.json diff --git a/test/test_content/datadir/songs/subdir/chordpro.csg b/test/test_content/datadir/songs/subdir/chordpro.csg new file mode 100644 index 00000000..c1295968 --- /dev/null +++ b/test/test_content/datadir/songs/subdir/chordpro.csg @@ -0,0 +1,51 @@ +{lang : en} +{columns : 2} +{ title : Greensleeves} +{subtitle: Test of the chordpro format} +{artist: Traditionnel} +{artist: Prénom Nom} +{cover : traditionnel.jpg } +{album :Angleterre} + +{partition : greensleeves.ly} + + +A[Am]las, my love, ye [G]do me wrong +To [Am]cast me oft dis[E]curteously +And [Am]I have loved [G]you so long +De[Am]lighting [E]in your [Am]companie + +{start_of_chorus} + [C]Greensleeves was [G]all my joy + [Am]Greensleeves was [E]my delight + [C]Greensleeves was my [G]heart of gold + And [Am]who but [E]Ladie [Am]Greensleeves +{end_of_chorus} + +I [Am]have been ready [G]at your hand +To [Am]grant what ever [E]you would crave +I [Am]have both waged [G]life and land +Your [Am]love and [E]good will [Am]for to have + +I [Am]bought thee kerchers [G]to thy head +That [Am]were wrought fine and [E]gallantly +I [Am]kept thee both at [G]boord and bed +Which [Am]cost my [E]purse well [Am]favouredly + +I [Am]bought thee peticotes [G]of the best +The [Am]cloth so fine as [E]fine might be +I [Am]gave thee jewels [G]for thy chest +And [Am]all this [E]cost I [Am]spent on thee + +{c:test of comment} + +{gc: test of guitar comment} + +{image: traditionnel.jpg} + +Thy [Am]smock of silke, both [G]faire and white +With [Am]gold embrodered [E]gorgeously +Thy [Am]peticote of [G]sendall right +And [Am]this I [E]bought thee [Am]gladly + + diff --git a/test/test_content/datadir/songs/texfile.tex b/test/test_content/datadir/songs/texfile.tex new file mode 100644 index 00000000..81a725ef --- /dev/null +++ b/test/test_content/datadir/songs/texfile.tex @@ -0,0 +1,70 @@ +\selectlanguage{french} +\songcolumns{2} +\beginsong{Chevaliers de la table ronde} + [by={Traditionnel},cover={traditionnel},album={France}] + + \cover + \gtab{C}{X32010} + \gtab{G7}{320001} + \gtab{F}{1:022100} + + \begin{verse} + Cheva\[C]liers de la Table Ronde + Goûtons \[G7]voir si le vin est \[C]bon + \rep{2} + \end{verse} + + \begin{chorus} + Goûtons \[F]voir, \echo{oui, oui, oui} + Goûtons \[C]voir, \echo{non, non, non} + Goûtons \[G7]voir si le vin est bon + \rep{2} + \end{chorus} + + \begin{verse} + S'il est bon, s'il est agréable + J'en boirai jusqu'à mon plaisir + \end{verse} + + \begin{verse} + J'en boirai cinq à six bouteilles + Et encore, ce n'est pas beaucoup + \end{verse} + + \begin{verse} + Si je meurs, je veux qu'on m'enterre + Dans une cave où il y a du bon vin + \end{verse} + + \begin{verse} + Les deux pieds contre la muraille + Et la tête sous le robinet + \end{verse} + + \begin{verse} + Et les quatre plus grands ivrognes + Porteront les quatre coins du drap + \end{verse} + + \begin{verse} + Pour donner le discours d'usage + On prendra le bistrot du coin + \end{verse} + + \begin{verse} + Et si le tonneau se débouche + J'en boirai jusqu'à mon plaisir + \end{verse} + + \begin{verse} + Et s'il en reste quelques gouttes + Ce sera pour nous rafraîchir + \end{verse} + + \begin{verse} + Sur ma tombe, je veux qu'on inscrive + \emph{Ici gît le roi des buveurs} + \end{verse} + +\endsong + diff --git a/test/test_content/datadir/songs/texsong.tsg b/test/test_content/datadir/songs/texsong.tsg new file mode 100644 index 00000000..81a725ef --- /dev/null +++ b/test/test_content/datadir/songs/texsong.tsg @@ -0,0 +1,70 @@ +\selectlanguage{french} +\songcolumns{2} +\beginsong{Chevaliers de la table ronde} + [by={Traditionnel},cover={traditionnel},album={France}] + + \cover + \gtab{C}{X32010} + \gtab{G7}{320001} + \gtab{F}{1:022100} + + \begin{verse} + Cheva\[C]liers de la Table Ronde + Goûtons \[G7]voir si le vin est \[C]bon + \rep{2} + \end{verse} + + \begin{chorus} + Goûtons \[F]voir, \echo{oui, oui, oui} + Goûtons \[C]voir, \echo{non, non, non} + Goûtons \[G7]voir si le vin est bon + \rep{2} + \end{chorus} + + \begin{verse} + S'il est bon, s'il est agréable + J'en boirai jusqu'à mon plaisir + \end{verse} + + \begin{verse} + J'en boirai cinq à six bouteilles + Et encore, ce n'est pas beaucoup + \end{verse} + + \begin{verse} + Si je meurs, je veux qu'on m'enterre + Dans une cave où il y a du bon vin + \end{verse} + + \begin{verse} + Les deux pieds contre la muraille + Et la tête sous le robinet + \end{verse} + + \begin{verse} + Et les quatre plus grands ivrognes + Porteront les quatre coins du drap + \end{verse} + + \begin{verse} + Pour donner le discours d'usage + On prendra le bistrot du coin + \end{verse} + + \begin{verse} + Et si le tonneau se débouche + J'en boirai jusqu'à mon plaisir + \end{verse} + + \begin{verse} + Et s'il en reste quelques gouttes + Ce sera pour nous rafraîchir + \end{verse} + + \begin{verse} + Sur ma tombe, je veux qu'on inscrive + \emph{Ici gît le roi des buveurs} + \end{verse} + +\endsong + diff --git a/test/test_content/glob.control b/test/test_content/glob.control new file mode 100644 index 00000000..a30583cc --- /dev/null +++ b/test/test_content/glob.control @@ -0,0 +1 @@ +["chordpro.csg"] \ No newline at end of file diff --git a/test/test_content/glob.source b/test/test_content/glob.source new file mode 100644 index 00000000..167ab6ab --- /dev/null +++ b/test/test_content/glob.source @@ -0,0 +1 @@ +["*.csg"] \ No newline at end of file diff --git a/test/test_content/include.control b/test/test_content/include.control new file mode 100644 index 00000000..5ba82a4c --- /dev/null +++ b/test/test_content/include.control @@ -0,0 +1 @@ +["exsong.sg", "chordpro.csg", "subdir/chordpro.csg"] \ No newline at end of file diff --git a/test/test_content/include.source b/test/test_content/include.source new file mode 100644 index 00000000..ccd69aa1 --- /dev/null +++ b/test/test_content/include.source @@ -0,0 +1 @@ +[["include" , "custom_list.json"]] \ No newline at end of file diff --git a/test/test_content/sections.control b/test/test_content/sections.control new file mode 100644 index 00000000..3666bbce --- /dev/null +++ b/test/test_content/sections.control @@ -0,0 +1 @@ +["section:Traditional", "exsong.sg", "section:Example", "texsong.tsg", "chordpro.csg", "exsong.sg"] \ No newline at end of file diff --git a/test/test_content/sections.source b/test/test_content/sections.source new file mode 100644 index 00000000..339815be --- /dev/null +++ b/test/test_content/sections.source @@ -0,0 +1,6 @@ +[["section", "Traditional"], + "exsong.sg", + ["section", "Example"], + "texsong.tsg", + "chordpro.csg", + "exsong.sg"] \ No newline at end of file diff --git a/test/test_content/sections_short.control b/test/test_content/sections_short.control new file mode 100644 index 00000000..706e86b8 --- /dev/null +++ b/test/test_content/sections_short.control @@ -0,0 +1 @@ +["section:(tradi)Traditional", "exsong.sg", "section*:Example", "texsong.tsg", "chordpro.csg", "exsong.sg"] \ No newline at end of file diff --git a/test/test_content/sections_short.source b/test/test_content/sections_short.source new file mode 100644 index 00000000..fe70d510 --- /dev/null +++ b/test/test_content/sections_short.source @@ -0,0 +1,6 @@ +[["section", "Traditional", "tradi"], + "exsong.sg", + ["section*", "Example"], + "texsong.tsg", + "chordpro.csg", + "exsong.sg"] \ No newline at end of file diff --git a/test/test_content/songs.control b/test/test_content/songs.control new file mode 100644 index 00000000..e85dfea7 --- /dev/null +++ b/test/test_content/songs.control @@ -0,0 +1 @@ +["exsong.sg", "texsong.tsg", "chordpro.csg", "subdir/chordpro.csg"] \ No newline at end of file diff --git a/test/test_content/songs.source b/test/test_content/songs.source new file mode 100644 index 00000000..dcd19323 --- /dev/null +++ b/test/test_content/songs.source @@ -0,0 +1 @@ +["exsong.sg", "intersong.is", "jsonlist.json", "texfile.tex", "texsong.tsg", "chordpro.csg", "subdir/chordpro.csg"] \ No newline at end of file diff --git a/test/test_content/songsection.control b/test/test_content/songsection.control new file mode 100644 index 00000000..69dd034b --- /dev/null +++ b/test/test_content/songsection.control @@ -0,0 +1 @@ +["songsection:Traditional", "exsong.sg", "songchapter:English", "texsong.tsg", "chordpro.csg", "exsong.sg"] \ No newline at end of file diff --git a/test/test_content/songsection.source b/test/test_content/songsection.source new file mode 100644 index 00000000..089322c4 --- /dev/null +++ b/test/test_content/songsection.source @@ -0,0 +1,6 @@ +[["songsection", "Traditional"], + "exsong.sg", + ["songchapter", "English"], + "texsong.tsg", + "chordpro.csg", + "exsong.sg"] \ No newline at end of file diff --git a/test/test_content/sorted.control b/test/test_content/sorted.control new file mode 100644 index 00000000..5cfaa29d --- /dev/null +++ b/test/test_content/sorted.control @@ -0,0 +1 @@ +["chordpro.csg", "exsong.sg", "subdir/chordpro.csg", "texsong.tsg"] \ No newline at end of file diff --git a/test/test_content/sorted.source b/test/test_content/sorted.source new file mode 100644 index 00000000..5b2bbf3a --- /dev/null +++ b/test/test_content/sorted.source @@ -0,0 +1 @@ +[["sorted(fullpath)"]] \ No newline at end of file diff --git a/test/test_content/test_content.py b/test/test_content/test_content.py new file mode 100644 index 00000000..5857506c --- /dev/null +++ b/test/test_content/test_content.py @@ -0,0 +1,118 @@ +"""Tests for the content plugins.""" + +# pylint: disable=too-few-public-methods + +import glob +import os +import unittest +import json + +from patacrep.songs import DataSubpath, DEFAULT_CONFIG +from patacrep import content, files +from patacrep.content import song, section, songsection, tex + +from .. import logging_reduced +from .. import dynamic # pylint: disable=unused-import + +class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest): + """Test of the content plugins. + + For any given `foo.source`, it parses the content as a json "content" + argument of a .sb file. + It controls that the generated file list is equal to the one in `foo.control`. + """ + + maxDiff = None + config = None + + @classmethod + def setUpClass(cls): + cls._generate_config() + + @classmethod + def _iter_testmethods(cls): + """Iterate over dynamically generated test methods""" + for source in sorted(glob.glob(os.path.join( + os.path.dirname(__file__), + '*.source', + ))): + base = source[:-len(".source")] + yield ( + "test_content_{}".format(os.path.basename(base)), + cls._create_content_test(base), + ) + + @classmethod + def _create_content_test(cls, base): + """Return a function that `base.source` produces the correct file list""" + + def test_content(self): + """Test that `base.source` produces the correct file list""" + sourcename = "{}.source".format(base) + with open(sourcename, mode="r", encoding="utf8") as sourcefile: + sbcontent = json.load(sourcefile) + + with logging_reduced('patacrep.content.song'): + expandedlist = content.process_content(sbcontent, cls.config.copy()) + sourcelist = [cls._clean_path(elem) for elem in expandedlist] + + controlname = "{}.control".format(base) + if not os.path.exists(controlname): + raise Exception("Missing control:" + str(sourcelist).replace("'", '"')) + with open(controlname, mode="r", encoding="utf8") as controlfile: + controllist = json.load(controlfile) + + self.assertEqual(controllist, sourcelist) + + test_content.__doc__ = ( + "Test that '{base}.source' produces the correct file list""" + ).format(base=os.path.basename(base)) + return test_content + + @classmethod + def _clean_path(cls, elem): + """Shorten the path relative to the `songs` directory""" + if isinstance(elem, song.SongRenderer): + songpath = os.path.join(os.path.dirname(__file__), 'datadir', 'songs') + return files.path2posix(files.relpath(elem.song.fullpath, songpath)) + + elif isinstance(elem, section.Section): + if elem.short is None: + return "{}:{}".format(elem.keyword, elem.name) + else: + return "{}:({}){}".format(elem.keyword, elem.short, elem.name) + + elif isinstance(elem, songsection.SongSection): + return "{}:{}".format(elem.keyword, elem.name) + + elif isinstance(elem, tex.LaTeX): + return files.path2posix(elem.filename) + + else: + raise Exception(elem) + + @classmethod + def _generate_config(cls): + """Generate the config to process the content""" + + config = DEFAULT_CONFIG.copy() + + datadirpaths = [os.path.join(os.path.dirname(__file__), 'datadir')] + + config['datadir'] = datadirpaths + + config['_songdir'] = [ + DataSubpath(path, 'songs') + for path in datadirpaths + ] + config['_content_plugins'] = files.load_plugins( + datadirs=datadirpaths, + root_modules=['content'], + keyword='CONTENT_PLUGINS', + ) + config['_song_plugins'] = files.load_plugins( + datadirs=datadirpaths, + root_modules=['songs'], + keyword='SONG_RENDERERS', + )['tsg'] + cls.config = config diff --git a/test/test_content/tex.control b/test/test_content/tex.control new file mode 100644 index 00000000..85eeb47e --- /dev/null +++ b/test/test_content/tex.control @@ -0,0 +1 @@ +["test/test_content/datadir/songs/texfile.tex"] \ No newline at end of file diff --git a/test/test_content/tex.source b/test/test_content/tex.source new file mode 100644 index 00000000..56852196 --- /dev/null +++ b/test/test_content/tex.source @@ -0,0 +1 @@ +[["tex", "texfile.tex", "chordpro.csg"]] \ No newline at end of file diff --git a/test/test_chordpro/00.csg b/test/test_song/00.csg similarity index 100% rename from test/test_chordpro/00.csg rename to test/test_song/00.csg diff --git a/test/test_chordpro/datadir/img/traditionnel.png b/test/test_song/00.csg.source similarity index 100% rename from test/test_chordpro/datadir/img/traditionnel.png rename to test/test_song/00.csg.source diff --git a/test/test_chordpro/00.tsg b/test/test_song/00.tsg similarity index 100% rename from test/test_chordpro/00.tsg rename to test/test_song/00.tsg diff --git a/test/test_chordpro/01.csg b/test/test_song/01.csg similarity index 100% rename from test/test_chordpro/01.csg rename to test/test_song/01.csg diff --git a/test/test_chordpro/01.csg.source b/test/test_song/01.csg.source similarity index 100% rename from test/test_chordpro/01.csg.source rename to test/test_song/01.csg.source diff --git a/test/test_chordpro/01.tsg b/test/test_song/01.tsg similarity index 100% rename from test/test_chordpro/01.tsg rename to test/test_song/01.tsg diff --git a/test/test_chordpro/02.csg b/test/test_song/02.csg similarity index 100% rename from test/test_chordpro/02.csg rename to test/test_song/02.csg diff --git a/test/test_chordpro/02.csg.source b/test/test_song/02.csg.source similarity index 100% rename from test/test_chordpro/02.csg.source rename to test/test_song/02.csg.source diff --git a/test/test_chordpro/02.tsg b/test/test_song/02.tsg similarity index 100% rename from test/test_chordpro/02.tsg rename to test/test_song/02.tsg diff --git a/test/test_chordpro/03.csg b/test/test_song/03.csg similarity index 100% rename from test/test_chordpro/03.csg rename to test/test_song/03.csg diff --git a/test/test_chordpro/03.csg.source b/test/test_song/03.csg.source similarity index 100% rename from test/test_chordpro/03.csg.source rename to test/test_song/03.csg.source diff --git a/test/test_chordpro/03.tsg b/test/test_song/03.tsg similarity index 100% rename from test/test_chordpro/03.tsg rename to test/test_song/03.tsg diff --git a/test/test_chordpro/04.csg b/test/test_song/04.csg similarity index 100% rename from test/test_chordpro/04.csg rename to test/test_song/04.csg diff --git a/test/test_chordpro/04.csg.source b/test/test_song/04.csg.source similarity index 100% rename from test/test_chordpro/04.csg.source rename to test/test_song/04.csg.source diff --git a/test/test_chordpro/04.tsg b/test/test_song/04.tsg similarity index 100% rename from test/test_chordpro/04.tsg rename to test/test_song/04.tsg diff --git a/test/test_chordpro/05.csg b/test/test_song/05.csg similarity index 100% rename from test/test_chordpro/05.csg rename to test/test_song/05.csg diff --git a/test/test_chordpro/05.csg.source b/test/test_song/05.csg.source similarity index 100% rename from test/test_chordpro/05.csg.source rename to test/test_song/05.csg.source diff --git a/test/test_chordpro/05.tsg b/test/test_song/05.tsg similarity index 100% rename from test/test_chordpro/05.tsg rename to test/test_song/05.tsg diff --git a/test/test_chordpro/06.csg b/test/test_song/06.csg similarity index 100% rename from test/test_chordpro/06.csg rename to test/test_song/06.csg diff --git a/test/test_chordpro/06.csg.source b/test/test_song/06.csg.source similarity index 100% rename from test/test_chordpro/06.csg.source rename to test/test_song/06.csg.source diff --git a/test/test_chordpro/06.tsg b/test/test_song/06.tsg similarity index 100% rename from test/test_chordpro/06.tsg rename to test/test_song/06.tsg diff --git a/test/test_chordpro/07.csg b/test/test_song/07.csg similarity index 100% rename from test/test_chordpro/07.csg rename to test/test_song/07.csg diff --git a/test/test_chordpro/07.csg.source b/test/test_song/07.csg.source similarity index 100% rename from test/test_chordpro/07.csg.source rename to test/test_song/07.csg.source diff --git a/test/test_chordpro/07.tsg b/test/test_song/07.tsg similarity index 100% rename from test/test_chordpro/07.tsg rename to test/test_song/07.tsg diff --git a/test/test_chordpro/08.csg b/test/test_song/08.csg similarity index 100% rename from test/test_chordpro/08.csg rename to test/test_song/08.csg diff --git a/test/test_chordpro/08.csg.source b/test/test_song/08.csg.source similarity index 100% rename from test/test_chordpro/08.csg.source rename to test/test_song/08.csg.source diff --git a/test/test_chordpro/08.tsg b/test/test_song/08.tsg similarity index 100% rename from test/test_chordpro/08.tsg rename to test/test_song/08.tsg diff --git a/test/test_chordpro/09.csg b/test/test_song/09.csg similarity index 100% rename from test/test_chordpro/09.csg rename to test/test_song/09.csg diff --git a/test/test_chordpro/09.csg.source b/test/test_song/09.csg.source similarity index 100% rename from test/test_chordpro/09.csg.source rename to test/test_song/09.csg.source diff --git a/test/test_chordpro/09.tsg b/test/test_song/09.tsg similarity index 100% rename from test/test_chordpro/09.tsg rename to test/test_song/09.tsg diff --git a/test/test_chordpro/10.csg b/test/test_song/10.csg similarity index 100% rename from test/test_chordpro/10.csg rename to test/test_song/10.csg diff --git a/test/test_chordpro/10.csg.source b/test/test_song/10.csg.source similarity index 100% rename from test/test_chordpro/10.csg.source rename to test/test_song/10.csg.source diff --git a/test/test_chordpro/10.tsg b/test/test_song/10.tsg similarity index 100% rename from test/test_chordpro/10.tsg rename to test/test_song/10.tsg diff --git a/test/test_chordpro/11.csg b/test/test_song/11.csg similarity index 100% rename from test/test_chordpro/11.csg rename to test/test_song/11.csg diff --git a/test/test_chordpro/11.csg.source b/test/test_song/11.csg.source similarity index 100% rename from test/test_chordpro/11.csg.source rename to test/test_song/11.csg.source diff --git a/test/test_chordpro/11.tsg b/test/test_song/11.tsg similarity index 100% rename from test/test_chordpro/11.tsg rename to test/test_song/11.tsg diff --git a/test/test_chordpro/12.csg b/test/test_song/12.csg similarity index 100% rename from test/test_chordpro/12.csg rename to test/test_song/12.csg diff --git a/test/test_chordpro/12.csg.source b/test/test_song/12.csg.source similarity index 100% rename from test/test_chordpro/12.csg.source rename to test/test_song/12.csg.source diff --git a/test/test_chordpro/12.tsg b/test/test_song/12.tsg similarity index 100% rename from test/test_chordpro/12.tsg rename to test/test_song/12.tsg diff --git a/test/test_chordpro/13.csg b/test/test_song/13.csg similarity index 100% rename from test/test_chordpro/13.csg rename to test/test_song/13.csg diff --git a/test/test_chordpro/13.csg.source b/test/test_song/13.csg.source similarity index 100% rename from test/test_chordpro/13.csg.source rename to test/test_song/13.csg.source diff --git a/test/test_chordpro/13.tsg b/test/test_song/13.tsg similarity index 100% rename from test/test_chordpro/13.tsg rename to test/test_song/13.tsg diff --git a/test/test_chordpro/21.csg b/test/test_song/21.csg similarity index 100% rename from test/test_chordpro/21.csg rename to test/test_song/21.csg diff --git a/test/test_chordpro/21.csg.source b/test/test_song/21.csg.source similarity index 100% rename from test/test_chordpro/21.csg.source rename to test/test_song/21.csg.source diff --git a/test/test_chordpro/21.tsg b/test/test_song/21.tsg similarity index 100% rename from test/test_chordpro/21.tsg rename to test/test_song/21.tsg diff --git a/test/test_chordpro/22.csg b/test/test_song/22.csg similarity index 100% rename from test/test_chordpro/22.csg rename to test/test_song/22.csg diff --git a/test/test_chordpro/22.csg.source b/test/test_song/22.csg.source similarity index 100% rename from test/test_chordpro/22.csg.source rename to test/test_song/22.csg.source diff --git a/test/test_chordpro/22.tsg b/test/test_song/22.tsg similarity index 100% rename from test/test_chordpro/22.tsg rename to test/test_song/22.tsg diff --git a/test/test_chordpro/23.csg b/test/test_song/23.csg similarity index 100% rename from test/test_chordpro/23.csg rename to test/test_song/23.csg diff --git a/test/test_chordpro/23.csg.source b/test/test_song/23.csg.source similarity index 100% rename from test/test_chordpro/23.csg.source rename to test/test_song/23.csg.source diff --git a/test/test_chordpro/23.tsg b/test/test_song/23.tsg similarity index 100% rename from test/test_chordpro/23.tsg rename to test/test_song/23.tsg diff --git a/test/test_chordpro/24.csg b/test/test_song/24.csg similarity index 100% rename from test/test_chordpro/24.csg rename to test/test_song/24.csg diff --git a/test/test_chordpro/24.csg.source b/test/test_song/24.csg.source similarity index 100% rename from test/test_chordpro/24.csg.source rename to test/test_song/24.csg.source diff --git a/test/test_chordpro/24.tsg b/test/test_song/24.tsg similarity index 100% rename from test/test_chordpro/24.tsg rename to test/test_song/24.tsg diff --git a/test/test_chordpro/25.csg b/test/test_song/25.csg similarity index 100% rename from test/test_chordpro/25.csg rename to test/test_song/25.csg diff --git a/test/test_chordpro/25.csg.source b/test/test_song/25.csg.source similarity index 100% rename from test/test_chordpro/25.csg.source rename to test/test_song/25.csg.source diff --git a/test/test_chordpro/25.tsg b/test/test_song/25.tsg similarity index 100% rename from test/test_chordpro/25.tsg rename to test/test_song/25.tsg diff --git a/test/test_chordpro/26.csg b/test/test_song/26.csg similarity index 100% rename from test/test_chordpro/26.csg rename to test/test_song/26.csg diff --git a/test/test_chordpro/26.csg.source b/test/test_song/26.csg.source similarity index 100% rename from test/test_chordpro/26.csg.source rename to test/test_song/26.csg.source diff --git a/test/test_chordpro/26.tsg b/test/test_song/26.tsg similarity index 100% rename from test/test_chordpro/26.tsg rename to test/test_song/26.tsg diff --git a/test/test_chordpro/27.csg b/test/test_song/27.csg similarity index 100% rename from test/test_chordpro/27.csg rename to test/test_song/27.csg diff --git a/test/test_chordpro/27.csg.source b/test/test_song/27.csg.source similarity index 100% rename from test/test_chordpro/27.csg.source rename to test/test_song/27.csg.source diff --git a/test/test_chordpro/27.tsg b/test/test_song/27.tsg similarity index 100% rename from test/test_chordpro/27.tsg rename to test/test_song/27.tsg diff --git a/test/test_chordpro/28.csg b/test/test_song/28.csg similarity index 100% rename from test/test_chordpro/28.csg rename to test/test_song/28.csg diff --git a/test/test_chordpro/28.csg.source b/test/test_song/28.csg.source similarity index 100% rename from test/test_chordpro/28.csg.source rename to test/test_song/28.csg.source diff --git a/test/test_chordpro/28.tsg b/test/test_song/28.tsg similarity index 100% rename from test/test_chordpro/28.tsg rename to test/test_song/28.tsg diff --git a/test/test_chordpro/29.csg b/test/test_song/29.csg similarity index 100% rename from test/test_chordpro/29.csg rename to test/test_song/29.csg diff --git a/test/test_chordpro/29.csg.source b/test/test_song/29.csg.source similarity index 100% rename from test/test_chordpro/29.csg.source rename to test/test_song/29.csg.source diff --git a/test/test_chordpro/29.tsg b/test/test_song/29.tsg similarity index 100% rename from test/test_chordpro/29.tsg rename to test/test_song/29.tsg diff --git a/test/test_compilation/__init__.py b/test/test_song/__init__.py similarity index 100% rename from test/test_compilation/__init__.py rename to test/test_song/__init__.py diff --git a/test/test_chordpro/author_names.csg b/test/test_song/author_names.csg similarity index 100% rename from test/test_chordpro/author_names.csg rename to test/test_song/author_names.csg diff --git a/test/test_chordpro/author_names.csg.source b/test/test_song/author_names.csg.source similarity index 100% rename from test/test_chordpro/author_names.csg.source rename to test/test_song/author_names.csg.source diff --git a/test/test_chordpro/author_names.tsg b/test/test_song/author_names.tsg similarity index 100% rename from test/test_chordpro/author_names.tsg rename to test/test_song/author_names.tsg diff --git a/test/test_chordpro/chords.csg b/test/test_song/chords.csg similarity index 100% rename from test/test_chordpro/chords.csg rename to test/test_song/chords.csg diff --git a/test/test_chordpro/chords.csg.source b/test/test_song/chords.csg.source similarity index 100% rename from test/test_chordpro/chords.csg.source rename to test/test_song/chords.csg.source diff --git a/test/test_chordpro/chords.tsg b/test/test_song/chords.tsg similarity index 100% rename from test/test_chordpro/chords.tsg rename to test/test_song/chords.tsg diff --git a/test/test_chordpro/customchords.csg b/test/test_song/customchords.csg similarity index 100% rename from test/test_chordpro/customchords.csg rename to test/test_song/customchords.csg diff --git a/test/test_chordpro/customchords.csg.source b/test/test_song/customchords.csg.source similarity index 100% rename from test/test_chordpro/customchords.csg.source rename to test/test_song/customchords.csg.source diff --git a/test/test_chordpro/customchords.tsg b/test/test_song/customchords.tsg similarity index 100% rename from test/test_chordpro/customchords.tsg rename to test/test_song/customchords.tsg diff --git a/test/test_chordpro/datadir/scores/greensleeves.ly b/test/test_song/datadir/img/traditionnel.png similarity index 100% rename from test/test_chordpro/datadir/scores/greensleeves.ly rename to test/test_song/datadir/img/traditionnel.png diff --git a/test/test_chordpro/metadata_cover.png b/test/test_song/datadir/scores/greensleeves.ly similarity index 100% rename from test/test_chordpro/metadata_cover.png rename to test/test_song/datadir/scores/greensleeves.ly diff --git a/test/test_chordpro/greensleeves.csg b/test/test_song/greensleeves.csg similarity index 100% rename from test/test_chordpro/greensleeves.csg rename to test/test_song/greensleeves.csg diff --git a/test/test_chordpro/greensleeves.csg.source b/test/test_song/greensleeves.csg.source similarity index 100% rename from test/test_chordpro/greensleeves.csg.source rename to test/test_song/greensleeves.csg.source diff --git a/test/test_chordpro/greensleeves.tsg b/test/test_song/greensleeves.tsg similarity index 100% rename from test/test_chordpro/greensleeves.tsg rename to test/test_song/greensleeves.tsg diff --git a/test/test_song/greensleeves_latex.crlf.tsg b/test/test_song/greensleeves_latex.crlf.tsg new file mode 100644 index 00000000..5c2c33e3 --- /dev/null +++ b/test/test_song/greensleeves_latex.crlf.tsg @@ -0,0 +1 @@ +\import{@TEST_FOLDER@/}{greensleeves_latex.crlf.tsg.source} \ No newline at end of file diff --git a/test/test_song/greensleeves_latex.crlf.tsg.source b/test/test_song/greensleeves_latex.crlf.tsg.source new file mode 100644 index 00000000..ff805290 --- /dev/null +++ b/test/test_song/greensleeves_latex.crlf.tsg.source @@ -0,0 +1,2 @@ +# This content will be overwritten with `greensleeves_latex.tsg.source` content +# with windows line endings (CRLF) - for testing purposes diff --git a/test/test_song/greensleeves_latex.tsg b/test/test_song/greensleeves_latex.tsg new file mode 100644 index 00000000..0edd8826 --- /dev/null +++ b/test/test_song/greensleeves_latex.tsg @@ -0,0 +1 @@ +\import{@TEST_FOLDER@/}{greensleeves_latex.tsg.source} \ No newline at end of file diff --git a/test/test_song/greensleeves_latex.tsg.source b/test/test_song/greensleeves_latex.tsg.source new file mode 100644 index 00000000..c4bc461d --- /dev/null +++ b/test/test_song/greensleeves_latex.tsg.source @@ -0,0 +1,68 @@ +\selectlanguage{english} +\songcolumns{2} + +\beginsong{Greensleeves\\ +Un autre sous-titre\\ +Un sous titre}[ + by={ + Traditionnel }, + album={Angleterre}, + cover={img/traditionnel}, +] + +\cover + + + +\lilypond{scores/greensleeves.ly} + + + +\begin{verse} + A\[Am]las, my love, ye \[G]do me wrong + To \[Am]cast me oft dis\[E]curteously + And \[Am]I have loved \[G]you so long + De\[Am]lighting \[E]in your \[Am]companie +\end{verse} + + +\begin{chorus} + \[C]Green\[B]sleeves was \[G]all my joy + \[Am]Greensleeves was \[E]my delight + \[C]Greensleeves was my \[G]heart of gold + And \[Am]who but \[E]Ladie \[Am]Greensleeves +\end{chorus} + + +\begin{verse} + I \[Am]have been ready \[G]at your hand + To \[Am]grant what ever \[E]you would crave + I \[Am]have both waged \[G]life and land + Your \[Am]love and \[E]good will \[Am]for to have +\end{verse} + + +\begin{verse} + I \[Am]bought thee kerchers \[G]to thy head + That \[Am]were wrought fine and \[E]gallantly + I \[Am]kept thee both at \[G]boord and bed + Which \[Am]cost my \[E]purse well \[Am]favouredly +\end{verse} + + +\begin{verse} + I \[Am]bought thee peticotes \[G]of the best + The \[Am]cloth so fine as \[E]fine might be + I \[Am]gave thee jewels \[G]for thy chest + And \[Am]all this \[E]cost I \[Am]spent on thee +\end{verse} + + +\begin{verse} + Thy \[Am]smock of silke, both \[G]faire and white + With \[Am]gold embrodered \[E]gorgeously + Thy \[Am]peticote of \[G]sendall right + And \[Am]this I \[E]bought thee \[Am]gladly +\end{verse} + +\endsong diff --git a/test/test_chordpro/invalid_chord.csg b/test/test_song/invalid_chord.csg similarity index 100% rename from test/test_chordpro/invalid_chord.csg rename to test/test_song/invalid_chord.csg diff --git a/test/test_chordpro/invalid_chord.csg.source b/test/test_song/invalid_chord.csg.source similarity index 100% rename from test/test_chordpro/invalid_chord.csg.source rename to test/test_song/invalid_chord.csg.source diff --git a/test/test_chordpro/invalid_chord.tsg b/test/test_song/invalid_chord.tsg similarity index 100% rename from test/test_chordpro/invalid_chord.tsg rename to test/test_song/invalid_chord.tsg diff --git a/test/test_chordpro/invalid_customchord.csg b/test/test_song/invalid_customchord.csg similarity index 100% rename from test/test_chordpro/invalid_customchord.csg rename to test/test_song/invalid_customchord.csg diff --git a/test/test_chordpro/invalid_customchord.csg.source b/test/test_song/invalid_customchord.csg.source similarity index 100% rename from test/test_chordpro/invalid_customchord.csg.source rename to test/test_song/invalid_customchord.csg.source diff --git a/test/test_chordpro/invalid_customchord.tsg b/test/test_song/invalid_customchord.tsg similarity index 100% rename from test/test_chordpro/invalid_customchord.tsg rename to test/test_song/invalid_customchord.tsg diff --git a/test/test_chordpro/invalid_directive.csg b/test/test_song/invalid_directive.csg similarity index 100% rename from test/test_chordpro/invalid_directive.csg rename to test/test_song/invalid_directive.csg diff --git a/test/test_chordpro/invalid_directive.csg.source b/test/test_song/invalid_directive.csg.source similarity index 100% rename from test/test_chordpro/invalid_directive.csg.source rename to test/test_song/invalid_directive.csg.source diff --git a/test/test_chordpro/invalid_directive.tsg b/test/test_song/invalid_directive.tsg similarity index 100% rename from test/test_chordpro/invalid_directive.tsg rename to test/test_song/invalid_directive.tsg diff --git a/test/test_chordpro/lang.csg b/test/test_song/lang.csg similarity index 100% rename from test/test_chordpro/lang.csg rename to test/test_song/lang.csg diff --git a/test/test_chordpro/lang.csg.source b/test/test_song/lang.csg.source similarity index 100% rename from test/test_chordpro/lang.csg.source rename to test/test_song/lang.csg.source diff --git a/test/test_chordpro/metadata.csg b/test/test_song/metadata.csg similarity index 100% rename from test/test_chordpro/metadata.csg rename to test/test_song/metadata.csg diff --git a/test/test_chordpro/metadata.csg.source b/test/test_song/metadata.csg.source similarity index 100% rename from test/test_chordpro/metadata.csg.source rename to test/test_song/metadata.csg.source diff --git a/test/test_chordpro/metadata.tsg b/test/test_song/metadata.tsg similarity index 100% rename from test/test_chordpro/metadata.tsg rename to test/test_song/metadata.tsg diff --git a/test/test_chordpro/metadata_image.png b/test/test_song/metadata_cover.png similarity index 100% rename from test/test_chordpro/metadata_image.png rename to test/test_song/metadata_cover.png diff --git a/test/test_chordpro/metadata_lilypond.ly b/test/test_song/metadata_image.png similarity index 100% rename from test/test_chordpro/metadata_lilypond.ly rename to test/test_song/metadata_image.png diff --git a/test/test_song/metadata_lilypond.ly b/test/test_song/metadata_lilypond.ly new file mode 100644 index 00000000..e69de29b diff --git a/test/test_chordpro/newline.crlf.csg b/test/test_song/newline.crlf.csg similarity index 100% rename from test/test_chordpro/newline.crlf.csg rename to test/test_song/newline.crlf.csg diff --git a/test/test_chordpro/newline.crlf.csg.source b/test/test_song/newline.crlf.csg.source similarity index 100% rename from test/test_chordpro/newline.crlf.csg.source rename to test/test_song/newline.crlf.csg.source diff --git a/test/test_chordpro/newline.crlf.html b/test/test_song/newline.crlf.html similarity index 100% rename from test/test_chordpro/newline.crlf.html rename to test/test_song/newline.crlf.html diff --git a/test/test_chordpro/newline.crlf.tsg b/test/test_song/newline.crlf.tsg similarity index 100% rename from test/test_chordpro/newline.crlf.tsg rename to test/test_song/newline.crlf.tsg diff --git a/test/test_chordpro/newline.csg b/test/test_song/newline.csg similarity index 100% rename from test/test_chordpro/newline.csg rename to test/test_song/newline.csg diff --git a/test/test_chordpro/newline.csg.source b/test/test_song/newline.csg.source similarity index 100% rename from test/test_chordpro/newline.csg.source rename to test/test_song/newline.csg.source diff --git a/test/test_chordpro/newline.html b/test/test_song/newline.html similarity index 100% rename from test/test_chordpro/newline.html rename to test/test_song/newline.html diff --git a/test/test_chordpro/newline.tsg b/test/test_song/newline.tsg similarity index 100% rename from test/test_chordpro/newline.tsg rename to test/test_song/newline.tsg diff --git a/test/test_chordpro/nolyrics.csg b/test/test_song/nolyrics.csg similarity index 100% rename from test/test_chordpro/nolyrics.csg rename to test/test_song/nolyrics.csg diff --git a/test/test_chordpro/nolyrics.csg.source b/test/test_song/nolyrics.csg.source similarity index 100% rename from test/test_chordpro/nolyrics.csg.source rename to test/test_song/nolyrics.csg.source diff --git a/test/test_chordpro/nolyrics.tsg b/test/test_song/nolyrics.tsg similarity index 100% rename from test/test_chordpro/nolyrics.tsg rename to test/test_song/nolyrics.tsg diff --git a/test/test_chordpro/tags.csg b/test/test_song/tags.csg similarity index 100% rename from test/test_chordpro/tags.csg rename to test/test_song/tags.csg diff --git a/test/test_chordpro/tags.csg.source b/test/test_song/tags.csg.source similarity index 100% rename from test/test_chordpro/tags.csg.source rename to test/test_song/tags.csg.source diff --git a/test/test_chordpro/tags.tsg b/test/test_song/tags.tsg similarity index 100% rename from test/test_chordpro/tags.tsg rename to test/test_song/tags.tsg diff --git a/test/test_chordpro/test_parser.py b/test/test_song/test_parser.py similarity index 92% rename from test/test_chordpro/test_parser.py rename to test/test_song/test_parser.py index 0689adcf..298f0017 100644 --- a/test/test_chordpro/test_parser.py +++ b/test/test_song/test_parser.py @@ -9,14 +9,17 @@ import unittest from pkg_resources import resource_filename from patacrep import files -from patacrep.build import DEFAULT_CONFIG +from patacrep.songs import DEFAULT_CONFIG from patacrep.encoding import open_read from patacrep.songs import errors -from .. import disable_logging +from .. import logging_reduced from .. import dynamic # pylint: disable=unused-import -OUTPUTS = ['csg', 'tsg', 'html'] +OUTPUTS = { + 'csg': ['csg', 'tsg', 'html'], + 'tsg': ['tsg'], +} class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest): """Test of chorpro parser, and several renderers. @@ -57,11 +60,15 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest): destname = "{}.{}".format(base, out_format) with self.chdir(): with open_read(destname) as expectfile: - with disable_logging(): + with logging_reduced(): song = self.song_plugins[out_format][in_format](sourcename, self.config) + expected = expectfile.read().strip().replace( + "@TEST_FOLDER@", + files.path2posix(resource_filename(__name__, "")), + ) self.assertMultiLineEqual( song.render().strip(), - expectfile.read().strip(), + expected, ) @classmethod @@ -82,7 +89,7 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest): for source in sorted(glob.glob('*.*.source')): [*base, in_format, _] = source.split('.') base = '.'.join(base) - for out_format in OUTPUTS: + for out_format in OUTPUTS[in_format]: outname = "{}.{}".format(base, out_format) if not os.path.exists(outname): continue diff --git a/test/test_chordpro/ukulelechords.csg b/test/test_song/ukulelechords.csg similarity index 100% rename from test/test_chordpro/ukulelechords.csg rename to test/test_song/ukulelechords.csg diff --git a/test/test_chordpro/ukulelechords.csg.source b/test/test_song/ukulelechords.csg.source similarity index 100% rename from test/test_chordpro/ukulelechords.csg.source rename to test/test_song/ukulelechords.csg.source diff --git a/test/test_chordpro/ukulelechords.tsg b/test/test_song/ukulelechords.tsg similarity index 100% rename from test/test_chordpro/ukulelechords.tsg rename to test/test_song/ukulelechords.tsg diff --git a/test/test_compilation/.gitignore b/test/test_songbook/.gitignore similarity index 100% rename from test/test_compilation/.gitignore rename to test/test_songbook/.gitignore diff --git a/test/test_songbook/__init__.py b/test/test_songbook/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/test/test_songbook/datadir.sb b/test/test_songbook/datadir.sb new file mode 100644 index 00000000..f44c3dba --- /dev/null +++ b/test/test_songbook/datadir.sb @@ -0,0 +1,6 @@ +bookoptions: +- pictures +datadir: +- datadir_datadir +- datadir_datadir2 +lang: en diff --git a/test/test_compilation/datadir.tex.control b/test/test_songbook/datadir.tex.control similarity index 100% rename from test/test_compilation/datadir.tex.control rename to test/test_songbook/datadir.tex.control diff --git a/test/test_compilation/datadir_datadir/img/datadir.png b/test/test_songbook/datadir_datadir/img/datadir.png similarity index 100% rename from test/test_compilation/datadir_datadir/img/datadir.png rename to test/test_songbook/datadir_datadir/img/datadir.png diff --git a/test/test_compilation/datadir_datadir/scores/datadir.ly b/test/test_songbook/datadir_datadir/scores/datadir.ly similarity index 100% rename from test/test_compilation/datadir_datadir/scores/datadir.ly rename to test/test_songbook/datadir_datadir/scores/datadir.ly diff --git a/test/test_compilation/datadir_datadir/songs/datadir.csg b/test/test_songbook/datadir_datadir/songs/datadir.csg similarity index 100% rename from test/test_compilation/datadir_datadir/songs/datadir.csg rename to test/test_songbook/datadir_datadir/songs/datadir.csg diff --git a/test/test_compilation/datadir_datadir/songs/datadir.tsg b/test/test_songbook/datadir_datadir/songs/datadir.tsg similarity index 100% rename from test/test_compilation/datadir_datadir/songs/datadir.tsg rename to test/test_songbook/datadir_datadir/songs/datadir.tsg diff --git a/test/test_compilation/datadir_datadir/songs/datadir2.csg b/test/test_songbook/datadir_datadir/songs/datadir2.csg similarity index 100% rename from test/test_compilation/datadir_datadir/songs/datadir2.csg rename to test/test_songbook/datadir_datadir/songs/datadir2.csg diff --git a/test/test_songbook/datadir_datadir/songs/datadir2.sg b/test/test_songbook/datadir_datadir/songs/datadir2.sg new file mode 100644 index 00000000..f37f351f --- /dev/null +++ b/test/test_songbook/datadir_datadir/songs/datadir2.sg @@ -0,0 +1,10 @@ +\beginsong{Image included from a different datadir\\\LaTeX} + [cover={img/datadir2}] + + \cover + + \lilypond{scores/datadir2.ly} + + \image{img/datadir2} + +\endsong diff --git a/test/test_compilation/datadir_datadir/songs/relative.csg b/test/test_songbook/datadir_datadir/songs/relative.csg similarity index 100% rename from test/test_compilation/datadir_datadir/songs/relative.csg rename to test/test_songbook/datadir_datadir/songs/relative.csg diff --git a/test/test_compilation/datadir_datadir/songs/relative.ly b/test/test_songbook/datadir_datadir/songs/relative.ly similarity index 100% rename from test/test_compilation/datadir_datadir/songs/relative.ly rename to test/test_songbook/datadir_datadir/songs/relative.ly diff --git a/test/test_compilation/datadir_datadir/songs/relative.png b/test/test_songbook/datadir_datadir/songs/relative.png similarity index 100% rename from test/test_compilation/datadir_datadir/songs/relative.png rename to test/test_songbook/datadir_datadir/songs/relative.png diff --git a/test/test_compilation/datadir_datadir/songs/relative.tsg b/test/test_songbook/datadir_datadir/songs/relative.tsg similarity index 100% rename from test/test_compilation/datadir_datadir/songs/relative.tsg rename to test/test_songbook/datadir_datadir/songs/relative.tsg diff --git a/test/test_compilation/datadir_datadir/songs/subdir/subdir.csg b/test/test_songbook/datadir_datadir/songs/subdir/subdir.csg similarity index 100% rename from test/test_compilation/datadir_datadir/songs/subdir/subdir.csg rename to test/test_songbook/datadir_datadir/songs/subdir/subdir.csg diff --git a/test/test_compilation/datadir_datadir/songs/subdir/subdir.ly b/test/test_songbook/datadir_datadir/songs/subdir/subdir.ly similarity index 100% rename from test/test_compilation/datadir_datadir/songs/subdir/subdir.ly rename to test/test_songbook/datadir_datadir/songs/subdir/subdir.ly diff --git a/test/test_compilation/datadir_datadir/songs/subdir/subdir.png b/test/test_songbook/datadir_datadir/songs/subdir/subdir.png similarity index 100% rename from test/test_compilation/datadir_datadir/songs/subdir/subdir.png rename to test/test_songbook/datadir_datadir/songs/subdir/subdir.png diff --git a/test/test_compilation/datadir_datadir/songs/subdir/subdir.tsg b/test/test_songbook/datadir_datadir/songs/subdir/subdir.tsg similarity index 100% rename from test/test_compilation/datadir_datadir/songs/subdir/subdir.tsg rename to test/test_songbook/datadir_datadir/songs/subdir/subdir.tsg diff --git a/test/test_compilation/datadir_datadir2/img/datadir2.png b/test/test_songbook/datadir_datadir2/img/datadir2.png similarity index 100% rename from test/test_compilation/datadir_datadir2/img/datadir2.png rename to test/test_songbook/datadir_datadir2/img/datadir2.png diff --git a/test/test_compilation/datadir_datadir2/scores/datadir2.ly b/test/test_songbook/datadir_datadir2/scores/datadir2.ly similarity index 100% rename from test/test_compilation/datadir_datadir2/scores/datadir2.ly rename to test/test_songbook/datadir_datadir2/scores/datadir2.ly diff --git a/test/test_songbook/languages.sb b/test/test_songbook/languages.sb new file mode 100644 index 00000000..ff589a74 --- /dev/null +++ b/test/test_songbook/languages.sb @@ -0,0 +1,2 @@ +datadir: +- languages_datadir diff --git a/test/test_compilation/languages.tex.control b/test/test_songbook/languages.tex.control similarity index 100% rename from test/test_compilation/languages.tex.control rename to test/test_songbook/languages.tex.control diff --git a/test/test_compilation/languages_datadir/songs/language.csg b/test/test_songbook/languages_datadir/songs/language.csg similarity index 100% rename from test/test_compilation/languages_datadir/songs/language.csg rename to test/test_songbook/languages_datadir/songs/language.csg diff --git a/test/test_compilation/languages_datadir/songs/language_location.csg b/test/test_songbook/languages_datadir/songs/language_location.csg similarity index 100% rename from test/test_compilation/languages_datadir/songs/language_location.csg rename to test/test_songbook/languages_datadir/songs/language_location.csg diff --git a/test/test_compilation/languages_datadir/songs/no_language.csg b/test/test_songbook/languages_datadir/songs/no_language.csg similarity index 100% rename from test/test_compilation/languages_datadir/songs/no_language.csg rename to test/test_songbook/languages_datadir/songs/no_language.csg diff --git a/test/test_compilation/languages_datadir/songs/wrong_language.csg b/test/test_songbook/languages_datadir/songs/wrong_language.csg similarity index 100% rename from test/test_compilation/languages_datadir/songs/wrong_language.csg rename to test/test_songbook/languages_datadir/songs/wrong_language.csg diff --git a/test/test_compilation/languages_datadir/songs/wrong_location.csg b/test/test_songbook/languages_datadir/songs/wrong_location.csg similarity index 100% rename from test/test_compilation/languages_datadir/songs/wrong_location.csg rename to test/test_songbook/languages_datadir/songs/wrong_location.csg diff --git a/test/test_songbook/syntax.sb b/test/test_songbook/syntax.sb new file mode 100644 index 00000000..4b1f4ef2 --- /dev/null +++ b/test/test_songbook/syntax.sb @@ -0,0 +1,3 @@ +datadir: +- syntax_datadir +lang: en diff --git a/test/test_compilation/syntax.tex.control b/test/test_songbook/syntax.tex.control similarity index 100% rename from test/test_compilation/syntax.tex.control rename to test/test_songbook/syntax.tex.control diff --git a/test/test_compilation/syntax_datadir/songs/musicnote.csg b/test/test_songbook/syntax_datadir/songs/musicnote.csg similarity index 100% rename from test/test_compilation/syntax_datadir/songs/musicnote.csg rename to test/test_songbook/syntax_datadir/songs/musicnote.csg diff --git a/test/test_compilation/test_compilation.py b/test/test_songbook/test_compilation.py similarity index 99% rename from test/test_compilation/test_compilation.py rename to test/test_songbook/test_compilation.py index a095dbfb..b225756e 100644 --- a/test/test_compilation/test_compilation.py +++ b/test/test_songbook/test_compilation.py @@ -1,4 +1,4 @@ -"""Tests for the chordpro parser.""" +"""Tests for the songbook compilation.""" # pylint: disable=too-few-public-methods diff --git a/test/test_songbook/unicode.sb b/test/test_songbook/unicode.sb new file mode 100644 index 00000000..19392a88 --- /dev/null +++ b/test/test_songbook/unicode.sb @@ -0,0 +1,3 @@ +datadir: +- unicode_datadir +lang: en diff --git a/test/test_compilation/unicode.tex.control b/test/test_songbook/unicode.tex.control similarity index 100% rename from test/test_compilation/unicode.tex.control rename to test/test_songbook/unicode.tex.control diff --git a/test/test_compilation/unicode_datadir/songs/nonbreak.csg b/test/test_songbook/unicode_datadir/songs/nonbreak.csg similarity index 100% rename from test/test_compilation/unicode_datadir/songs/nonbreak.csg rename to test/test_songbook/unicode_datadir/songs/nonbreak.csg