Fix the "ret_value" problem created by a little too much linting.

Add this to your merge proposal:
--------------------------------
lp:~raoul-snyman/openlp/fix-retvalue (revision 2684)
[SUCCESS] https://ci.openlp.io/job/Branch-01-Pull/1666/
[SUCCESS] https://ci.openlp.io/job/Branch-02-Functional-Tests/1577/
[SUCCESS] https://ci.openlp.io/job/Branch-03-Interface-Tests/1515/
[SUCCESS] https://ci.openlp.io/job/Branch-04a-Windows_Functional_Tests/1280/
[SUCCESS] https://ci.openlp.io/job/Branch-0...

bzr-revno: 2682
This commit is contained in:
raoul@snyman.info 2016-07-25 10:07:12 +02:00 committed by Raoul Snyman
commit 39e6ba873f
2 changed files with 69 additions and 29 deletions

View File

@ -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):
"""

View File

@ -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)