forked from openlp/openlp
Added tests for LyriX import.
This commit is contained in:
parent
2a4205c0a1
commit
89ae1ae738
@ -73,9 +73,10 @@ class LyrixImport(SongImport):
|
||||
try:
|
||||
# Read the file
|
||||
for line in file:
|
||||
line = line.strip()
|
||||
line_number += 1
|
||||
if line_number == 4:
|
||||
song_title = line.strip()
|
||||
song_title = line
|
||||
if line_number < 7:
|
||||
continue
|
||||
# Detect and get CCLI number
|
||||
@ -84,22 +85,22 @@ class LyrixImport(SongImport):
|
||||
try:
|
||||
# If the CCLI was found, we are near the end
|
||||
# Find author
|
||||
line = next(file)
|
||||
author = line[line.find(':') + 2:].strip()
|
||||
line = next(file).strip()
|
||||
author = line[line.find(':') + 2:]
|
||||
# Find copyright
|
||||
copyright = next(file)
|
||||
copyright = next(file).strip()
|
||||
except StopIteration:
|
||||
pass
|
||||
break
|
||||
if line.strip() == '':
|
||||
if line == '':
|
||||
if current_verse != '':
|
||||
verses.append(current_verse)
|
||||
current_verse = ''
|
||||
else:
|
||||
if current_verse == '':
|
||||
current_verse += line.strip()
|
||||
current_verse += line
|
||||
else:
|
||||
current_verse += '\n' + line.strip()
|
||||
current_verse += '\n' + line
|
||||
except Exception as e:
|
||||
self.log_error(translate('SongsPlugin.LyrixImport', 'File %s' % file.name),
|
||||
translate('SongsPlugin.LyrixImport', 'Error: %s') % e)
|
||||
|
53
tests/functional/openlp_plugins/songs/test_lyriximport.py
Normal file
53
tests/functional/openlp_plugins/songs/test_lyriximport.py
Normal file
@ -0,0 +1,53 @@
|
||||
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
||||
|
||||
###############################################################################
|
||||
# OpenLP - Open Source Lyrics Projection #
|
||||
# --------------------------------------------------------------------------- #
|
||||
# Copyright (c) 2008-2015 OpenLP Developers #
|
||||
# --------------------------------------------------------------------------- #
|
||||
# This program is free software; you can redistribute it and/or modify it #
|
||||
# under the terms of the GNU General Public License as published by the Free #
|
||||
# Software Foundation; version 2 of the License. #
|
||||
# #
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT #
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
||||
# more details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU General Public License along #
|
||||
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
||||
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||
###############################################################################
|
||||
"""
|
||||
This module contains tests for the LyriX song importer.
|
||||
"""
|
||||
|
||||
import os
|
||||
from unittest import TestCase
|
||||
|
||||
from tests.helpers.songfileimport import SongImportTestHelper
|
||||
from openlp.plugins.songs.lib.importers.opensong import OpenSongImport
|
||||
from openlp.core.common import Registry
|
||||
from tests.functional import patch, MagicMock
|
||||
|
||||
TEST_PATH = os.path.abspath(
|
||||
os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'lyrixsongs'))
|
||||
|
||||
|
||||
class TestLyrixFileImport(SongImportTestHelper):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.importer_class_name = 'LyrixImport'
|
||||
self.importer_module_name = 'lyrix'
|
||||
super(TestLyrixFileImport, self).__init__(*args, **kwargs)
|
||||
|
||||
def test_song_import(self):
|
||||
"""
|
||||
Test that loading an LyriX file works correctly on various files
|
||||
"""
|
||||
self.file_import([os.path.join(TEST_PATH, 'A06.TXT')],
|
||||
self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json')))
|
||||
self.file_import([os.path.join(TEST_PATH, 'A002.TXT')],
|
||||
self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace2.json')))
|
||||
self.file_import([os.path.join(TEST_PATH, 'AO05.TXT')],
|
||||
self.load_external_result_data(os.path.join(TEST_PATH, 'in die regterhand.json')))
|
@ -19,7 +19,7 @@
|
||||
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||
###############################################################################
|
||||
"""
|
||||
This module contains tests for the OpenSong song importer.
|
||||
This module contains tests for the VideoPsalm song importer.
|
||||
"""
|
||||
|
||||
import os
|
||||
|
@ -127,7 +127,7 @@ class SongImportTestHelper(TestCase):
|
||||
if isinstance(author, str):
|
||||
self.mocked_add_author.assert_any_call(author)
|
||||
else:
|
||||
self.mocked_add_author.assert_any_call(author[0], author[1])
|
||||
self.mocked_add_author.assert_any_call(*author)
|
||||
if song_copyright:
|
||||
self.mocked_add_copyright.assert_called_with(song_copyright)
|
||||
if ccli_number:
|
||||
|
34
tests/resources/lyrixsongs/A002.TXT
Normal file
34
tests/resources/lyrixsongs/A002.TXT
Normal file
@ -0,0 +1,34 @@
|
||||
|
||||
-------------
|
||||
A002
|
||||
AMAZING GRACE
|
||||
-------------
|
||||
|
||||
1. AMAZING GRACE! HOW SWEET THE SOUND
|
||||
THAT SAVED A WRETCH LIKE ME;
|
||||
I ONCE WAS LOST, BUT NOW AM FOUND;
|
||||
WAS BLIND, BUT NOW I SEE.
|
||||
|
||||
2. 'TWAS GRACE THAT TAUGHT MY HEART TO FEAR
|
||||
AND GRACE MY FEARS RELIEVED;
|
||||
HOW PRECIOUS DID THAT GRACE APPEAR,
|
||||
THE HOUR I FIRST BELIEVED!
|
||||
|
||||
3. THROUGH MANY DANGERS, TRIALS AND SNARES
|
||||
I HAVE ALREADY COME;
|
||||
'TIS GRACE THAT BROUGHT ME SAFE THUS FAR
|
||||
AND GRACE WILL LEAD ME HOME.
|
||||
|
||||
4. THE LORD HAS PROMISED GOOD TO ME,
|
||||
HIS WORD MY HOPE SECURES;
|
||||
HE WILL MY SHIELD AND FORTRESS BE
|
||||
AS LONG AS LIFE ENDURES.
|
||||
|
||||
5. WHEN WE'VE BEEN THERE TEN THOUSAND YEARS
|
||||
BRIGHT SHINING AS THE SUN,
|
||||
WE'VE NO LESS DAYS TO SING GOD'S PRAISE
|
||||
THAN WHEN WE'D FIRST BEGUN.
|
||||
|
||||
CCLI no.: 22025
|
||||
Words/Music: Edwin Excell, John Newton, John P. Rees
|
||||
Public Domain
|
31
tests/resources/lyrixsongs/A06.TXT
Normal file
31
tests/resources/lyrixsongs/A06.TXT
Normal file
@ -0,0 +1,31 @@
|
||||
|
||||
----------------------------------
|
||||
A06
|
||||
AMAZING GRACE, HOW SWEET THE SOUND
|
||||
----------------------------------
|
||||
|
||||
1. AMAZING GRACE, HOW SWEET THE SOUND
|
||||
THAT SAVED A WRETCH LIKE ME
|
||||
I ONCE WAS LOST, BUT NOW I'M FOUND
|
||||
WAS BLIND, BUT NOW I SEE
|
||||
|
||||
2. 'TWAS GRACE THAT TAUGHT MY HEART TO FEAR
|
||||
AND GRACE MY FEARS RELIEVED
|
||||
HOW PRECIOUS DID THAT GRACE APPEAR
|
||||
THE HOUR I FIRST BELIEVED
|
||||
|
||||
3. THROUGH MANY DANGERS, TOILS AND SNARES
|
||||
I HAVE ALREADY COME, 'TWAS GRACE
|
||||
THAT BROUGHT ME SAFE THUS FAR
|
||||
AND GRACE WILL LEAD ME HOME
|
||||
|
||||
4. WHEN WE'VE BEEN THERE TEN THOUSAND YEARS
|
||||
BRIGHT SHINING AS THE SUN
|
||||
WE'VE NO LESS DAYS TO SING GOD'S PRAISE
|
||||
THAN WHEN WE'VE FIRST BEGUN
|
||||
|
||||
5. PRAISE GOD, PRAISE GOD
|
||||
PRAISE GOD, PRAISE GOD
|
||||
PRAISE GOD, PRAISE GOD
|
||||
PRAISE GOD..
|
||||
|
48
tests/resources/lyrixsongs/AO05.TXT
Normal file
48
tests/resources/lyrixsongs/AO05.TXT
Normal file
@ -0,0 +1,48 @@
|
||||
|
||||
--------------------------------
|
||||
AO05
|
||||
IN DIE REGTERHAND VAN HOM WAT IN
|
||||
--------------------------------
|
||||
|
||||
1. IN DIE REGTERHAND VAN HOM
|
||||
WAT IN MAJESTEIT REGEER
|
||||
Lê DIE BOEKROL VAN VERLOSSING
|
||||
SEWEMAAL VERSEëL
|
||||
EN NIEMAND KON GEVIND WORD
|
||||
OM SY SEëLS OOP TE BREEK
|
||||
TOT DIE LAM VAN GOD NA VORE KOM
|
||||
OM DIE BOEKROL SELF TE NEEM
|
||||
DIE VIER-EN-TWINTIG OUDERLINGE
|
||||
VAL TOE VOOR HOM NEER
|
||||
SAAM MET AL DIE ENG'LE
|
||||
IN DIE GANSE HEMELLEëR,
|
||||
EN ELKE WESE WAT ASEM HET
|
||||
OP DIE AARDE, IN DIE SEE, EN OOR DIE
|
||||
LENGTE EN DIE BREEDTE
|
||||
VAN DIE SKEPPING BRING HOM EER
|
||||
|
||||
2. HERE U ALLEEN IS WAARDIG
|
||||
OM DIE LEWENSBOEK TE NEEM
|
||||
EN U ALLEEN IS MAGTIG
|
||||
OM SY SEëLS OOP TE BREEK,
|
||||
WANT U'T VIR ONS GESTERWE,
|
||||
MET U BLOED HET U BETAAL
|
||||
OM ONS LOS TE KOOP
|
||||
UIT ELKE STAM EN NASIE,VOLK EN TAAL
|
||||
|
||||
AL DIE LOF EN DIE KRAG
|
||||
EN DIE EER
|
||||
EN DIE HEERLIKHEID
|
||||
EN RYKDON EN STERKTE
|
||||
AAN U ALLEEN O HEER
|
||||
AL DIE LOF EN DIE KRAG
|
||||
EN DIE EER
|
||||
EN WYSHEID AAN DIE LAM
|
||||
OP DIE TROON
|
||||
WAT NOU EN TOT IN
|
||||
EWIGHEID REGEER
|
||||
NOU EN TOT IN EWIGHEID
|
||||
REGEER
|
||||
DIE LAM WAT TOT IN
|
||||
EWIGHEID REGEER
|
||||
|
26
tests/resources/lyrixsongs/Amazing Grace.json
Normal file
26
tests/resources/lyrixsongs/Amazing Grace.json
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"title": "AMAZING GRACE, HOW SWEET THE SOUND",
|
||||
"verse_order_list": [],
|
||||
"verses": [
|
||||
[
|
||||
"1. AMAZING GRACE, HOW SWEET THE SOUND\nTHAT SAVED A WRETCH LIKE ME\nI ONCE WAS LOST, BUT NOW I'M FOUND\nWAS BLIND, BUT NOW I SEE",
|
||||
"v"
|
||||
],
|
||||
[
|
||||
"2. 'TWAS GRACE THAT TAUGHT MY HEART TO FEAR\nAND GRACE MY FEARS RELIEVED\nHOW PRECIOUS DID THAT GRACE APPEAR\nTHE HOUR I FIRST BELIEVED",
|
||||
"v"
|
||||
],
|
||||
[
|
||||
"3. THROUGH MANY DANGERS, TOILS AND SNARES\nI HAVE ALREADY COME, 'TWAS GRACE\nTHAT BROUGHT ME SAFE THUS FAR\nAND GRACE WILL LEAD ME HOME",
|
||||
"v"
|
||||
],
|
||||
[
|
||||
"4. WHEN WE'VE BEEN THERE TEN THOUSAND YEARS\nBRIGHT SHINING AS THE SUN\nWE'VE NO LESS DAYS TO SING GOD'S PRAISE\nTHAN WHEN WE'VE FIRST BEGUN",
|
||||
"v"
|
||||
],
|
||||
[
|
||||
"5. PRAISE GOD, PRAISE GOD\nPRAISE GOD, PRAISE GOD\nPRAISE GOD, PRAISE GOD\nPRAISE GOD..",
|
||||
"v"
|
||||
]
|
||||
]
|
||||
}
|
33
tests/resources/lyrixsongs/Amazing Grace2.json
Normal file
33
tests/resources/lyrixsongs/Amazing Grace2.json
Normal file
@ -0,0 +1,33 @@
|
||||
{
|
||||
"authors": [
|
||||
"John Newton",
|
||||
"Edwin Excell",
|
||||
"John P. Rees"
|
||||
],
|
||||
"ccli_number": "22025",
|
||||
"copyright": "Public Domain",
|
||||
"title": "AMAZING GRACE",
|
||||
"verse_order_list": [],
|
||||
"verses": [
|
||||
[
|
||||
"1. AMAZING GRACE! HOW SWEET THE SOUND\nTHAT SAVED A WRETCH LIKE ME;\nI ONCE WAS LOST, BUT NOW AM FOUND;\nWAS BLIND, BUT NOW I SEE.",
|
||||
"v"
|
||||
],
|
||||
[
|
||||
"2. 'TWAS GRACE THAT TAUGHT MY HEART TO FEAR\nAND GRACE MY FEARS RELIEVED;\nHOW PRECIOUS DID THAT GRACE APPEAR,\nTHE HOUR I FIRST BELIEVED!",
|
||||
"v"
|
||||
],
|
||||
[
|
||||
"3. THROUGH MANY DANGERS, TRIALS AND SNARES\nI HAVE ALREADY COME;\n'TIS GRACE THAT BROUGHT ME SAFE THUS FAR\nAND GRACE WILL LEAD ME HOME.",
|
||||
"v"
|
||||
],
|
||||
[
|
||||
"4. THE LORD HAS PROMISED GOOD TO ME,\nHIS WORD MY HOPE SECURES;\nHE WILL MY SHIELD AND FORTRESS BE\nAS LONG AS LIFE ENDURES.",
|
||||
"v"
|
||||
],
|
||||
[
|
||||
"5. WHEN WE'VE BEEN THERE TEN THOUSAND YEARS\nBRIGHT SHINING AS THE SUN,\nWE'VE NO LESS DAYS TO SING GOD'S PRAISE\nTHAN WHEN WE'D FIRST BEGUN.",
|
||||
"v"
|
||||
]
|
||||
]
|
||||
}
|
18
tests/resources/lyrixsongs/in die regterhand.json
Normal file
18
tests/resources/lyrixsongs/in die regterhand.json
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
"title": "IN DIE REGTERHAND VAN HOM WAT IN",
|
||||
"verse_order_list": [],
|
||||
"verses": [
|
||||
[
|
||||
"1. IN DIE REGTERHAND VAN HOM\nWAT IN MAJESTEIT REGEER\nLк DIE BOEKROL VAN VERLOSSING\nSEWEMAAL VERSEлL\nEN NIEMAND KON GEVIND WORD\nOM SY SEлLS OOP TE BREEK\nTOT DIE LAM VAN GOD NA VORE KOM\nOM DIE BOEKROL SELF TE NEEM\nDIE VIER-EN-TWINTIG OUDERLINGE\nVAL TOE VOOR HOM NEER\nSAAM MET AL DIE ENG'LE\nIN DIE GANSE HEMELLEлR,\nEN ELKE WESE WAT ASEM HET\nOP DIE AARDE, IN DIE SEE, EN OOR DIE\nLENGTE EN DIE BREEDTE\nVAN DIE SKEPPING BRING HOM EER",
|
||||
"v"
|
||||
],
|
||||
[
|
||||
"2. HERE U ALLEEN IS WAARDIG\nOM DIE LEWENSBOEK TE NEEM\nEN U ALLEEN IS MAGTIG\nOM SY SEлLS OOP TE BREEK,\nWANT U'T VIR ONS GESTERWE,\nMET U BLOED HET U BETAAL\nOM ONS LOS TE KOOP\nUIT ELKE STAM EN NASIE,VOLK EN TAAL",
|
||||
"v"
|
||||
],
|
||||
[
|
||||
"AL DIE LOF EN DIE KRAG\nEN DIE EER\nEN DIE HEERLIKHEID\nEN RYKDON EN STERKTE\nAAN U ALLEEN O HEER\nAL DIE LOF EN DIE KRAG\nEN DIE EER\nEN WYSHEID AAN DIE LAM\nOP DIE TROON\nWAT NOU EN TOT IN\nEWIGHEID REGEER\nNOU EN TOT IN EWIGHEID\nREGEER\nDIE LAM WAT TOT IN\nEWIGHEID REGEER",
|
||||
"v"
|
||||
]
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user