Browse Source

Create content tests

pull/179/head
Oliverpool 9 years ago
parent
commit
7c8653d8b2
  1. 0
      test/test_content/__init__.py
  2. 51
      test/test_content/datadir/songs/chordpro.csg
  3. 10
      test/test_content/datadir/songs/exsong.sg
  4. 6
      test/test_content/datadir/songs/intersong.is
  5. 0
      test/test_content/datadir/songs/jsonlist.json
  6. 51
      test/test_content/datadir/songs/subdir/chordpro.csg
  7. 70
      test/test_content/datadir/songs/texfile.tex
  8. 70
      test/test_content/datadir/songs/texsong.tsg
  9. 1
      test/test_content/sections.control
  10. 6
      test/test_content/sections.source
  11. 1
      test/test_content/songs.control
  12. 1
      test/test_content/songs.source
  13. 1
      test/test_content/sorted.control
  14. 1
      test/test_content/sorted.source
  15. 106
      test/test_content/test_content.py

0
test/test_content/__init__.py

51
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

10
test/test_content/datadir/songs/exsong.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

6
test/test_content/datadir/songs/intersong.is

@ -0,0 +1,6 @@
\selectlanguage{french}
\sortassong{}[by={QQ}]
\begin{intersong}
Lorem ipsum
\end{intersong}

0
test/test_content/datadir/songs/jsonlist.json

51
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

70
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

70
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

1
test/test_content/sections.control

@ -0,0 +1 @@
["section:Traditional", "exsong.sg", "section:Example", "texsong.tsg", "chordpro.csg", "exsong.sg"]

6
test/test_content/sections.source

@ -0,0 +1,6 @@
[["section", "Traditional"],
"exsong.sg",
["section", "Example"],
"texsong.tsg",
"chordpro.csg",
"exsong.sg"]

1
test/test_content/songs.control

@ -0,0 +1 @@
["exsong.sg", "texsong.tsg", "chordpro.csg", "subdir/chordpro.csg"]

1
test/test_content/songs.source

@ -0,0 +1 @@
["exsong.sg", "intersong.is", "jsonlist.json", "texfile.tex", "texsong.tsg", "chordpro.csg", "subdir/chordpro.csg"]

1
test/test_content/sorted.control

@ -0,0 +1 @@
["chordpro.csg", "exsong.sg", "subdir/chordpro.csg", "texsong.tsg"]

1
test/test_content/sorted.source

@ -0,0 +1 @@
[["sorted(fullpath)"]]

106
test/test_content/test_content.py

@ -0,0 +1,106 @@
"""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.song import SongRenderer
from patacrep.content.section import Section
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)
expandedlist = content.process_content(sbcontent, cls.config.copy())
sourcelist = list(map(cls._clean_path, 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, SongRenderer):
songpath = os.path.join(os.path.dirname(__file__), 'datadir', 'songs')
return files.relpath(elem.song.fullpath, songpath)
elif isinstance(elem, Section):
return "{}:{}".format(elem.keyword, elem.name)
else:
raise Exception(elem)
@classmethod
def _generate_config(cls):
"""Generate the config to process the content"""
config = DEFAULT_CONFIG.copy()
datadirpath = os.path.join(os.path.dirname(__file__), 'datadir')
config['datadir'] = [datadirpath]
config['_songdir'] = [
DataSubpath(path, 'songs')
for path in config['datadir']
]
config['_content_plugins'] = files.load_plugins(
datadirs=config.get('datadir', []),
root_modules=['content'],
keyword='CONTENT_PLUGINS',
)
config['_song_plugins'] = files.load_plugins(
datadirs=config.get('datadir', []),
root_modules=['songs'],
keyword='SONG_RENDERERS',
)['tsg']
cls.config = config
Loading…
Cancel
Save