start to fix tests

This commit is contained in:
Tim Bentley 2017-05-23 05:59:35 +01:00
parent cad03b9abd
commit b7001116da
3 changed files with 16 additions and 11 deletions

View File

@ -440,11 +440,14 @@ def get_file_encoding(filename):
log.exception('Error detecting file encoding')
def json_default(o):
def json_default(obj):
"""
Function to help save objects as JSON
:param o: object
:param obj: object
:return: the object dictionary
"""
return o.__dict__
try:
return obj.__dict__
except:
raise TypeError("Unserializable object {} of type {}".format(obj, type(obj)))

View File

@ -379,10 +379,12 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ThemeManage
critical_error_message_box(message=translate('OpenLP.ThemeManager', 'You have not selected a theme.'))
return
theme = item.data(QtCore.Qt.UserRole)
path, filter_used = QtWidgets.QFileDialog.getSaveFileName(self.main_window,
translate('OpenLP.ThemeManager', 'Save Theme - ({name})').format(name=theme),
Settings().value(self.settings_section + '/last directory export'),
translate('OpenLP.ThemeManager', 'OpenLP Themes (*.otz)'))
path, filter_used = \
QtWidgets.QFileDialog.getSaveFileName(self.main_window,
translate('OpenLP.ThemeManager', 'Save Theme - ({name})').
format(name=theme),
Settings().value(self.settings_section + '/last directory export'),
translate('OpenLP.ThemeManager', 'OpenLP Themes (*.otz)'))
self.application.set_busy_cursor()
if path:
Settings().setValue(self.settings_section + '/last directory export', path)

View File

@ -26,7 +26,6 @@ import os
import shutil
from unittest import TestCase
from tempfile import mkdtemp
from PyQt5 import QtWidgets
from tempfile import mkdtemp
@ -65,7 +64,7 @@ class TestThemeManager(TestCase):
mocked_zipfile_init.return_value = None
# WHEN: The theme is exported
theme_manager._export_theme(os.path.join('some', 'path'), 'Default')
theme_manager._export_theme(os.path.join('some', 'path', 'Default.otz'), 'Default')
# THEN: The zipfile should be created at the given path
mocked_zipfile_init.assert_called_with(os.path.join('some', 'path', 'Default.otz'), 'w')
@ -128,8 +127,9 @@ class TestThemeManager(TestCase):
theme_manager.path = ''
mocked_theme = MagicMock()
mocked_theme.theme_name = 'themename'
mocked_theme.extract_formatted_xml = MagicMock()
mocked_theme.extract_formatted_xml.return_value = 'fake_theme_xml'.encode()
mocked_theme.filename = "filename"
# mocked_theme.extract_formatted_xml = MagicMock()
# mocked_theme.extract_formatted_xml.return_value = 'fake_theme_xml'.encode()
# WHEN: Calling _write_theme with path to different images
file_name1 = os.path.join(TEST_RESOURCES_PATH, 'church.jpg')