From f2c7bf0367f935f61315e5e2aaea1a824ab6b9f4 Mon Sep 17 00:00:00 2001 From: John Lines Date: Wed, 4 Sep 2019 17:06:44 +0100 Subject: [PATCH] put default hints plugin directory and chnage name to singingthefaith-hints.tag --- .../songs/lib/importers/singingthefaith-hints.tag | 2 +- .../plugins/songs/lib/importers/singingthefaith.py | 14 ++++++++++++-- .../songs/test_singingthefaithimport.py | 11 +++++++---- tests/helpers/songfileimport.py | 3 ++- .../songs/singingthefaith/{H1.txt => H901.txt} | 2 +- .../songs/singingthefaith/{H2.txt => H902.txt} | 0 .../singingthefaith/{STF001.json => STF901.json} | 0 .../singingthefaith/{STF002.json => STF902.json} | 0 .../hints/{hints.tag => singingthefaith-hints.tag} | 0 9 files changed, 23 insertions(+), 9 deletions(-) rename resources/hints.tag => openlp/plugins/songs/lib/importers/singingthefaith-hints.tag (99%) rename tests/resources/songs/singingthefaith/{H1.txt => H901.txt} (79%) rename tests/resources/songs/singingthefaith/{H2.txt => H902.txt} (100%) rename tests/resources/songs/singingthefaith/{STF001.json => STF901.json} (100%) rename tests/resources/songs/singingthefaith/{STF002.json => STF902.json} (100%) rename tests/resources/songs/singingthefaith/hints/{hints.tag => singingthefaith-hints.tag} (100%) diff --git a/resources/hints.tag b/openlp/plugins/songs/lib/importers/singingthefaith-hints.tag similarity index 99% rename from resources/hints.tag rename to openlp/plugins/songs/lib/importers/singingthefaith-hints.tag index 3791e7be8..f865e0c3b 100644 --- a/resources/hints.tag +++ b/openlp/plugins/songs/lib/importers/singingthefaith-hints.tag @@ -1,6 +1,6 @@ Tag-STFHints-version: 1.0 Version: 2 -SongbookNumberInTitle: True +SongbookNumberInTitle: False End: Hymn: 2 VerseOrder: V1,C1,V2,C1,V3,C1 diff --git a/openlp/plugins/songs/lib/importers/singingthefaith.py b/openlp/plugins/songs/lib/importers/singingthefaith.py index e6fe78b48..8c5a86c10 100644 --- a/openlp/plugins/songs/lib/importers/singingthefaith.py +++ b/openlp/plugins/songs/lib/importers/singingthefaith.py @@ -30,6 +30,8 @@ from pathlib import Path from openlp.core.common.i18n import translate from openlp.plugins.songs.lib.importers.songimport import SongImport +from openlp.core.common.applocation import AppLocation + log = logging.getLogger(__name__) @@ -80,6 +82,7 @@ class SingingTheFaithImport(SongImport): """ Process the SingingTheFaith file - pass in a file-like object, not a file path. """ + hints_file_name = 'singingthefaith-hints.tag' singing_the_faith_version = 1 self.set_defaults() # Setup variables @@ -120,12 +123,19 @@ class SingingTheFaithImport(SongImport): # See if there is a hints file in the same location as the file dir_path = filename.parent - hints_file_path = dir_path / 'hints.tag' + hints_file_path = dir_path / hints_file_name try: with hints_file_path.open('r') as hints_file: hints_available = self.read_hints(hints_file, song_number_file) except FileNotFoundError: - hints_available = False + # Look for the hints file in the Plugins directory + hints_file_path = AppLocation.get_directory(AppLocation.PluginsDir) / 'songs' / 'lib' / \ + 'importers' / hints_file_name + try: + with hints_file_path.open('r') as hints_file: + hints_available = self.read_hints(hints_file, song_number_file) + except FileNotFoundError: + hints_available = False try: for line in file: diff --git a/tests/functional/openlp_plugins/songs/test_singingthefaithimport.py b/tests/functional/openlp_plugins/songs/test_singingthefaithimport.py index 1c7a259f4..70aa39544 100644 --- a/tests/functional/openlp_plugins/songs/test_singingthefaithimport.py +++ b/tests/functional/openlp_plugins/songs/test_singingthefaithimport.py @@ -40,12 +40,15 @@ class TestSingingTheFaithFileImport(SongImportTestHelper): """ Test that loading a Singing The Faith file works correctly on various files """ + # 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 / 'H1.txt'], - self.load_external_result_data(TEST_PATH / 'STF001.json')) + self.file_import([TEST_PATH / 'H901.txt'], + self.load_external_result_data(TEST_PATH / 'STF901.json')) # Whole song - self.file_import([TEST_PATH / 'H2.txt'], - self.load_external_result_data(TEST_PATH / 'STF002.json')) + self.file_import([TEST_PATH / 'H902.txt'], + self.load_external_result_data(TEST_PATH / 'STF902.json')) # Tests with hints - note that the hints directory has a hints.tag which specifies # SongbookNumberInTitle: True diff --git a/tests/helpers/songfileimport.py b/tests/helpers/songfileimport.py index 0c007fa18..542cc1860 100644 --- a/tests/helpers/songfileimport.py +++ b/tests/helpers/songfileimport.py @@ -153,7 +153,8 @@ class SongImportTestHelper(TestCase): 'song_number for %s should be %s' % (source_file_name, song_number) if verse_order_list: assert importer.verse_order_list == verse_order_list, \ - 'verse_order_list for %s should be %s' % (source_file_name, verse_order_list) + 'verse_order_list for %s should be %s and is %s' % (source_file_name, + verse_order_list, importer.verse_order_list) self.mocked_finish.assert_called_with() def _get_data(self, data, key): diff --git a/tests/resources/songs/singingthefaith/H1.txt b/tests/resources/songs/singingthefaith/H901.txt similarity index 79% rename from tests/resources/songs/singingthefaith/H1.txt rename to tests/resources/songs/singingthefaith/H901.txt index 3caf1cd11..877bbfa1b 100644 --- a/tests/resources/songs/singingthefaith/H1.txt +++ b/tests/resources/songs/singingthefaith/H901.txt @@ -6,4 +6,4 @@ John Newton (d. 1807) -Reproduced from Singing the Faith Electronic Words Edition, number 1 - or not as this is a hand made test file +Reproduced from Singing the Faith Electronic Words Edition, number 901 - or not as this is a hand made test file diff --git a/tests/resources/songs/singingthefaith/H2.txt b/tests/resources/songs/singingthefaith/H902.txt similarity index 100% rename from tests/resources/songs/singingthefaith/H2.txt rename to tests/resources/songs/singingthefaith/H902.txt diff --git a/tests/resources/songs/singingthefaith/STF001.json b/tests/resources/songs/singingthefaith/STF901.json similarity index 100% rename from tests/resources/songs/singingthefaith/STF001.json rename to tests/resources/songs/singingthefaith/STF901.json diff --git a/tests/resources/songs/singingthefaith/STF002.json b/tests/resources/songs/singingthefaith/STF902.json similarity index 100% rename from tests/resources/songs/singingthefaith/STF002.json rename to tests/resources/songs/singingthefaith/STF902.json diff --git a/tests/resources/songs/singingthefaith/hints/hints.tag b/tests/resources/songs/singingthefaith/hints/singingthefaith-hints.tag similarity index 100% rename from tests/resources/songs/singingthefaith/hints/hints.tag rename to tests/resources/songs/singingthefaith/hints/singingthefaith-hints.tag