From 4fb0e43c041dcbeb67f6440e66d888a325ba3f00 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Thu, 20 Nov 2014 06:58:33 +0000 Subject: [PATCH 1/4] New start old bugs --- openlp/core/lib/renderer.py | 9 +++- openlp/core/ui/firsttimeform.py | 11 ++++ .../songusage/forms/songusagedetailform.py | 2 +- .../openlp_core_lib/test_renderer.py | 54 ++++++++++++++++++- 4 files changed, 73 insertions(+), 3 deletions(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index ab4a5a4df..3f7ffc80f 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -250,7 +250,13 @@ class Renderer(OpenLPMixin, RegistryMixin, RegistryProperties): # Remove two or more option slide breaks next to each other (causing infinite loop). while '\n[---]\n[---]\n' in text: text = text.replace('\n[---]\n[---]\n', '\n[---]\n') - while True: + while ' [---]' in text: + text = text.replace(' [---]', '[---]') + while '[---] ' in text: + text = text.replace('[---] ', '[---]') + count = 0 + # only loop 5 times as there will never be more than 5 incorrect logical splits on a single slide. + while True and count < 5: slides = text.split('\n[---]\n', 2) # If there are (at least) two occurrences of [---] we use the first two slides (and neglect the last # for now). @@ -296,6 +302,7 @@ class Renderer(OpenLPMixin, RegistryMixin, RegistryProperties): lines = text.strip('\n').split('\n') pages.extend(self._paginate_slide(lines, line_end)) break + count =+ 1 else: # Clean up line endings. pages = self._paginate_slide(text.split('\n'), line_end) diff --git a/openlp/core/ui/firsttimeform.py b/openlp/core/ui/firsttimeform.py index 02d9e65f7..13d7ab0cf 100644 --- a/openlp/core/ui/firsttimeform.py +++ b/openlp/core/ui/firsttimeform.py @@ -95,6 +95,17 @@ class FirstTimeForm(QtGui.QWizard, UiFirstTimeWizard, RegistryProperties): """ self.application.process_events() if self.currentId() == FirstTimePage.Plugins: + if self.has_run_wizard: + self.songs_check_box.setChecked(self.plugin_manager.get_plugin_by_name('songs').is_active()) + self.bible_check_box.setChecked(self.plugin_manager.get_plugin_by_name('bibles').is_active()) + self.presentation_check_box.setChecked(self.plugin_manager.get_plugin_by_name( + 'presentations').is_active()) + self.image_check_box.setChecked(self.plugin_manager.get_plugin_by_name('images').is_active()) + self.media_check_box.setChecked(self.plugin_manager.get_plugin_by_name('media').is_active()) + self.remote_check_box.setChecked(self.plugin_manager.get_plugin_by_name('remotes').is_active()) + self.custom_check_box.setChecked(self.plugin_manager.get_plugin_by_name('custom').is_active()) + self.song_usage_check_box.setChecked(self.plugin_manager.get_plugin_by_name('songusage').is_active()) + self.alert_check_box.setChecked(self.plugin_manager.get_plugin_by_name('alerts').is_active()) if not self.web_access: return FirstTimePage.NoInternet else: diff --git a/openlp/plugins/songusage/forms/songusagedetailform.py b/openlp/plugins/songusage/forms/songusagedetailform.py index e8111c058..5d8470a99 100644 --- a/openlp/plugins/songusage/forms/songusagedetailform.py +++ b/openlp/plugins/songusage/forms/songusagedetailform.py @@ -99,7 +99,7 @@ class SongUsageDetailForm(QtGui.QDialog, Ui_SongUsageDetailDialog, RegistryPrope report_file_name = os.path.join(path, file_name) file_handle = None try: - file_handle = open(report_file_name, 'w') + file_handle = open(report_file_name, 'wb') for instance in usage: record = '\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",' \ '\"%s\",\"%s\"\n' % \ diff --git a/tests/functional/openlp_core_lib/test_renderer.py b/tests/functional/openlp_core_lib/test_renderer.py index 8df4816bb..3a3eaf4cb 100644 --- a/tests/functional/openlp_core_lib/test_renderer.py +++ b/tests/functional/openlp_core_lib/test_renderer.py @@ -34,7 +34,7 @@ from unittest import TestCase from PyQt4 import QtCore from openlp.core.common import Registry -from openlp.core.lib import Renderer, ScreenList +from openlp.core.lib import Renderer, ScreenList, ServiceItem from tests.interfaces import MagicMock @@ -109,3 +109,55 @@ class TestRenderer(TestCase): # THEN: The word lists should be the same. self.assertListEqual(result_words, expected_words) + + def format_slide_logical_split_test(self): + """ + Test that a line with text and a logic break does not break the renderer just returns the input + """ + # GIVEN: A line of with a space text and the logical split + renderer = Renderer() + renderer.empty_height = 25 + given_line = 'a\n[---]\nb' + expected_words = ['a
[---]
b'] + service_item = ServiceItem(None) + + # WHEN: Split the line based on rules + + result_words = renderer.format_slide(given_line, service_item) + + # THEN: The word lists should be the same. + self.assertListEqual(result_words, expected_words) + + def format_slide_blank_before_split_test(self): + """ + Test that a line with blanks before the logical split at handled + """ + # GIVEN: A line of with a space before the logical split + renderer = Renderer() + renderer.empty_height = 25 + given_line = '\n [---]\n' + expected_words = ['
[---]'] + service_item = ServiceItem(None) + + # WHEN: Split the line + result_words = renderer.format_slide(given_line, service_item) + + # THEN: The blanks have been removed. + self.assertListEqual(result_words, expected_words) + + def format_slide_blank_after_split_test(self): + """ + Test that a line with blanks before the logical split at handled + """ + # GIVEN: A line of with a space after the logical split + renderer = Renderer() + renderer.empty_height = 25 + given_line = '\n[---] \n' + expected_words = ['
[---] '] + service_item = ServiceItem(None) + + # WHEN: Split the line + result_words = renderer.format_slide(given_line, service_item) + + # THEN: The blanks have been removed. + self.assertListEqual(result_words, expected_words) \ No newline at end of file From 22a4974d86d353990897ba78f71d320e6413c1ad Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 22 Nov 2014 07:07:08 +0000 Subject: [PATCH 2/4] Comments --- tests/functional/openlp_core_lib/test_renderer.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_renderer.py b/tests/functional/openlp_core_lib/test_renderer.py index 3a3eaf4cb..d1a507373 100644 --- a/tests/functional/openlp_core_lib/test_renderer.py +++ b/tests/functional/openlp_core_lib/test_renderer.py @@ -88,7 +88,7 @@ class TestRenderer(TestCase): expected_tuple = ('{st}{r}Text text text{/r}{/st}', '{st}{r}', '') - # WHEN: + # WHEN: The renderer converts the start tags result = renderer._get_start_tags(given_raw_text) # THEN: Check if the correct tuple is returned. @@ -104,7 +104,7 @@ class TestRenderer(TestCase): given_line = 'beginning asdf \n end asdf' expected_words = ['beginning', 'asdf', 'end', 'asdf'] - # WHEN: Split the line + # WHEN: Split the line based on word split rules result_words = renderer._words_split(given_line) # THEN: The word lists should be the same. @@ -121,7 +121,7 @@ class TestRenderer(TestCase): expected_words = ['a
[---]
b'] service_item = ServiceItem(None) - # WHEN: Split the line based on rules + # WHEN: Split the line based on word split rules result_words = renderer.format_slide(given_line, service_item) @@ -139,7 +139,7 @@ class TestRenderer(TestCase): expected_words = ['
[---]'] service_item = ServiceItem(None) - # WHEN: Split the line + # WHEN: Split the line based on word split rules result_words = renderer.format_slide(given_line, service_item) # THEN: The blanks have been removed. @@ -156,8 +156,8 @@ class TestRenderer(TestCase): expected_words = ['
[---] '] service_item = ServiceItem(None) - # WHEN: Split the line + # WHEN: Split the line based on word split rules result_words = renderer.format_slide(given_line, service_item) # THEN: The blanks have been removed. - self.assertListEqual(result_words, expected_words) \ No newline at end of file + self.assertListEqual(result_words, expected_words) From f4ff654a654d80a12e1ed1460efcafb9a942d409 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 22 Nov 2014 20:26:59 +0000 Subject: [PATCH 3/4] If invlaid bible name stop searching Fixes: https://launchpad.net/bugs/1290246 --- openlp/plugins/bibles/lib/__init__.py | 5 ++++- .../openlp_plugins/bibles/test_lib_parse_reference.py | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/openlp/plugins/bibles/lib/__init__.py b/openlp/plugins/bibles/lib/__init__.py index d67319797..fb10e6740 100644 --- a/openlp/plugins/bibles/lib/__init__.py +++ b/openlp/plugins/bibles/lib/__init__.py @@ -330,7 +330,10 @@ def parse_reference(reference, bible, language_selection, book_ref_id=False): if not book_ref_id: book_ref_id = bible.get_book_ref_id_by_localised_name(book, language_selection) elif not bible.get_book_by_book_ref_id(book_ref_id): - book_ref_id = False + return False + # We have not found the book so do not continue + if not book_ref_id: + return False ranges = match.group('ranges') range_list = get_reference_match('range_separator').split(ranges) ref_list = [] diff --git a/tests/interfaces/openlp_plugins/bibles/test_lib_parse_reference.py b/tests/interfaces/openlp_plugins/bibles/test_lib_parse_reference.py index e20105ea1..989d62583 100644 --- a/tests/interfaces/openlp_plugins/bibles/test_lib_parse_reference.py +++ b/tests/interfaces/openlp_plugins/bibles/test_lib_parse_reference.py @@ -105,3 +105,13 @@ class TestBibleManager(TestCase, TestMixin): # THEN a verse array should be returned self.assertEqual([(54, 1, 1, -1), (54, 2, 1, 1)], results, "The bible verses should match the expected results") + + def parse_reference_four_test(self): + """ + Test the parse_reference method with non existence book + """ + # GIVEN given a bible in the bible manager + # WHEN asking to parse the bible reference + results = parse_reference('Raoul 1', self.manager.db_cache['tests'], MagicMock()) + # THEN a verse array should be returned + self.assertEqual(False, results, "The bible Search should return False") From 21db63b03216b062fe67da6268d9a9e77f965b5e Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 25 Nov 2014 21:36:52 +0000 Subject: [PATCH 4/4] remove blank line --- tests/functional/openlp_core_lib/test_renderer.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/functional/openlp_core_lib/test_renderer.py b/tests/functional/openlp_core_lib/test_renderer.py index d1a507373..5e3d087b9 100644 --- a/tests/functional/openlp_core_lib/test_renderer.py +++ b/tests/functional/openlp_core_lib/test_renderer.py @@ -122,7 +122,6 @@ class TestRenderer(TestCase): service_item = ServiceItem(None) # WHEN: Split the line based on word split rules - result_words = renderer.format_slide(given_line, service_item) # THEN: The word lists should be the same.