Merge branch 'fix-song-import-tests' into 'master'

Fix a bunch of tests and warnings

See merge request openlp/openlp!248
This commit is contained in:
Tim Bentley 2020-09-29 07:27:43 +00:00
commit 92030e63c4
9 changed files with 128 additions and 142 deletions

View File

@ -375,10 +375,10 @@ def resize_image(image_path, width, height, background='#000000', ignore_aspect_
size = QtCore.QSize(width, height)
elif image_ratio < resize_ratio:
# Use the image's height as reference for the new size.
size = QtCore.QSize(image_ratio * height, height)
size = QtCore.QSize(int(image_ratio * height), height)
else:
# Use the image's width as reference for the new size.
size = QtCore.QSize(width, 1 / (image_ratio / width))
size = QtCore.QSize(width, int(1 / (image_ratio / width)))
reader.setScaledSize(size)
preview = reader.read()
if image_ratio == resize_ratio:

View File

@ -166,7 +166,7 @@ class AspectRatioLayout(QtWidgets.QLayout):
x = rect.width() - self.margin - width
else:
x = self.margin + (available_width - width) / 2
widget.setGeometry(rect.x() + x, rect.y() + self.margin, width, height)
widget.setGeometry(rect.x() + int(x), rect.y() + self.margin, width, height)
self.resize.emit(QtCore.QSize(width, height))
def sizeHint(self):

View File

@ -33,30 +33,21 @@ from tests.utils.constants import RESOURCE_PATH
TEST_PATH = RESOURCE_PATH / 'songs' / 'opensong'
class TestOpenSongFileImport(SongImportTestHelper):
def __init__(self, *args, **kwargs):
self.importer_class_name = 'OpenSongImport'
self.importer_module_name = 'opensong'
super(TestOpenSongFileImport, self).__init__(*args, **kwargs)
def test_song_import(self):
"""
Test that loading an OpenSong file works correctly on various files
"""
# Mock out the settings - always return False
self.settings.value.side_effect = lambda value: True if value == 'songs/enable chords' else False
# Do the test import
self.file_import([TEST_PATH / 'Amazing Grace'],
self.load_external_result_data(TEST_PATH / 'Amazing Grace.json'))
self.file_import([TEST_PATH / 'Beautiful Garden Of Prayer'],
self.load_external_result_data(TEST_PATH / 'Beautiful Garden Of Prayer.json'))
self.file_import([TEST_PATH / 'One, Two, Three, Four, Five'],
self.load_external_result_data(TEST_PATH / 'One, Two, Three, Four, Five.json'))
self.file_import([TEST_PATH / 'Amazing Grace2'],
self.load_external_result_data(TEST_PATH / 'Amazing Grace.json'))
self.file_import([TEST_PATH / 'Amazing Grace with bad CCLI'],
self.load_external_result_data(TEST_PATH / 'Amazing Grace without CCLI.json'))
def test_opensong_file_import(settings):
"""
Test that loading an OpenSong file works correctly on various files
"""
with SongImportTestHelper('OpenSongImport', 'opensong') as helper:
helper.file_import([TEST_PATH / 'Amazing Grace'],
helper.load_external_result_data(TEST_PATH / 'Amazing Grace.json'))
helper.file_import([TEST_PATH / 'Beautiful Garden Of Prayer'],
helper.load_external_result_data(TEST_PATH / 'Beautiful Garden Of Prayer.json'))
helper.file_import([TEST_PATH / 'One, Two, Three, Four, Five'],
helper.load_external_result_data(TEST_PATH / 'One, Two, Three, Four, Five.json'))
helper.file_import([TEST_PATH / 'Amazing Grace2'],
helper.load_external_result_data(TEST_PATH / 'Amazing Grace.json'))
helper.file_import([TEST_PATH / 'Amazing Grace with bad CCLI'],
helper.load_external_result_data(TEST_PATH / 'Amazing Grace without CCLI.json'))
class TestOpenSongImport(TestCase):

View File

@ -25,34 +25,31 @@ ProPresenter song files into the current installation database.
from tests.helpers.songfileimport import SongImportTestHelper
from tests.utils.constants import RESOURCE_PATH
TEST_PATH = RESOURCE_PATH / 'songs' / 'propresenter'
class TestProPresenterFileImport(SongImportTestHelper):
def test_pro4_song_import(settings):
"""
Test that loading a ProPresenter 4 file works correctly
"""
with SongImportTestHelper('ProPresenterImport', 'propresenter') as helper:
helper.file_import([TEST_PATH / 'Amazing Grace.pro4'],
helper.load_external_result_data(TEST_PATH / 'Amazing Grace.json'))
def __init__(self, *args, **kwargs):
self.importer_class_name = 'ProPresenterImport'
self.importer_module_name = 'propresenter'
super(TestProPresenterFileImport, self).__init__(*args, **kwargs)
def test_pro4_song_import(self):
"""
Test that loading a ProPresenter 4 file works correctly
"""
self.file_import([TEST_PATH / 'Amazing Grace.pro4'],
self.load_external_result_data(TEST_PATH / 'Amazing Grace.json'))
def test_pro5_song_import(settings):
"""
Test that loading a ProPresenter 5 file works correctly
"""
with SongImportTestHelper('ProPresenterImport', 'propresenter') as helper:
helper.file_import([TEST_PATH / 'Amazing Grace.pro5'],
helper.load_external_result_data(TEST_PATH / 'Amazing Grace.json'))
def test_pro5_song_import(self):
"""
Test that loading a ProPresenter 5 file works correctly
"""
self.file_import([TEST_PATH / 'Amazing Grace.pro5'],
self.load_external_result_data(TEST_PATH / 'Amazing Grace.json'))
def test_pro6_song_import(self):
"""
Test that loading a ProPresenter 6 file works correctly
"""
self.file_import([TEST_PATH / 'Amazing Grace.pro6'],
self.load_external_result_data(TEST_PATH / 'Amazing Grace.json'))
def test_pro6_song_import(settings):
"""
Test that loading a ProPresenter 6 file works correctly
"""
with SongImportTestHelper('ProPresenterImport', 'propresenter') as helper:
helper.file_import([TEST_PATH / 'Amazing Grace.pro6'],
helper.load_external_result_data(TEST_PATH / 'Amazing Grace.json'))

View File

@ -28,26 +28,20 @@ from tests.utils.constants import RESOURCE_PATH
TEST_PATH = RESOURCE_PATH / 'songs' / 'singingthefaith'
class TestSingingTheFaithFileImport(SongImportTestHelper):
def __init__(self, *args, **kwargs):
self.importer_class_name = 'SingingTheFaithImport'
self.importer_module_name = 'singingthefaith'
super(TestSingingTheFaithFileImport, self).__init__(*args, **kwargs)
def test_song_import(self):
"""
Test that loading a Singing The Faith file works correctly on various files
"""
def test_singingthefaith_file_import(registry):
"""
Test that loading a Singing The Faith file works correctly on various files
"""
with SongImportTestHelper('SingingTheFaithImport', 'singingthefaith') as helper:
# Note that the previous tests without hints no longer apply as there is always a
# hints file, which contains the hints for the real Singing The Faith Songs.
# Unhinted songs here must be numbered above any real Singing The Faith Song
# Single verse
self.file_import([TEST_PATH / 'H901.txt'],
self.load_external_result_data(TEST_PATH / 'STF901.json'))
helper.file_import([TEST_PATH / 'H901.txt'],
helper.load_external_result_data(TEST_PATH / 'STF901.json'))
# Whole song
self.file_import([TEST_PATH / 'H902.txt'],
self.load_external_result_data(TEST_PATH / 'STF902.json'))
helper.file_import([TEST_PATH / 'H902.txt'],
helper.load_external_result_data(TEST_PATH / 'STF902.json'))
# Tests with hints - note that the hints directory has a hints.tag which specifies
# SongbookNumberInTitle: True
@ -55,8 +49,8 @@ class TestSingingTheFaithFileImport(SongImportTestHelper):
# song tests will need it
# Single verse
self.file_import([TEST_PATH / 'hints' / 'H1.txt'],
self.load_external_result_data(TEST_PATH / 'hints' / 'STF001.json'))
helper.file_import([TEST_PATH / 'hints' / 'H1.txt'],
helper.load_external_result_data(TEST_PATH / 'hints' / 'STF001.json'))
# Whole song
self.file_import([TEST_PATH / 'hints' / 'H2.txt'],
self.load_external_result_data(TEST_PATH / 'hints' / 'STF002.json'))
helper.file_import([TEST_PATH / 'hints' / 'H2.txt'],
helper.load_external_result_data(TEST_PATH / 'hints' / 'STF002.json'))

View File

@ -25,6 +25,7 @@ from unittest import TestCase
from unittest.mock import MagicMock, patch
from openlp.core.common.registry import Registry
from openlp.core.common.settings import Settings
from openlp.plugins.songs.lib.importers.songbeamer import SongBeamerImport, SongBeamerTypes
from tests.helpers.songfileimport import SongImportTestHelper
from tests.utils.constants import RESOURCE_PATH
@ -33,32 +34,28 @@ from tests.utils.constants import RESOURCE_PATH
TEST_PATH = RESOURCE_PATH / 'songs' / 'songbeamer'
class TestSongBeamerFileImport(SongImportTestHelper):
def __init__(self, *args, **kwargs):
self.importer_class_name = 'SongBeamerImport'
self.importer_module_name = 'songbeamer'
super(TestSongBeamerFileImport, self).__init__(*args, **kwargs)
def test_song_import(self):
"""
Test that loading an SongBeamer file works correctly on various files
"""
def test_songbeamer_file_import(settings):
"""
Test that loading an SongBeamer file works correctly on various files
"""
with SongImportTestHelper('SongBeamerImport', 'songbeamer') as helper:
# Mock out the settings - always return False
self.settings.value.side_effect = lambda value: True if value == 'songs/enable chords' else False
self.file_import([TEST_PATH / 'Amazing Grace.sng'],
self.load_external_result_data(TEST_PATH / 'Amazing Grace.json'))
self.file_import([TEST_PATH / 'Lobsinget dem Herrn.sng'],
self.load_external_result_data(TEST_PATH / 'Lobsinget dem Herrn.json'))
self.file_import([TEST_PATH / 'When I Call On You.sng'],
self.load_external_result_data(TEST_PATH / 'When I Call On You.json'))
Settings().setValue('songs/enable chords', True)
helper.file_import([TEST_PATH / 'Amazing Grace.sng'],
helper.load_external_result_data(TEST_PATH / 'Amazing Grace.json'))
helper.file_import([TEST_PATH / 'Lobsinget dem Herrn.sng'],
helper.load_external_result_data(TEST_PATH / 'Lobsinget dem Herrn.json'))
helper.file_import([TEST_PATH / 'When I Call On You.sng'],
helper.load_external_result_data(TEST_PATH / 'When I Call On You.json'))
def test_cp1252_encoded_file(self):
"""
Test that a CP1252 encoded file get's decoded properly.
"""
self.file_import([TEST_PATH / 'cp1252song.sng'],
self.load_external_result_data(TEST_PATH / 'cp1252song.json'))
def test_songbeamer_cp1252_encoded_file(settings):
"""
Test that a CP1252 encoded file get's decoded properly.
"""
with SongImportTestHelper('SongBeamerImport', 'songbeamer') as helper:
helper.file_import([TEST_PATH / 'cp1252song.sng'],
helper.load_external_result_data(TEST_PATH / 'cp1252song.json'))
class TestSongBeamerImport(TestCase):

View File

@ -922,16 +922,12 @@ class TestSongSelectForm(TestCase, TestMixin):
mocked_view_song.assert_called_with()
class TestSongSelectFileImport(SongImportTestHelper):
def __init__(self, *args, **kwargs):
self.importer_class_name = 'CCLIFileImport'
self.importer_module_name = 'cclifile'
super().__init__(*args, **kwargs)
def test_song_import(self):
"""
Test that loading an OpenSong file works correctly on various files
"""
self.file_import([TEST_PATH / 'TestSong.bin'], self.load_external_result_data(TEST_PATH / 'TestSong-bin.json'))
self.file_import([TEST_PATH / 'TestSong.txt'], self.load_external_result_data(TEST_PATH / 'TestSong-txt.json'))
def test_songselect_file_import():
"""
Test that loading a SongSelect file works correctly on various files
"""
with SongImportTestHelper('CCLIFileImport', 'cclifile') as helper:
helper.file_import([TEST_PATH / 'TestSong.bin'],
helper.load_external_result_data(TEST_PATH / 'TestSong-bin.json'))
helper.file_import([TEST_PATH / 'TestSong.txt'],
helper.load_external_result_data(TEST_PATH / 'TestSong-txt.json'))

View File

@ -28,44 +28,46 @@ from tests.utils.constants import RESOURCE_PATH
TEST_PATH = RESOURCE_PATH / 'songs' / 'wordsofworship'
class TestWordsOfWorshipFileImport(SongImportTestHelper):
def test_amazing_grace_song_import(registry):
"""
Test that loading a Words of Worship file works correctly
"""
with SongImportTestHelper('WordsOfWorshipImport', 'wordsofworship') as helper:
helper.file_import([TEST_PATH / 'Amazing Grace (6 Verses)_v2_1_2.wow-song'],
helper.load_external_result_data(TEST_PATH / 'Amazing Grace (6 Verses)_v2_1_2.json'))
def __init__(self, *args, **kwargs):
self.importer_class_name = 'WordsOfWorshipImport'
self.importer_module_name = 'wordsofworship'
super().__init__(*args, **kwargs)
def test_amazing_grace_song_import(self):
"""
Test that loading a Words of Worship file works correctly
"""
self.file_import([TEST_PATH / 'Amazing Grace (6 Verses)_v2_1_2.wow-song'],
self.load_external_result_data(TEST_PATH / 'Amazing Grace (6 Verses)_v2_1_2.json'))
def test_when_morning_gilds_song_import(registry):
"""
Test that loading a Words of Worship file v2.0.0 works correctly
"""
with SongImportTestHelper('WordsOfWorshipImport', 'wordsofworship') as helper:
helper.file_import([TEST_PATH / 'When morning gilds the skies_v2_0_0.wsg'],
helper.load_external_result_data(TEST_PATH / 'When morning gilds the skies_v2_0_0.json'))
def test_when_morning_gilds_song_import(self):
"""
Test that loading a Words of Worship file v2.0.0 works correctly
"""
self.file_import([TEST_PATH / 'When morning gilds the skies_v2_0_0.wsg'],
self.load_external_result_data(TEST_PATH / 'When morning gilds the skies_v2_0_0.json'))
def test_holy_holy_holy_song_import(self):
"""
Test that loading a Words of Worship file works correctly
"""
self.file_import([TEST_PATH / 'Holy Holy Holy Lord God Almighty_v2_1_2.wow-song'],
self.load_external_result_data(TEST_PATH / 'Holy Holy Holy Lord God Almighty_v2_1_2.json'))
def test_holy_holy_holy_song_import(registry):
"""
Test that loading a Words of Worship file works correctly
"""
with SongImportTestHelper('WordsOfWorshipImport', 'wordsofworship') as helper:
helper.file_import([TEST_PATH / 'Holy Holy Holy Lord God Almighty_v2_1_2.wow-song'],
helper.load_external_result_data(TEST_PATH / 'Holy Holy Holy Lord God Almighty_v2_1_2.json'))
def test_test_song_v2_0_0_song_import(self):
"""
Test that loading a Words of Worship file v2.0.0 works correctly
"""
self.file_import([TEST_PATH / 'Test_Song_v2_0_0.wsg'],
self.load_external_result_data(TEST_PATH / 'Test_Song_v2_0_0.json'))
def test_test_song_song_import(self):
"""
Test that loading a Words of Worship file v2.1.2 works correctly
"""
self.file_import([TEST_PATH / 'Test_Song_v2_1_2.wow-song'],
self.load_external_result_data(TEST_PATH / 'Test_Song_v2_1_2.json'))
def test_test_song_v2_0_0_song_import(registry):
"""
Test that loading a Words of Worship file v2.0.0 works correctly
"""
with SongImportTestHelper('WordsOfWorshipImport', 'wordsofworship') as helper:
helper.file_import([TEST_PATH / 'Test_Song_v2_0_0.wsg'],
helper.load_external_result_data(TEST_PATH / 'Test_Song_v2_0_0.json'))
def test_test_song_song_import(registry):
"""
Test that loading a Words of Worship file v2.1.2 works correctly
"""
with SongImportTestHelper('WordsOfWorshipImport', 'wordsofworship') as helper:
helper.file_import([TEST_PATH / 'Test_Song_v2_1_2.wow-song'],
helper.load_external_result_data(TEST_PATH / 'Test_Song_v2_1_2.json'))

View File

@ -73,6 +73,15 @@ class SongImportTestHelper(object):
self.add_author_patcher.stop()
self.song_import_patcher.stop()
def __enter__(self):
"""Make this class into a context manager"""
self.setUp()
return self
def __exit__(self, exc_type, exc_value, traceback):
"""Make this class into a context manager"""
self.tearDown
def load_external_result_data(self, file_path):
"""
A method to load and return an object containing the song data from an external file.