openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #22285
[Merge] lp:~trb143/openlp/theme-cleanup into lp:openlp
Tim Bentley has proposed merging lp:~trb143/openlp/theme-cleanup into lp:openlp.
Requested reviews:
Raoul Snyman (raoul-snyman)
For more details, see:
https://code.launchpad.net/~trb143/openlp/theme-cleanup/+merge/198115
Start of the ThemeManager refactor.
Add helper which has no UI code.
Add tests for Helper to increase coverage.
--
https://code.launchpad.net/~trb143/openlp/theme-cleanup/+merge/198115
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/core/ui/thememanager.py'
--- openlp/core/ui/thememanager.py 2013-11-16 20:32:50 +0000
+++ openlp/core/ui/thememanager.py 2013-12-06 19:11:27 +0000
@@ -33,7 +33,6 @@
import zipfile
import shutil
import logging
-import re
from xml.etree.ElementTree import ElementTree, XML
from PyQt4 import QtCore, QtGui
@@ -59,7 +58,7 @@
"""
super(ThemeManager, self).__init__(parent)
Registry().register('theme_manager', self)
- Registry().register_function('bootstrap_initialise', self.load_first_time_themes)
+ Registry().register_function('bootstrap_initialise', self.initialise)
Registry().register_function('bootstrap_post_set_up', self._push_themes)
self.settings_section = 'themes'
self.theme_form = ThemeForm(self)
@@ -135,15 +134,7 @@
Registry().register_function('theme_update_global', self.change_global_from_tab)
# Variables
self.theme_list = []
- self.path = AppLocation.get_section_data_path(self.settings_section)
- check_directory_exists(self.path)
- self.thumb_path = os.path.join(self.path, 'thumbnails')
- check_directory_exists(self.thumb_path)
- self.theme_form.path = self.path
self.old_background_image = None
- self.bad_v1_name_chars = re.compile(r'[%+\[\]]')
- # Last little bits of setting up
- self.global_theme = Settings().value(self.settings_section + '/global theme')
def check_list_state(self, item):
"""
@@ -392,6 +383,7 @@
"""
Imports any themes on start up and makes sure there is at least one theme
"""
+ log.debug('load_first_time_themes called')
self.application.set_busy_cursor()
files = AppLocation.get_files(self.settings_section, '.otz')
for theme_file in files:
@@ -410,8 +402,8 @@
def load_themes(self):
"""
- Loads the theme lists and triggers updates across the whole system
- using direct calls or core functions and events for the plugins.
+ Loads the theme lists and triggers updates across the whole system using direct calls or core functions and
+ events for the plugins.
The plugins will call back in to get the real list if they want it.
"""
log.debug('Load themes from dir')
@@ -636,18 +628,18 @@
self.main_window.finished_progress_bar()
self.load_themes()
- def generate_image(self, theme_data, forcePage=False):
+ def generate_image(self, theme_data, force_page=False):
"""
Call the renderer to build a Sample Image
``theme_data``
The theme to generated a preview for.
- ``forcePage``
+ ``force_page``
Flag to tell message lines per page need to be generated.
"""
log.debug('generate_image \n%s ', theme_data)
- return self.renderer.generate_preview(theme_data, forcePage)
+ return self.renderer.generate_preview(theme_data, force_page)
def get_preview_image(self, theme):
"""
@@ -672,7 +664,7 @@
theme.extend_image_filename(path)
return theme
- def _validate_theme_action(self, select_text, confirm_title, confirm_text, testPlugin=True, confirm=True):
+ def _validate_theme_action(self, select_text, confirm_title, confirm_text, test_plugin=True, confirm=True):
"""
Check to see if theme has been selected and the destructive action
is allowed.
@@ -694,7 +686,7 @@
message=translate('OpenLP.ThemeManager', 'You are unable to delete the default theme.'))
return False
# check for use in the system else where.
- if testPlugin:
+ if test_plugin:
for plugin in self.plugin_manager.plugins:
if plugin.uses_theme(theme):
critical_error_message_box(translate('OpenLP.ThemeManager', 'Validation Error'),
=== modified file 'openlp/core/ui/thememanagerhelper.py'
--- openlp/core/ui/thememanagerhelper.py 2013-10-13 13:51:13 +0000
+++ openlp/core/ui/thememanagerhelper.py 2013-12-06 19:11:27 +0000
@@ -29,10 +29,34 @@
"""
The Theme Controller helps manages adding, deleteing and modifying of themes.
"""
+import logging
+import os
+
+from openlp.core.common import AppLocation, Settings, check_directory_exists
+
+log = logging.getLogger(__name__)
class ThemeManagerHelper(object):
"""
Manages the non ui theme functions.
"""
- pass
\ No newline at end of file
+ def initialise(self):
+ """
+ Setup the manager
+ """
+ log.debug('initialise called')
+ self.global_theme = Settings().value(self.settings_section + '/global theme')
+ self.build_theme_path()
+ self.load_first_time_themes()
+
+ def build_theme_path(self):
+ """
+ Set up the theme path variables
+ """
+ log.debug('build theme path called')
+ self.path = AppLocation.get_section_data_path(self.settings_section)
+ check_directory_exists(self.path)
+ self.thumb_path = os.path.join(self.path, 'thumbnails')
+ check_directory_exists(self.thumb_path)
+ self.theme_form.path = self.path
\ No newline at end of file
=== modified file 'openlp/plugins/presentations/lib/messagelistener.py'
--- openlp/plugins/presentations/lib/messagelistener.py 2013-08-31 18:17:38 +0000
+++ openlp/plugins/presentations/lib/messagelistener.py 2013-12-06 19:11:27 +0000
@@ -316,7 +316,7 @@
hide_mode = message[2]
file = item.get_frame_path()
self.handler = item.processor
- if self.handler == self.media_item.Automatic:
+ if self.handler == self.media_item.automatic:
self.handler = self.media_item.findControllerByType(file)
if not self.handler:
return
=== modified file 'tests/functional/openlp_core_common/__init__.py'
--- tests/functional/openlp_core_common/__init__.py 2013-10-13 17:02:12 +0000
+++ tests/functional/openlp_core_common/__init__.py 2013-12-06 19:11:27 +0000
@@ -1,1 +1,28 @@
-__author__ = 'tim'
+# -*- coding: utf-8 -*-
+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
+
+###############################################################################
+# OpenLP - Open Source Lyrics Projection #
+# --------------------------------------------------------------------------- #
+# Copyright (c) 2008-2013 Raoul Snyman #
+# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
+# --------------------------------------------------------------------------- #
+# 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 #
+###############################################################################
=== modified file 'tests/functional/openlp_core_common/test_applocation.py'
--- tests/functional/openlp_core_common/test_applocation.py 2013-10-14 05:01:01 +0000
+++ tests/functional/openlp_core_common/test_applocation.py 2013-12-06 19:11:27 +0000
@@ -59,7 +59,6 @@
# WHEN: we call AppLocation.get_data_path()
data_path = AppLocation.get_data_path()
- print(data_path)
# THEN: check that all the correct methods were called, and the result is correct
mocked_settings.contains.assert_called_with('advanced/data path')
=== modified file 'tests/functional/openlp_core_lib/test_theme.py'
--- tests/functional/openlp_core_lib/test_theme.py 2013-10-18 18:11:17 +0000
+++ tests/functional/openlp_core_lib/test_theme.py 2013-12-06 19:11:27 +0000
@@ -62,9 +62,11 @@
# THEN: We should get some default behaviours
self.assertTrue(default_theme.background_border_color == '#000000', 'The theme should have a black border')
- self.assertTrue(default_theme.background_type == 'solid', 'There theme should have a solid backgrounds')
+ self.assertTrue(default_theme.background_type == 'solid', 'The theme should have a solid backgrounds')
self.assertTrue(default_theme.display_vertical_align == 0,
- 'There theme should have display_vertical_align of 0')
+ 'The theme should have a display_vertical_align of 0')
self.assertTrue(default_theme.font_footer_name == "Arial",
- 'There theme should has font_footer_name of Arial')
- self.assertTrue(default_theme.font_main_bold is False, 'There theme should has font_main_bold of false')
\ No newline at end of file
+ 'The theme should have a font_footer_name of Arial')
+ self.assertTrue(default_theme.font_main_bold is False, 'The theme should have a font_main_bold of false')
+ self.assertTrue(len(default_theme.__dict__) == 47, 'The theme should have 47 variables')
+
=== added file 'tests/interfaces/openlp_core_ui/test_thememanagerhelper.py'
--- tests/interfaces/openlp_core_ui/test_thememanagerhelper.py 1970-01-01 00:00:00 +0000
+++ tests/interfaces/openlp_core_ui/test_thememanagerhelper.py 2013-12-06 19:11:27 +0000
@@ -0,0 +1,99 @@
+# -*- coding: utf-8 -*-
+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
+
+###############################################################################
+# OpenLP - Open Source Lyrics Projection #
+# --------------------------------------------------------------------------- #
+# Copyright (c) 2008-2013 Raoul Snyman #
+# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
+# --------------------------------------------------------------------------- #
+# 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 #
+###############################################################################
+"""
+Interface tests to test the thememanagerhelper class and related methods.
+"""
+import os
+from unittest import TestCase
+from tempfile import mkstemp
+
+from openlp.core.common import Settings
+from openlp.core.ui import ThemeManagerHelper
+from tests.functional import patch, MagicMock
+
+
+class TestThemeManagerHelper(TestCase):
+ """
+ Test the functions in the ThemeManagerHelp[er module
+ """
+ def setUp(self):
+ """
+ Create the UI
+ """
+ fd, self.ini_file = mkstemp('.ini')
+ Settings().set_filename(self.ini_file)
+ self.helper = ThemeManagerHelper()
+ self.helper.settings_section = "themes"
+
+ def tearDown(self):
+ """
+ Delete all the C++ objects at the end so that we don't have a segfault
+ """
+ os.unlink(self.ini_file)
+ os.unlink(Settings().fileName())
+
+ def test_initialise(self):
+ """
+ Test the thememanagerhelper initialise - basic test
+ """
+ # GIVEN: A new a call to initialise
+ Settings().setValue('themes/global theme', 'my_theme')
+ self.helper.build_theme_path = MagicMock()
+ self.helper.load_first_time_themes = MagicMock()
+
+ # WHEN: the initialistion is run
+ self.helper.initialise()
+
+ # THEN:
+ self.assertEqual(1, self.helper.build_theme_path.call_count,
+ 'The function build_theme_path should have been called')
+ self.assertEqual(1, self.helper.load_first_time_themes.call_count,
+ 'The function load_first_time_themes should have been called only once')
+ self.assertEqual(self.helper.global_theme, 'my_theme',
+ 'The global theme should have been set to my_theme')
+
+ def test_build_theme_path(self):
+ """
+ Test the thememanagerhelper build_theme_path - basic test
+ """
+ # GIVEN: A new a call to initialise
+ with patch('openlp.core.common.applocation.check_directory_exists') as mocked_check_directory_exists:
+ # GIVEN: A mocked out Settings class and a mocked out AppLocation.get_directory()
+ mocked_check_directory_exists.return_value = True
+ Settings().setValue('themes/global theme', 'my_theme')
+
+ self.helper.theme_form = MagicMock()
+ #self.helper.load_first_time_themes = MagicMock()
+
+ # WHEN: the build_theme_path is run
+ self.helper.build_theme_path()
+
+ # THEN:
+ self.assertEqual(self.helper.path, self.helper.theme_form.path,
+ 'The theme path and the main path should be the same value')
\ No newline at end of file
Follow ups