From ebefc03674ecb0c59d715b19cc78233c724aa325 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Sat, 23 Jul 2016 23:41:24 +0200 Subject: [PATCH 1/3] Fix the disappearance of a variable :-) --- openlp/core/lib/theme.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openlp/core/lib/theme.py b/openlp/core/lib/theme.py index fc20037e7..c27b08cd0 100644 --- a/openlp/core/lib/theme.py +++ b/openlp/core/lib/theme.py @@ -474,6 +474,7 @@ class ThemeXML(object): if element.startswith('shadow') or element.startswith('outline'): master = 'font_main' # fix bold font + ret_value = None if element == 'weight': element = 'bold' if value == 'Normal': @@ -482,7 +483,7 @@ class ThemeXML(object): ret_value = True if element == 'proportion': element = 'size' - return False, master, element, ret_value + return False, master, element, ret_value if ret_value is not None else value def _create_attr(self, master, element, value): """ From ea455d9b3201f485cbf3ff38bcf9877b1b58f810 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Sun, 24 Jul 2016 22:41:27 +0200 Subject: [PATCH 2/3] Write some tests --- .../functional/openlp_core_lib/test_theme.py | 95 +++++++++++++------ 1 file changed, 67 insertions(+), 28 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_theme.py b/tests/functional/openlp_core_lib/test_theme.py index c006abb78..abacface8 100644 --- a/tests/functional/openlp_core_lib/test_theme.py +++ b/tests/functional/openlp_core_lib/test_theme.py @@ -22,43 +22,82 @@ """ Package to test the openlp.core.lib.theme package. """ -from tests.functional import MagicMock, patch from unittest import TestCase +import os from openlp.core.lib.theme import ThemeXML -class TestTheme(TestCase): +class TestThemeXML(TestCase): """ - Test the functions in the Theme module + Test the ThemeXML class """ - def setUp(self): - """ - Create the UI - """ - pass - - def tearDown(self): - """ - Delete all the C++ objects at the end so that we don't have a segfault - """ - pass - def test_new_theme(self): """ - Test the theme creation - basic test + Test the ThemeXML constructor """ - # GIVEN: A new theme - - # WHEN: A theme is created + # GIVEN: The ThemeXML class + # WHEN: A theme object is created default_theme = ThemeXML() - # 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', 'The theme should have a solid backgrounds') - self.assertTrue(default_theme.display_vertical_align == 0, - 'The theme should have a display_vertical_align of 0') - self.assertTrue(default_theme.font_footer_name == "Arial", - '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') + # THEN: The default values should be correct + self.assertEqual('#000000', default_theme.background_border_color, 'background_border_color should be "#000000"') + self.assertEqual('solid', default_theme.background_type, 'background_type should be "solid"') + self.assertEqual(0, default_theme.display_vertical_align, 'display_vertical_align should be 0') + self.assertEqual('Arial', default_theme.font_footer_name, 'font_footer_name should be "Arial"') + self.assertFalse(default_theme.font_main_bold, 'font_main_bold should be False') + self.assertEqual(47, len(default_theme.__dict__), 'The theme should have 47 attributes') + + def test_expand_json(self): + """ + Test the expand_json method + """ + # GIVEN: A ThemeXML object and some JSON to "expand" + theme = ThemeXML() + theme_json = { + 'background': { + 'border_color': '#000000', + 'type': 'solid' + }, + 'display': { + 'vertical_align': 0 + }, + 'font': { + 'footer': { + 'bold': False + }, + 'main': { + 'name': 'Arial' + } + } + } + + # WHEN: ThemeXML.expand_json() is run + theme.expand_json(theme_json) + + # THEN: The attributes should be set on the object + self.assertEqual('#000000', theme.background_border_color, 'background_border_color should be "#000000"') + self.assertEqual('solid', theme.background_type, 'background_type should be "solid"') + self.assertEqual(0, theme.display_vertical_align, 'display_vertical_align should be 0') + self.assertFalse(theme.font_footer_bold, 'font_footer_bold should be False') + self.assertEqual('Arial', theme.font_main_name, 'font_main_name should be "Arial"') + + def test_extend_image_filename(self): + """ + Test the extend_image_filename method + """ + # GIVEN: A theme object + theme = ThemeXML() + theme.theme_name = 'MyBeautifulTheme ' + theme.background_filename = ' video.mp4' + theme.background_type = 'video' + path = os.path.expanduser('~') + + # WHEN: ThemeXML.extend_image_filename is run + theme.extend_image_filename(path) + + # THEN: The filename of the background should be correct + expected_filename = os.path.join(path, 'MyBeautifulTheme', 'video.mp4') + self.assertEqual(expected_filename, theme.background_filename) + self.assertEqual('MyBeautifulTheme', theme.theme_name) + From 0dcae022bcf59f06bfb630605854153903bf0348 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Sun, 24 Jul 2016 22:49:00 +0200 Subject: [PATCH 3/3] some pep8 fixes --- tests/functional/openlp_core_lib/test_theme.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_theme.py b/tests/functional/openlp_core_lib/test_theme.py index abacface8..db6b78d02 100644 --- a/tests/functional/openlp_core_lib/test_theme.py +++ b/tests/functional/openlp_core_lib/test_theme.py @@ -41,7 +41,8 @@ class TestThemeXML(TestCase): default_theme = ThemeXML() # THEN: The default values should be correct - self.assertEqual('#000000', default_theme.background_border_color, 'background_border_color should be "#000000"') + self.assertEqual('#000000', default_theme.background_border_color, + 'background_border_color should be "#000000"') self.assertEqual('solid', default_theme.background_type, 'background_type should be "solid"') self.assertEqual(0, default_theme.display_vertical_align, 'display_vertical_align should be 0') self.assertEqual('Arial', default_theme.font_footer_name, 'font_footer_name should be "Arial"') @@ -100,4 +101,3 @@ class TestThemeXML(TestCase): expected_filename = os.path.join(path, 'MyBeautifulTheme', 'video.mp4') self.assertEqual(expected_filename, theme.background_filename) self.assertEqual('MyBeautifulTheme', theme.theme_name) -