forked from openlp/openlp
Fix tests so they work better. Pylint fixes and bug fixex
This commit is contained in:
parent
2491caf957
commit
96afb2a737
@ -438,8 +438,8 @@ class ServiceManager(QtGui.QWidget):
|
||||
log.debug(temp_file_name)
|
||||
path_file_name = unicode(self.fileName())
|
||||
path, file_name = os.path.split(path_file_name)
|
||||
basename = os.path.splitext(file_name)[0]
|
||||
service_file_name = '%s.osd' % basename
|
||||
base_name = os.path.splitext(file_name)[0]
|
||||
service_file_name = '%s.osd' % base_name
|
||||
log.debug(u'ServiceManager.saveFile - %s', path_file_name)
|
||||
Settings().setValue(self.main_window.serviceManagerSettingsSection + u'/last directory', path)
|
||||
service = []
|
||||
@ -667,11 +667,11 @@ class ServiceManager(QtGui.QWidget):
|
||||
fileName = unicode(fileName)
|
||||
if not os.path.exists(fileName):
|
||||
return False
|
||||
zip = None
|
||||
zip_file = None
|
||||
fileTo = None
|
||||
try:
|
||||
zip = zipfile.ZipFile(fileName)
|
||||
for zipinfo in zip.infolist():
|
||||
zip_file = zipfile.ZipFile(fileName)
|
||||
for zipinfo in zip_file.infolist():
|
||||
try:
|
||||
ucsfile = zipinfo.filename.decode(u'utf-8')
|
||||
except UnicodeDecodeError:
|
||||
@ -684,7 +684,7 @@ class ServiceManager(QtGui.QWidget):
|
||||
osfile = os.path.split(osfile)[1]
|
||||
log.debug(u'Extract file: %s', osfile)
|
||||
zipinfo.filename = osfile
|
||||
zip.extract(zipinfo, self.servicePath)
|
||||
zip_file.extract(zipinfo, self.servicePath)
|
||||
if osfile.endswith(u'osd'):
|
||||
p_file = os.path.join(self.servicePath, osfile)
|
||||
if 'p_file' in locals():
|
||||
@ -737,8 +737,8 @@ class ServiceManager(QtGui.QWidget):
|
||||
finally:
|
||||
if fileTo:
|
||||
fileTo.close()
|
||||
if zip:
|
||||
zip.close()
|
||||
if zip_file:
|
||||
zip_file.close()
|
||||
self.main_window.finishedProgressBar()
|
||||
Receiver.send_message(u'cursor_normal')
|
||||
self.repaintServiceList(-1, -1)
|
||||
@ -819,6 +819,9 @@ class ServiceManager(QtGui.QWidget):
|
||||
self.menu.exec_(self.serviceManagerList.mapToGlobal(point))
|
||||
|
||||
def onServiceItemNoteForm(self):
|
||||
"""
|
||||
Allow the service note to be edited
|
||||
"""
|
||||
item = self.findServiceItem()[0]
|
||||
self.serviceNoteForm.textEdit.setPlainText(
|
||||
self.serviceItems[item][u'service_item'].notes)
|
||||
|
@ -140,7 +140,7 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog):
|
||||
per save.
|
||||
"""
|
||||
if self.resetSuffixes:
|
||||
self.mainWindow.serviceManagerContents.resetSupportedSuffixes()
|
||||
self.service_manager.resetSupportedSuffixes()
|
||||
self.resetSuffixes = False
|
||||
|
||||
def _get_main_window(self):
|
||||
@ -151,4 +151,14 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog):
|
||||
self._main_window = Registry().get(u'main_window')
|
||||
return self._main_window
|
||||
|
||||
main_window = property(_get_main_window)
|
||||
main_window = property(_get_main_window)
|
||||
|
||||
def _get_service_manager(self):
|
||||
"""
|
||||
Adds the plugin manager to the class dynamically
|
||||
"""
|
||||
if not hasattr(self, u'_service_manager'):
|
||||
self._service_manager = Registry().get(u'service_manager')
|
||||
return self._service_manager
|
||||
|
||||
service_manager = property(_get_service_manager)
|
@ -189,10 +189,10 @@ class ImageMediaItem(MediaManagerItem):
|
||||
|
||||
def onResetClick(self):
|
||||
"""
|
||||
Called to reset the Live backgound with the image selected,
|
||||
Called to reset the Live background with the image selected,
|
||||
"""
|
||||
self.resetAction.setVisible(False)
|
||||
self.plugin.liveController.display.resetImage()
|
||||
self.live_controller.display.resetImage()
|
||||
|
||||
def liveThemeChanged(self):
|
||||
"""
|
||||
@ -211,7 +211,7 @@ class ImageMediaItem(MediaManagerItem):
|
||||
bitem = self.listView.item(item.row())
|
||||
filename = bitem.data(QtCore.Qt.UserRole)
|
||||
if os.path.exists(filename):
|
||||
if self.plugin.liveController.display.directImage(filename, background):
|
||||
if self.live_controller.display.directImage(filename, background):
|
||||
self.resetAction.setVisible(True)
|
||||
else:
|
||||
critical_error_message_box(UiStrings().LiveBGError,
|
||||
|
@ -131,7 +131,7 @@ class MediaMediaItem(MediaManagerItem):
|
||||
"""
|
||||
Called to reset the Live background with the media selected,
|
||||
"""
|
||||
self.live_controller.mediaController.media_reset(self.plugin.liveController)
|
||||
self.media_controller.media_reset(self.live_controller)
|
||||
self.resetAction.setVisible(False)
|
||||
|
||||
def videobackgroundReplaced(self):
|
||||
@ -154,7 +154,7 @@ class MediaMediaItem(MediaManagerItem):
|
||||
service_item.shortname = service_item.title
|
||||
(path, name) = os.path.split(filename)
|
||||
service_item.add_from_command(path, name,CLAPPERBOARD)
|
||||
if self.live_controller.mediaController.video(DisplayControllerType.Live, service_item,
|
||||
if self.media_controller.video(DisplayControllerType.Live, service_item,
|
||||
videoBehindText=True):
|
||||
self.resetAction.setVisible(True)
|
||||
else:
|
||||
|
@ -13,26 +13,28 @@ class TestRegistry(TestCase):
|
||||
|
||||
def registry_basic_test(self):
|
||||
"""
|
||||
Test the Service Item basic test
|
||||
Test the registry creation and its usage
|
||||
"""
|
||||
# GIVEN: A new registry
|
||||
registry = Registry.create()
|
||||
|
||||
# WHEN: I add a service it should save it
|
||||
# WHEN: I add a component it should save it
|
||||
mock_1 = MagicMock()
|
||||
Registry().register(u'test1', mock_1)
|
||||
|
||||
# THEN: we should be able retrieve the saved object
|
||||
# THEN: we should be able retrieve the saved component
|
||||
assert Registry().get(u'test1') == mock_1, u'The saved service can be retrieved and matches'
|
||||
|
||||
# WHEN: I add a service for the second time I am mad.
|
||||
# THEN I will get an exception
|
||||
# WHEN: I add a component for the second time I am mad.
|
||||
# THEN and I will get an exception
|
||||
with self.assertRaises(KeyError) as context:
|
||||
Registry().register(u'test1', mock_1)
|
||||
self.assertEqual(context.exception[0], u'Duplicate service exception test1')
|
||||
self.assertEqual(context.exception[0], u'Duplicate service exception test1',
|
||||
u'The correct exception has been thrown')
|
||||
|
||||
# WHEN I try to get back a non existent service
|
||||
# WHEN I try to get back a non existent component
|
||||
# THEN I will get an exception
|
||||
with self.assertRaises(KeyError) as context:
|
||||
temp = Registry().get(u'test2')
|
||||
self.assertEqual(context.exception[0], u'Service test2 not found in list')
|
||||
self.assertEqual(context.exception[0], u'Service test2 not found in list',
|
||||
u'The correct exception has been thrown')
|
||||
|
@ -6,7 +6,7 @@ from unittest import TestCase
|
||||
|
||||
from mock import MagicMock, patch
|
||||
from openlp.core.ui import starttimeform
|
||||
from PyQt4 import QtGui, QtTest
|
||||
from PyQt4 import QtCore, QtGui, QtTest
|
||||
|
||||
class TestStartTimeDialog(TestCase):
|
||||
|
||||
@ -51,15 +51,32 @@ class TestStartTimeDialog(TestCase):
|
||||
mocked_serviceitem = MagicMock()
|
||||
mocked_serviceitem.start_time = 61
|
||||
mocked_serviceitem.end_time = 3701
|
||||
mocked_serviceitem.media_length = 3701
|
||||
|
||||
# WHEN displaying the UI and pressing enter
|
||||
self.form.item = mocked_serviceitem
|
||||
with patch(u'openlp.core.lib.QtGui.QDialog') as MockedQtGuiQDialog:
|
||||
MockedQtGuiQDialog.return_value = True
|
||||
#does not work yet
|
||||
#self.form.exec_()
|
||||
self.form.item = {u'service_item': mocked_serviceitem}
|
||||
with patch(u'PyQt4.QtGui.QDialog') as mocked_exec:
|
||||
self.form.exec_()
|
||||
okWidget = self.form.buttonBox.button(self.form.buttonBox.Ok)
|
||||
QtTest.QTest.mouseClick(okWidget, QtCore.Qt.LeftButton)
|
||||
|
||||
# THEN the following values are returned
|
||||
# THEN the following input values values are returned
|
||||
self.assertEqual(self.form.hourSpinBox.value(), 0)
|
||||
self.assertEqual(self.form.minuteSpinBox.value(), 0)
|
||||
self.assertEqual(self.form.secondSpinBox.value(), 0)
|
||||
self.assertEqual(self.form.minuteSpinBox.value(), 1)
|
||||
self.assertEqual(self.form.secondSpinBox.value(), 1)
|
||||
self.assertEqual(self.form.item[u'service_item'].start_time, 61, u'The start time has not changed')
|
||||
|
||||
# WHEN displaying the UI, changing the time to 2min 3secs and pressing enter
|
||||
self.form.item = {u'service_item': mocked_serviceitem}
|
||||
with patch(u'PyQt4.QtGui.QDialog') as mocked_exec:
|
||||
self.form.exec_()
|
||||
self.form.minuteSpinBox.setValue(2)
|
||||
self.form.secondSpinBox.setValue(3)
|
||||
okWidget = self.form.buttonBox.button(self.form.buttonBox.Ok)
|
||||
QtTest.QTest.mouseClick(okWidget, QtCore.Qt.LeftButton)
|
||||
|
||||
# THEN the following values values are returned
|
||||
self.assertEqual(self.form.hourSpinBox.value(), 0)
|
||||
self.assertEqual(self.form.minuteSpinBox.value(), 2)
|
||||
self.assertEqual(self.form.secondSpinBox.value(), 3)
|
||||
self.assertEqual(self.form.item[u'service_item'].start_time, 123, u'The start time has changed')
|
Loading…
Reference in New Issue
Block a user