diff --git a/tests/functional/openlp_core/lib/test_serviceitem.py b/tests/functional/openlp_core/lib/test_serviceitem.py index f554ded3a..7e094751c 100644 --- a/tests/functional/openlp_core/lib/test_serviceitem.py +++ b/tests/functional/openlp_core/lib/test_serviceitem.py @@ -30,8 +30,10 @@ from openlp.core.common import md5_hash from openlp.core.common.registry import Registry from openlp.core.common.settings import Settings from openlp.core.lib import ItemCapabilities, ServiceItem, ServiceItemType, FormattingTags + from tests.helpers.testmixin import TestMixin from tests.utils import assert_length, convert_file_service_item +from tests.utils.constants import RESOURCE_PATH VERSE = 'The Lord said to {r}Noah{/r}: \n'\ 'There\'s gonna be a {su}floody{/su}, {sb}floody{/sb}\n'\ @@ -58,7 +60,7 @@ RENDERED_VERSE = 'The Lord said to Noa 'e'\ 'n of the Lord\n' FOOTER = ['Arky Arky (Unknown)', 'Public Domain', 'CCLI 123456'] -TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'service')) +TEST_PATH = str(RESOURCE_PATH / 'service') __default_settings__ = { 'songs/enable chords': True, diff --git a/tests/functional/openlp_core/test_app.py b/tests/functional/openlp_core/test_app.py index 6f5b05803..5d0e11f6c 100644 --- a/tests/functional/openlp_core/test_app.py +++ b/tests/functional/openlp_core/test_app.py @@ -29,7 +29,7 @@ from PyQt5 import QtCore, QtWidgets from openlp.core.app import OpenLP, parse_options from openlp.core.common.settings import Settings -TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'resources')) +from tests.utils.constants import RESOURCE_PATH def test_parse_options_basic(): @@ -280,7 +280,7 @@ class TestOpenLP(TestCase): Test the reimplemented event method """ # GIVEN: A file path and a QEvent. - file_path = os.path.join(TEST_PATH, 'church.jpg') + file_path = str(RESOURCE_PATH / 'church.jpg') mocked_file_method = MagicMock(return_value=file_path) event = QtCore.QEvent(QtCore.QEvent.FileOpen) event.file = mocked_file_method diff --git a/tests/functional/openlp_plugins/bibles/test_csvimport.py b/tests/functional/openlp_plugins/bibles/test_csvimport.py index a3f9e01bd..7ecdc9cda 100644 --- a/tests/functional/openlp_plugins/bibles/test_csvimport.py +++ b/tests/functional/openlp_plugins/bibles/test_csvimport.py @@ -23,7 +23,6 @@ This module contains tests for the CSV Bible importer. """ import csv -import json from collections import namedtuple from unittest import TestCase from unittest.mock import ANY, MagicMock, PropertyMock, call, patch @@ -32,6 +31,8 @@ from openlp.core.common.path import Path from openlp.core.lib.exceptions import ValidationError from openlp.plugins.bibles.lib.bibleimport import BibleImport from openlp.plugins.bibles.lib.importers.csvbible import Book, CSVBible, Verse + +from tests.utils import load_external_result_data from tests.utils.constants import RESOURCE_PATH TEST_PATH = RESOURCE_PATH / 'bibles' @@ -330,8 +331,7 @@ class TestCSVImport(TestCase): """ # GIVEN: Test files with a mocked out "manager", "import_wizard", and mocked functions # get_book_ref_id_by_name, create_verse, create_book, session and get_language. - file_data = (TEST_PATH / 'dk1933.json').read_text() - test_data = json.loads(file_data) + test_data = load_external_result_data(TEST_PATH / 'dk1933.json') books_file = TEST_PATH / 'dk1933-books.csv' verses_file = TEST_PATH / 'dk1933-verses.csv' with patch('openlp.plugins.bibles.lib.importers.csvbible.CSVBible.application'): diff --git a/tests/functional/openlp_plugins/bibles/test_opensongimport.py b/tests/functional/openlp_plugins/bibles/test_opensongimport.py index 10813e4d8..833e47efc 100644 --- a/tests/functional/openlp_plugins/bibles/test_opensongimport.py +++ b/tests/functional/openlp_plugins/bibles/test_opensongimport.py @@ -22,7 +22,6 @@ """ This module contains tests for the OpenSong Bible importer. """ -import json from unittest import TestCase from unittest.mock import MagicMock, patch, call @@ -33,6 +32,7 @@ from openlp.plugins.bibles.lib.importers.opensong import OpenSongBible, get_text from openlp.plugins.bibles.lib.bibleimport import BibleImport from tests.helpers.testmixin import TestMixin +from tests.utils import load_external_result_data from tests.utils.constants import RESOURCE_PATH TEST_PATH = RESOURCE_PATH / 'bibles' @@ -399,8 +399,7 @@ class TestOpenSongImportFileImports(TestCase, TestMixin): """ # GIVEN: Test files with a mocked out "manager", "import_wizard", and mocked functions # get_book_ref_id_by_name, create_verse, create_book, session and get_language. - file_data = (TEST_PATH / 'dk1933.json').read_text() - test_data = json.loads(file_data) + test_data = load_external_result_data(TEST_PATH / 'dk1933.json') bible_file = 'opensong-dk1933.xml' with patch('openlp.plugins.bibles.lib.importers.opensong.OpenSongBible.application'): mocked_manager = MagicMock() diff --git a/tests/functional/openlp_plugins/bibles/test_osisimport.py b/tests/functional/openlp_plugins/bibles/test_osisimport.py index bec3c77aa..e5c9e1a62 100644 --- a/tests/functional/openlp_plugins/bibles/test_osisimport.py +++ b/tests/functional/openlp_plugins/bibles/test_osisimport.py @@ -22,7 +22,6 @@ """ This module contains tests for the OSIS Bible importer. """ -import json from unittest import TestCase from unittest.mock import MagicMock, call, patch @@ -30,6 +29,7 @@ from openlp.plugins.bibles.lib.bibleimport import BibleImport from openlp.plugins.bibles.lib.db import BibleDB from openlp.plugins.bibles.lib.importers.osis import OSISBible +from tests.utils import load_external_result_data from tests.utils.constants import RESOURCE_PATH TEST_PATH = RESOURCE_PATH / 'bibles' @@ -422,8 +422,7 @@ class TestOsisImportFileImports(TestCase): """ # GIVEN: Test files with a mocked out "manager", "import_wizard", and mocked functions # get_book_ref_id_by_name, create_verse, create_book, session and get_language. - file_data = (TEST_PATH / 'dk1933.json').read_text() - test_data = json.loads(file_data) + test_data = load_external_result_data(TEST_PATH / 'dk1933.json') bible_file = 'osis-dk1933.xml' with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'): mocked_manager = MagicMock() @@ -452,8 +451,7 @@ class TestOsisImportFileImports(TestCase): """ # GIVEN: Test files with a mocked out "manager", "import_wizard", and mocked functions # get_book_ref_id_by_name, create_verse, create_book, session and get_language. - file_data = (TEST_PATH / 'kjv.json').read_text() - test_data = json.loads(file_data) + test_data = load_external_result_data(TEST_PATH / 'kjv.json') bible_file = 'osis-kjv.xml' with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'): mocked_manager = MagicMock() @@ -482,8 +480,7 @@ class TestOsisImportFileImports(TestCase): """ # GIVEN: Test files with a mocked out "manager", "import_wizard", and mocked functions # get_book_ref_id_by_name, create_verse, create_book, session and get_language. - file_data = (TEST_PATH / 'web.json').read_text() - test_data = json.loads(file_data) + test_data = load_external_result_data(TEST_PATH / 'web.json') bible_file = 'osis-web.xml' with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'): mocked_manager = MagicMock() @@ -512,8 +509,7 @@ class TestOsisImportFileImports(TestCase): """ # GIVEN: Test files with a mocked out "manager", "import_wizard", and mocked functions # get_book_ref_id_by_name, create_verse, create_book, session and get_language. - file_data = (TEST_PATH / 'dk1933.json').read_text() - test_data = json.loads(file_data) + test_data = load_external_result_data(TEST_PATH / 'dk1933.json') bible_file = 'osis-dk1933-empty-verse.xml' with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'): mocked_manager = MagicMock() diff --git a/tests/functional/openlp_plugins/bibles/test_swordimport.py b/tests/functional/openlp_plugins/bibles/test_swordimport.py index 12758ae13..4e6f3a80a 100644 --- a/tests/functional/openlp_plugins/bibles/test_swordimport.py +++ b/tests/functional/openlp_plugins/bibles/test_swordimport.py @@ -22,7 +22,6 @@ """ This module contains tests for the SWORD Bible importer. """ -import json from unittest import TestCase, skipUnless from unittest.mock import MagicMock, patch @@ -34,6 +33,7 @@ except ImportError: from openlp.plugins.bibles.lib.db import BibleDB +from tests.utils import load_external_result_data from tests.utils.constants import TEST_RESOURCES_PATH TEST_PATH = TEST_RESOURCES_PATH / 'bibles' @@ -80,8 +80,7 @@ class TestSwordImport(TestCase): mocked_manager = MagicMock() mocked_import_wizard = MagicMock() importer = SwordBible(mocked_manager, path='.', name='.', file_path=None, sword_key='', sword_path='') - file_data = (TEST_PATH / 'dk1933.json').read_text() - test_data = json.loads(file_data) + test_data = load_external_result_data(TEST_PATH / 'dk1933.json') importer.wizard = mocked_import_wizard importer.get_book_ref_id_by_name = MagicMock() importer.create_verse = MagicMock() diff --git a/tests/functional/openlp_plugins/bibles/test_zefaniaimport.py b/tests/functional/openlp_plugins/bibles/test_zefaniaimport.py index 966239ef2..326426fc1 100644 --- a/tests/functional/openlp_plugins/bibles/test_zefaniaimport.py +++ b/tests/functional/openlp_plugins/bibles/test_zefaniaimport.py @@ -22,15 +22,13 @@ """ This module contains tests for the Zefania Bible importer. """ -import os -import json from unittest import TestCase from unittest.mock import MagicMock, patch -from openlp.core.common.path import Path -from openlp.plugins.bibles.lib.importers.zefania import ZefaniaBible from openlp.plugins.bibles.lib.db import BibleDB +from openlp.plugins.bibles.lib.importers.zefania import ZefaniaBible +from tests.utils import load_external_result_data from tests.utils.constants import RESOURCE_PATH TEST_PATH = RESOURCE_PATH / 'bibles' @@ -68,8 +66,7 @@ class TestZefaniaImport(TestCase): """ # GIVEN: Test files with a mocked out "manager", "import_wizard", and mocked functions # get_book_ref_id_by_name, create_verse, create_book, session and get_language. - file_data = (TEST_PATH / 'dk1933.json').read_text() - test_data = json.loads(file_data) + test_data = load_external_result_data(TEST_PATH / 'dk1933.json') bible_file = 'zefania-dk1933.xml' with patch('openlp.plugins.bibles.lib.importers.zefania.ZefaniaBible.application'): mocked_manager = MagicMock() @@ -98,8 +95,7 @@ class TestZefaniaImport(TestCase): """ # GIVEN: Test files with a mocked out "manager", "import_wizard", and mocked functions # get_book_ref_id_by_name, create_verse, create_book, session and get_language. - file_data = (TEST_PATH / 'rst.json').read_text() - test_data = json.loads(file_data) + test_data = load_external_result_data(TEST_PATH / 'rst.json') bible_file = 'zefania-rst.xml' with patch('openlp.plugins.bibles.lib.importers.zefania.ZefaniaBible.application'): mocked_manager = MagicMock() diff --git a/tests/functional/openlp_plugins/songs/test_opsproimport.py b/tests/functional/openlp_plugins/songs/test_opsproimport.py index 149e05142..099730d69 100644 --- a/tests/functional/openlp_plugins/songs/test_opsproimport.py +++ b/tests/functional/openlp_plugins/songs/test_opsproimport.py @@ -22,7 +22,6 @@ """ This module contains tests for the WorshipCenter Pro song importer. """ -import json from unittest import TestCase, skipUnless from unittest.mock import patch, MagicMock @@ -33,6 +32,7 @@ try: except ImportError: CAN_RUN_TESTS = False +from tests.utils import load_external_result_data from tests.utils.constants import RESOURCE_PATH TEST_PATH = RESOURCE_PATH / 'opsprosongs' @@ -106,8 +106,7 @@ class TestOpsProSongImport(TestCase): importer.process_song(song, lyrics, []) # THEN: The imported data should look like expected - file_data = (TEST_PATH / 'You are so faithful.json').read_text() - result_data = json.loads(file_data) + result_data = load_external_result_data(TEST_PATH / 'You are so faithful.json') self.assertListEqual(importer.verses, _get_item(result_data, 'verses')) self.assertListEqual(importer.verse_order_list_generated, _get_item(result_data, 'verse_order_list')) @@ -126,8 +125,7 @@ class TestOpsProSongImport(TestCase): importer.process_song(song, lyrics, []) # THEN: The imported data should look like expected - file_data = (TEST_PATH / 'Amazing Grace.json').read_text() - result_data = json.loads(file_data) + result_data = load_external_result_data(TEST_PATH / 'Amazing Grace.json') self.assertListEqual(importer.verses, _get_item(result_data, 'verses')) self.assertListEqual(importer.verse_order_list_generated, _get_item(result_data, 'verse_order_list')) @@ -146,8 +144,7 @@ class TestOpsProSongImport(TestCase): importer.process_song(song, lyrics, []) # THEN: The imported data should look like expected - file_data = (TEST_PATH / 'Amazing Grace.json').read_text() - result_data = json.loads(file_data) + result_data = load_external_result_data(TEST_PATH / 'Amazing Grace.json') self.assertListEqual(importer.verses, _get_item(result_data, 'verses')) self.assertListEqual(importer.verse_order_list_generated, _get_item(result_data, 'verse_order_list')) @@ -166,7 +163,6 @@ class TestOpsProSongImport(TestCase): importer.process_song(song, lyrics, []) # THEN: The imported data should look like expected - file_data = (TEST_PATH / 'Amazing Grace3.json').read_text() - result_data = json.loads(file_data) + result_data = load_external_result_data(TEST_PATH / 'Amazing Grace3.json') self.assertListEqual(importer.verses, _get_item(result_data, 'verses')) self.assertListEqual(importer.verse_order_list_generated, _get_item(result_data, 'verse_order_list')) diff --git a/tests/functional/openlp_plugins/songs/test_powerpraiseimport.py b/tests/functional/openlp_plugins/songs/test_powerpraiseimport.py index 4df5806ae..8c20e5c1a 100644 --- a/tests/functional/openlp_plugins/songs/test_powerpraiseimport.py +++ b/tests/functional/openlp_plugins/songs/test_powerpraiseimport.py @@ -23,14 +23,10 @@ The :mod:`powerpraiseimport` module provides the functionality for importing ProPresenter song files into the current installation database. """ -import os - -from openlp.core.common.path import Path - from tests.helpers.songfileimport import SongImportTestHelper +from tests.utils.constants import RESOURCE_PATH -TEST_PATH = os.path.abspath( - os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'powerpraisesongs')) +TEST_PATH = RESOURCE_PATH / 'powerpraisesongs' class TestPowerPraiseFileImport(SongImportTestHelper): @@ -44,7 +40,7 @@ class TestPowerPraiseFileImport(SongImportTestHelper): """ Test that loading a PowerPraise file works correctly """ - self.file_import([Path(TEST_PATH, 'Naher, mein Gott zu Dir.ppl')], - self.load_external_result_data(os.path.join(TEST_PATH, 'Naher, mein Gott zu Dir.json'))) - self.file_import([Path(TEST_PATH, 'You are so faithful.ppl')], - self.load_external_result_data(os.path.join(TEST_PATH, 'You are so faithful.json'))) + self.file_import([TEST_PATH / 'Naher, mein Gott zu Dir.ppl'], + self.load_external_result_data(TEST_PATH / 'Naher, mein Gott zu Dir.json')) + self.file_import([TEST_PATH / 'You are so faithful.ppl'], + self.load_external_result_data(TEST_PATH / 'You are so faithful.json')) diff --git a/tests/functional/openlp_plugins/songs/test_presentationmanagerimport.py b/tests/functional/openlp_plugins/songs/test_presentationmanagerimport.py index 5391c31af..a83384126 100644 --- a/tests/functional/openlp_plugins/songs/test_presentationmanagerimport.py +++ b/tests/functional/openlp_plugins/songs/test_presentationmanagerimport.py @@ -22,14 +22,10 @@ """ This module contains tests for the PresentationManager song importer. """ -import os - -from openlp.core.common.path import Path - from tests.helpers.songfileimport import SongImportTestHelper +from tests.utils.constants import RESOURCE_PATH -TEST_PATH = os.path.abspath( - os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'presentationmanagersongs')) +TEST_PATH = RESOURCE_PATH / 'presentationmanagersongs' class TestPresentationManagerFileImport(SongImportTestHelper): @@ -43,7 +39,7 @@ class TestPresentationManagerFileImport(SongImportTestHelper): """ Test that loading a PresentationManager file works correctly """ - self.file_import([Path(TEST_PATH, 'Great Is Thy Faithfulness.sng')], - self.load_external_result_data(os.path.join(TEST_PATH, 'Great Is Thy Faithfulness.json'))) - self.file_import([Path(TEST_PATH, 'Amazing Grace.sng')], - self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) + self.file_import([TEST_PATH / 'Great Is Thy Faithfulness.sng'], + self.load_external_result_data(TEST_PATH / 'Great Is Thy Faithfulness.json')) + self.file_import([TEST_PATH / 'Amazing Grace.sng'], + self.load_external_result_data(TEST_PATH / 'Amazing Grace.json')) diff --git a/tests/functional/openlp_plugins/songs/test_propresenterimport.py b/tests/functional/openlp_plugins/songs/test_propresenterimport.py index e93dd6d9f..941866c8a 100644 --- a/tests/functional/openlp_plugins/songs/test_propresenterimport.py +++ b/tests/functional/openlp_plugins/songs/test_propresenterimport.py @@ -23,14 +23,10 @@ The :mod:`propresenterimport` module provides the functionality for importing ProPresenter song files into the current installation database. """ -import os - -from openlp.core.common.path import Path - from tests.helpers.songfileimport import SongImportTestHelper +from tests.utils.constants import RESOURCE_PATH -TEST_PATH = os.path.abspath( - os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'propresentersongs')) +TEST_PATH = RESOURCE_PATH / 'propresentersongs' class TestProPresenterFileImport(SongImportTestHelper): @@ -44,19 +40,19 @@ class TestProPresenterFileImport(SongImportTestHelper): """ Test that loading a ProPresenter 4 file works correctly """ - self.file_import([Path(TEST_PATH, 'Amazing Grace.pro4')], - self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) + self.file_import([TEST_PATH / 'Amazing Grace.pro4'], + self.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([Path(TEST_PATH, 'Amazing Grace.pro5')], - self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) + 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([Path(TEST_PATH, 'Amazing Grace.pro6')], - self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) + self.file_import([TEST_PATH / 'Amazing Grace.pro6'], + self.load_external_result_data(TEST_PATH / 'Amazing Grace.json')) diff --git a/tests/functional/openlp_plugins/songs/test_songbeamerimport.py b/tests/functional/openlp_plugins/songs/test_songbeamerimport.py index 165abd1a9..76767ccfe 100644 --- a/tests/functional/openlp_plugins/songs/test_songbeamerimport.py +++ b/tests/functional/openlp_plugins/songs/test_songbeamerimport.py @@ -22,18 +22,16 @@ """ This module contains tests for the Songbeamer song importer. """ -import os from unittest import TestCase from unittest.mock import MagicMock, patch from openlp.core.common.registry import Registry -from openlp.core.common.path import Path from openlp.plugins.songs.lib.importers.songbeamer import SongBeamerImport, SongBeamerTypes from tests.helpers.songfileimport import SongImportTestHelper +from tests.utils.constants import RESOURCE_PATH -TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), - '..', '..', '..', 'resources', 'songbeamersongs')) +TEST_PATH = RESOURCE_PATH / 'songbeamersongs' class TestSongBeamerFileImport(SongImportTestHelper): @@ -52,19 +50,19 @@ class TestSongBeamerFileImport(SongImportTestHelper): mocked_returned_settings = MagicMock() mocked_returned_settings.value.side_effect = lambda value: True if value == 'songs/enable chords' else False mocked_settings.return_value = mocked_returned_settings - self.file_import([Path(TEST_PATH, 'Amazing Grace.sng')], - self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) - self.file_import([Path(TEST_PATH, 'Lobsinget dem Herrn.sng')], - self.load_external_result_data(os.path.join(TEST_PATH, 'Lobsinget dem Herrn.json'))) - self.file_import([Path(TEST_PATH, 'When I Call On You.sng')], - self.load_external_result_data(os.path.join(TEST_PATH, 'When I Call On You.json'))) + 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')) def test_cp1252_encoded_file(self): """ Test that a CP1252 encoded file get's decoded properly. """ - self.file_import([Path(TEST_PATH, 'cp1252song.sng')], - self.load_external_result_data(os.path.join(TEST_PATH, 'cp1252song.json'))) + self.file_import([TEST_PATH / 'cp1252song.sng'], + self.load_external_result_data(TEST_PATH / 'cp1252song.json')) class TestSongBeamerImport(TestCase): diff --git a/tests/functional/openlp_plugins/songs/test_songproimport.py b/tests/functional/openlp_plugins/songs/test_songproimport.py index 4e874165b..379e9e4e4 100644 --- a/tests/functional/openlp_plugins/songs/test_songproimport.py +++ b/tests/functional/openlp_plugins/songs/test_songproimport.py @@ -23,14 +23,10 @@ The :mod:`songproimport` module provides the functionality for importing SongPro song files into the current installation database. """ -import os - -from openlp.core.common.path import Path - from tests.helpers.songfileimport import SongImportTestHelper +from tests.utils.constants import RESOURCE_PATH -TEST_PATH = os.path.abspath( - os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'songprosongs')) +TEST_PATH = RESOURCE_PATH / 'songprosongs' class TestSongProFileImport(SongImportTestHelper): @@ -44,5 +40,5 @@ class TestSongProFileImport(SongImportTestHelper): """ Test that loading an SongPro file works correctly """ - self.file_import(Path(TEST_PATH, 'amazing-grace.txt'), - self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) + self.file_import(TEST_PATH / 'amazing-grace.txt', + self.load_external_result_data(TEST_PATH / 'Amazing Grace.json')) diff --git a/tests/functional/openlp_plugins/songs/test_songselect.py b/tests/functional/openlp_plugins/songs/test_songselect.py index fa2b2931d..a30000489 100644 --- a/tests/functional/openlp_plugins/songs/test_songselect.py +++ b/tests/functional/openlp_plugins/songs/test_songselect.py @@ -23,7 +23,6 @@ """ This module contains tests for the CCLI SongSelect importer. """ -import os from unittest import TestCase from unittest.mock import MagicMock, patch, call from urllib.error import URLError @@ -31,16 +30,15 @@ from urllib.error import URLError from PyQt5 import QtWidgets from openlp.core.common.registry import Registry -from openlp.core.common.path import Path from openlp.plugins.songs.forms.songselectform import SongSelectForm, SearchWorker from openlp.plugins.songs.lib import Song from openlp.plugins.songs.lib.songselect import SongSelectImport, LOGOUT_URL, BASE_URL from tests.helpers.songfileimport import SongImportTestHelper from tests.helpers.testmixin import TestMixin +from tests.utils.constants import RESOURCE_PATH -TEST_PATH = os.path.abspath( - os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'songselect')) +TEST_PATH = RESOURCE_PATH / 'songselect' class TestSongSelectImport(TestCase, TestMixin): @@ -817,10 +815,8 @@ class TestSongSelectFileImport(SongImportTestHelper): """ Test that loading an OpenSong file works correctly on various files """ - self.file_import([Path(TEST_PATH, 'TestSong.bin')], - self.load_external_result_data(os.path.join(TEST_PATH, 'TestSong-bin.json'))) - self.file_import([Path(TEST_PATH, 'TestSong.txt')], - self.load_external_result_data(os.path.join(TEST_PATH, 'TestSong-txt.json'))) + 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')) class TestSearchWorker(TestCase, TestMixin): diff --git a/tests/functional/openlp_plugins/songs/test_songshowplusimport.py b/tests/functional/openlp_plugins/songs/test_songshowplusimport.py index 79e8ba593..451241566 100644 --- a/tests/functional/openlp_plugins/songs/test_songshowplusimport.py +++ b/tests/functional/openlp_plugins/songs/test_songshowplusimport.py @@ -22,18 +22,16 @@ """ This module contains tests for the SongShow Plus song importer. """ -import os from unittest import TestCase from unittest.mock import patch, MagicMock -from openlp.core.common.path import Path from openlp.plugins.songs.lib import VerseType from openlp.plugins.songs.lib.importers.songshowplus import SongShowPlusImport from tests.helpers.songfileimport import SongImportTestHelper +from tests.utils.constants import RESOURCE_PATH -TEST_PATH = os.path.abspath( - os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'songshowplussongs')) +TEST_PATH = RESOURCE_PATH / 'songshowplussongs' class TestSongShowPlusFileImport(SongImportTestHelper): @@ -47,14 +45,14 @@ class TestSongShowPlusFileImport(SongImportTestHelper): """ Test that loading a SongShow Plus file works correctly on various files """ - self.file_import([Path(TEST_PATH, 'Amazing Grace.sbsong')], - self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) - self.file_import([Path(TEST_PATH, 'Beautiful Garden Of Prayer.sbsong')], - self.load_external_result_data(os.path.join(TEST_PATH, 'Beautiful Garden Of Prayer.json'))) - self.file_import([Path(TEST_PATH, 'a mighty fortress is our god.sbsong')], - self.load_external_result_data(os.path.join(TEST_PATH, 'a mighty fortress is our god.json'))) - self.file_import([Path(TEST_PATH, 'cleanse-me.sbsong')], - self.load_external_result_data(os.path.join(TEST_PATH, 'cleanse-me.json'))) + self.file_import([TEST_PATH / 'Amazing Grace.sbsong'], + self.load_external_result_data(TEST_PATH / 'Amazing Grace.json')) + self.file_import([TEST_PATH / 'Beautiful Garden Of Prayer.sbsong'], + self.load_external_result_data(TEST_PATH / 'Beautiful Garden Of Prayer.json')) + self.file_import([TEST_PATH / 'a mighty fortress is our god.sbsong'], + self.load_external_result_data(TEST_PATH / 'a mighty fortress is our god.json')) + self.file_import([TEST_PATH / 'cleanse-me.sbsong'], + self.load_external_result_data(TEST_PATH / 'cleanse-me.json')) class TestSongShowPlusImport(TestCase): diff --git a/tests/functional/openlp_plugins/songs/test_sundayplusimport.py b/tests/functional/openlp_plugins/songs/test_sundayplusimport.py index 5a5977943..769647d8f 100644 --- a/tests/functional/openlp_plugins/songs/test_sundayplusimport.py +++ b/tests/functional/openlp_plugins/songs/test_sundayplusimport.py @@ -21,15 +21,12 @@ """ This module contains tests for the SundayPlus song importer. """ -import os from unittest.mock import patch -from openlp.core.common.path import Path - from tests.helpers.songfileimport import SongImportTestHelper +from tests.utils.constants import RESOURCE_PATH -TEST_PATH = os.path.abspath( - os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'sundayplussongs')) +TEST_PATH = RESOURCE_PATH / 'sundayplussongs' class TestSundayPlusFileImport(SongImportTestHelper): @@ -46,5 +43,5 @@ class TestSundayPlusFileImport(SongImportTestHelper): with patch('openlp.plugins.songs.lib.importers.sundayplus.retrieve_windows_encoding') as \ mocked_retrieve_windows_encoding: mocked_retrieve_windows_encoding.return_value = 'cp1252' - self.file_import([Path(TEST_PATH, 'Amazing Grace.ptf')], - self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) + self.file_import([TEST_PATH / 'Amazing Grace.ptf'], + self.load_external_result_data(TEST_PATH / 'Amazing Grace.json')) diff --git a/tests/functional/openlp_plugins/songs/test_videopsalm.py b/tests/functional/openlp_plugins/songs/test_videopsalm.py index 69e4d9127..b4caddd0f 100644 --- a/tests/functional/openlp_plugins/songs/test_videopsalm.py +++ b/tests/functional/openlp_plugins/songs/test_videopsalm.py @@ -21,15 +21,12 @@ """ This module contains tests for the VideoPsalm song importer. """ -import os - -from openlp.core.common.path import Path - -from tests.helpers.songfileimport import SongImportTestHelper from unittest.mock import patch, MagicMock -TEST_PATH = os.path.abspath( - os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'videopsalmsongs')) +from tests.helpers.songfileimport import SongImportTestHelper +from tests.utils.constants import RESOURCE_PATH + +TEST_PATH = RESOURCE_PATH / 'videopsalmsongs' class TestVideoPsalmFileImport(SongImportTestHelper): @@ -49,7 +46,7 @@ class TestVideoPsalmFileImport(SongImportTestHelper): mocked_returned_settings.value.side_effect = lambda value: True if value == 'songs/enable chords' else False mocked_settings.return_value = mocked_returned_settings # Do the test import - self.file_import(Path(TEST_PATH, 'videopsalm-as-safe-a-stronghold.json'), - self.load_external_result_data(os.path.join(TEST_PATH, 'as-safe-a-stronghold.json'))) - self.file_import(Path(TEST_PATH, 'videopsalm-as-safe-a-stronghold2.json'), - self.load_external_result_data(os.path.join(TEST_PATH, 'as-safe-a-stronghold2.json'))) + self.file_import(TEST_PATH / 'videopsalm-as-safe-a-stronghold.json', + self.load_external_result_data(TEST_PATH / 'as-safe-a-stronghold.json')) + self.file_import(TEST_PATH / 'videopsalm-as-safe-a-stronghold2.json', + self.load_external_result_data(TEST_PATH / 'as-safe-a-stronghold2.json')) diff --git a/tests/functional/openlp_plugins/songs/test_wordsofworshipimport.py b/tests/functional/openlp_plugins/songs/test_wordsofworshipimport.py index c0cb9b47d..ab3a8f8d6 100644 --- a/tests/functional/openlp_plugins/songs/test_wordsofworshipimport.py +++ b/tests/functional/openlp_plugins/songs/test_wordsofworshipimport.py @@ -22,15 +22,10 @@ """ This module contains tests for the Words of Worship song importer. """ -import os - -from openlp.core.common.path import Path - from tests.helpers.songfileimport import SongImportTestHelper -from openlp.plugins.songs.lib.importers.wordsofworship import WordsOfWorshipImport +from tests.utils.constants import RESOURCE_PATH -TEST_PATH = os.path.abspath( - os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'wordsofworshipsongs')) +TEST_PATH = RESOURCE_PATH / 'wordsofworshipsongs' class TestWordsOfWorshipFileImport(SongImportTestHelper): @@ -44,10 +39,9 @@ class TestWordsOfWorshipFileImport(SongImportTestHelper): """ Test that loading a Words of Worship file works correctly """ - self.file_import([Path(TEST_PATH, 'Amazing Grace (6 Verses).wow-song')], - self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace (6 Verses).json'))) - self.file_import([Path(TEST_PATH, 'When morning gilds the skies.wsg')], - self.load_external_result_data(os.path.join(TEST_PATH, 'When morning gilds the skies.json'))) - self.file_import([Path(TEST_PATH, 'Holy Holy Holy Lord God Almighty.wow-song')], - self.load_external_result_data(os.path.join(TEST_PATH, - 'Holy Holy Holy Lord God Almighty.json'))) + self.file_import([TEST_PATH / 'Amazing Grace (6 Verses).wow-song'], + self.load_external_result_data(TEST_PATH / 'Amazing Grace (6 Verses).json')) + self.file_import([TEST_PATH / 'When morning gilds the skies.wsg'], + self.load_external_result_data(TEST_PATH / 'When morning gilds the skies.json')) + self.file_import([TEST_PATH / 'Holy Holy Holy Lord God Almighty.wow-song'], + self.load_external_result_data(TEST_PATH / 'Holy Holy Holy Lord God Almighty.json')) diff --git a/tests/functional/openlp_plugins/songs/test_worshipassistantimport.py b/tests/functional/openlp_plugins/songs/test_worshipassistantimport.py index be0179a98..91d6d0660 100644 --- a/tests/functional/openlp_plugins/songs/test_worshipassistantimport.py +++ b/tests/functional/openlp_plugins/songs/test_worshipassistantimport.py @@ -23,14 +23,10 @@ The :mod:`worshipassistantimport` module provides the functionality for importing WorshipAssistant song files into the current installation database. """ -import os - -from openlp.core.common.path import Path - from tests.helpers.songfileimport import SongImportTestHelper +from tests.utils.constants import RESOURCE_PATH -TEST_PATH = os.path.abspath( - os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'worshipassistantsongs')) +TEST_PATH = RESOURCE_PATH / 'worshipassistantsongs' class TestWorshipAssistantFileImport(SongImportTestHelper): @@ -44,9 +40,8 @@ class TestWorshipAssistantFileImport(SongImportTestHelper): """ Test that loading an Worship Assistant file works correctly """ - self.file_import(Path(TEST_PATH, 'du_herr.csv'), - self.load_external_result_data(os.path.join(TEST_PATH, 'du_herr.json'))) - self.file_import(Path(TEST_PATH, 'would_you_be_free.csv'), - self.load_external_result_data(os.path.join(TEST_PATH, 'would_you_be_free.json'))) - self.file_import(Path(TEST_PATH, 'would_you_be_free2.csv'), - self.load_external_result_data(os.path.join(TEST_PATH, 'would_you_be_free.json'))) + self.file_import(TEST_PATH / 'du_herr.csv', self.load_external_result_data(TEST_PATH / 'du_herr.json')) + self.file_import(TEST_PATH / 'would_you_be_free.csv', + self.load_external_result_data(TEST_PATH / 'would_you_be_free.json')) + self.file_import(TEST_PATH / 'would_you_be_free2.csv', + self.load_external_result_data(TEST_PATH/ 'would_you_be_free.json')) diff --git a/tests/functional/openlp_plugins/songs/test_zionworximport.py b/tests/functional/openlp_plugins/songs/test_zionworximport.py index 42991382e..329495a42 100644 --- a/tests/functional/openlp_plugins/songs/test_zionworximport.py +++ b/tests/functional/openlp_plugins/songs/test_zionworximport.py @@ -22,19 +22,17 @@ """ This module contains tests for the ZionWorx song importer. """ -import os from unittest import TestCase from unittest.mock import MagicMock, patch from openlp.core.common.registry import Registry -from openlp.core.common.path import Path -from openlp.plugins.songs.lib.importers.zionworx import ZionWorxImport from openlp.plugins.songs.lib.importers.songimport import SongImport +from openlp.plugins.songs.lib.importers.zionworx import ZionWorxImport from tests.helpers.songfileimport import SongImportTestHelper +from tests.utils.constants import RESOURCE_PATH -TEST_PATH = os.path.abspath( - os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'zionworxsongs')) +TEST_PATH = RESOURCE_PATH / 'zionworxsongs' class TestZionWorxImport(TestCase): @@ -73,5 +71,4 @@ class TestZionWorxFileImport(SongImportTestHelper): """ Test that loading an ZionWorx file works correctly on various files """ - self.file_import(Path(TEST_PATH, 'zionworx.csv'), - self.load_external_result_data(os.path.join(TEST_PATH, 'zionworx.json'))) + self.file_import(TEST_PATH / 'zionworx.csv', self.load_external_result_data(TEST_PATH / 'zionworx.json')) diff --git a/tests/helpers/songfileimport.py b/tests/helpers/songfileimport.py index 4b245b10b..6aedc7f03 100644 --- a/tests/helpers/songfileimport.py +++ b/tests/helpers/songfileimport.py @@ -29,7 +29,6 @@ from unittest import TestCase from unittest.mock import MagicMock, patch, call from openlp.core.common.registry import Registry -from openlp.plugins.songs.lib.importers.opensong import OpenSongImport log = logging.getLogger(__name__) @@ -78,13 +77,13 @@ class SongImportTestHelper(TestCase): self.add_author_patcher.stop() self.song_import_patcher.stop() - def load_external_result_data(self, file_name): + def load_external_result_data(self, file_path): """ A method to load and return an object containing the song data from an external file. + + :param openlp.core.common.path.Path file_path: The path of the file to load """ - # TODO: To path object - result_file = open(str(file_name, 'rb')) - return json.loads(result_file.read().decode()) + return json.loads(file_path.read_text()) def file_import(self, source_file_name, result_data): """ diff --git a/tests/interfaces/openlp_core/ui/media/vendor/test_mediainfoWrapper.py b/tests/interfaces/openlp_core/ui/media/vendor/test_mediainfoWrapper.py index 6ec2431b9..4bfda88c8 100644 --- a/tests/interfaces/openlp_core/ui/media/vendor/test_mediainfoWrapper.py +++ b/tests/interfaces/openlp_core/ui/media/vendor/test_mediainfoWrapper.py @@ -22,13 +22,13 @@ """ Package to test the openlp.core.ui.media package. """ - -import os from unittest import TestCase from openlp.core.ui.media.vendor.mediainfoWrapper import MediaInfoWrapper -TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', '..', '..', 'resources', 'media')) +from tests.utils.constants import RESOURCE_PATH + +TEST_PATH = RESOURCE_PATH / 'media' TEST_MEDIA = [['avi_file.avi', 61495], ['mp3_file.mp3', 134426], ['mpg_file.mpg', 9404], ['mp4_file.mp4', 188336]] @@ -40,7 +40,7 @@ class TestMediainfoWrapper(TestCase): """ for test_data in TEST_MEDIA: # GIVEN: a media file - full_path = os.path.normpath(os.path.join(TEST_PATH, test_data[0])) + full_path = str(TEST_PATH / test_data[0]) # WHEN the media data is retrieved results = MediaInfoWrapper.parse(full_path) diff --git a/tests/utils/__init__.py b/tests/utils/__init__.py index dd4d78354..1789c29ec 100644 --- a/tests/utils/__init__.py +++ b/tests/utils/__init__.py @@ -41,3 +41,12 @@ def convert_file_service_item(test_path, name, row=0): finally: open_file.close() return first_line + + +def load_external_result_data(file_path): + """ + A method to load and return an object containing the song data from an external file. + + :param openlp.core.common.path.Path file_path: The path of the file to load + """ + return json.loads(file_path.read_text())