Fix tests so they work better. Pylint fixes and bug fixex

This commit is contained in:
Tim Bentley 2013-01-25 20:50:18 +00:00
parent 2491caf957
commit 96afb2a737
6 changed files with 64 additions and 32 deletions

View File

@ -438,8 +438,8 @@ class ServiceManager(QtGui.QWidget):
log.debug(temp_file_name) log.debug(temp_file_name)
path_file_name = unicode(self.fileName()) path_file_name = unicode(self.fileName())
path, file_name = os.path.split(path_file_name) path, file_name = os.path.split(path_file_name)
basename = os.path.splitext(file_name)[0] base_name = os.path.splitext(file_name)[0]
service_file_name = '%s.osd' % basename service_file_name = '%s.osd' % base_name
log.debug(u'ServiceManager.saveFile - %s', path_file_name) log.debug(u'ServiceManager.saveFile - %s', path_file_name)
Settings().setValue(self.main_window.serviceManagerSettingsSection + u'/last directory', path) Settings().setValue(self.main_window.serviceManagerSettingsSection + u'/last directory', path)
service = [] service = []
@ -667,11 +667,11 @@ class ServiceManager(QtGui.QWidget):
fileName = unicode(fileName) fileName = unicode(fileName)
if not os.path.exists(fileName): if not os.path.exists(fileName):
return False return False
zip = None zip_file = None
fileTo = None fileTo = None
try: try:
zip = zipfile.ZipFile(fileName) zip_file = zipfile.ZipFile(fileName)
for zipinfo in zip.infolist(): for zipinfo in zip_file.infolist():
try: try:
ucsfile = zipinfo.filename.decode(u'utf-8') ucsfile = zipinfo.filename.decode(u'utf-8')
except UnicodeDecodeError: except UnicodeDecodeError:
@ -684,7 +684,7 @@ class ServiceManager(QtGui.QWidget):
osfile = os.path.split(osfile)[1] osfile = os.path.split(osfile)[1]
log.debug(u'Extract file: %s', osfile) log.debug(u'Extract file: %s', osfile)
zipinfo.filename = osfile zipinfo.filename = osfile
zip.extract(zipinfo, self.servicePath) zip_file.extract(zipinfo, self.servicePath)
if osfile.endswith(u'osd'): if osfile.endswith(u'osd'):
p_file = os.path.join(self.servicePath, osfile) p_file = os.path.join(self.servicePath, osfile)
if 'p_file' in locals(): if 'p_file' in locals():
@ -737,8 +737,8 @@ class ServiceManager(QtGui.QWidget):
finally: finally:
if fileTo: if fileTo:
fileTo.close() fileTo.close()
if zip: if zip_file:
zip.close() zip_file.close()
self.main_window.finishedProgressBar() self.main_window.finishedProgressBar()
Receiver.send_message(u'cursor_normal') Receiver.send_message(u'cursor_normal')
self.repaintServiceList(-1, -1) self.repaintServiceList(-1, -1)
@ -819,6 +819,9 @@ class ServiceManager(QtGui.QWidget):
self.menu.exec_(self.serviceManagerList.mapToGlobal(point)) self.menu.exec_(self.serviceManagerList.mapToGlobal(point))
def onServiceItemNoteForm(self): def onServiceItemNoteForm(self):
"""
Allow the service note to be edited
"""
item = self.findServiceItem()[0] item = self.findServiceItem()[0]
self.serviceNoteForm.textEdit.setPlainText( self.serviceNoteForm.textEdit.setPlainText(
self.serviceItems[item][u'service_item'].notes) self.serviceItems[item][u'service_item'].notes)

View File

@ -140,7 +140,7 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog):
per save. per save.
""" """
if self.resetSuffixes: if self.resetSuffixes:
self.mainWindow.serviceManagerContents.resetSupportedSuffixes() self.service_manager.resetSupportedSuffixes()
self.resetSuffixes = False self.resetSuffixes = False
def _get_main_window(self): def _get_main_window(self):
@ -152,3 +152,13 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog):
return self._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)

View File

@ -189,10 +189,10 @@ class ImageMediaItem(MediaManagerItem):
def onResetClick(self): 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.resetAction.setVisible(False)
self.plugin.liveController.display.resetImage() self.live_controller.display.resetImage()
def liveThemeChanged(self): def liveThemeChanged(self):
""" """
@ -211,7 +211,7 @@ class ImageMediaItem(MediaManagerItem):
bitem = self.listView.item(item.row()) bitem = self.listView.item(item.row())
filename = bitem.data(QtCore.Qt.UserRole) filename = bitem.data(QtCore.Qt.UserRole)
if os.path.exists(filename): 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) self.resetAction.setVisible(True)
else: else:
critical_error_message_box(UiStrings().LiveBGError, critical_error_message_box(UiStrings().LiveBGError,

View File

@ -131,7 +131,7 @@ class MediaMediaItem(MediaManagerItem):
""" """
Called to reset the Live background with the media selected, 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) self.resetAction.setVisible(False)
def videobackgroundReplaced(self): def videobackgroundReplaced(self):
@ -154,7 +154,7 @@ class MediaMediaItem(MediaManagerItem):
service_item.shortname = service_item.title service_item.shortname = service_item.title
(path, name) = os.path.split(filename) (path, name) = os.path.split(filename)
service_item.add_from_command(path, name,CLAPPERBOARD) 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): videoBehindText=True):
self.resetAction.setVisible(True) self.resetAction.setVisible(True)
else: else:

View File

@ -13,26 +13,28 @@ class TestRegistry(TestCase):
def registry_basic_test(self): def registry_basic_test(self):
""" """
Test the Service Item basic test Test the registry creation and its usage
""" """
# GIVEN: A new registry # GIVEN: A new registry
registry = Registry.create() registry = Registry.create()
# WHEN: I add a service it should save it # WHEN: I add a component it should save it
mock_1 = MagicMock() mock_1 = MagicMock()
Registry().register(u'test1', mock_1) 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' 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. # WHEN: I add a component for the second time I am mad.
# THEN I will get an exception # THEN and I will get an exception
with self.assertRaises(KeyError) as context: with self.assertRaises(KeyError) as context:
Registry().register(u'test1', mock_1) 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 # THEN I will get an exception
with self.assertRaises(KeyError) as context: with self.assertRaises(KeyError) as context:
temp = Registry().get(u'test2') 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')

View File

@ -6,7 +6,7 @@ from unittest import TestCase
from mock import MagicMock, patch from mock import MagicMock, patch
from openlp.core.ui import starttimeform from openlp.core.ui import starttimeform
from PyQt4 import QtGui, QtTest from PyQt4 import QtCore, QtGui, QtTest
class TestStartTimeDialog(TestCase): class TestStartTimeDialog(TestCase):
@ -51,15 +51,32 @@ class TestStartTimeDialog(TestCase):
mocked_serviceitem = MagicMock() mocked_serviceitem = MagicMock()
mocked_serviceitem.start_time = 61 mocked_serviceitem.start_time = 61
mocked_serviceitem.end_time = 3701 mocked_serviceitem.end_time = 3701
mocked_serviceitem.media_length = 3701
# WHEN displaying the UI and pressing enter # WHEN displaying the UI and pressing enter
self.form.item = mocked_serviceitem self.form.item = {u'service_item': mocked_serviceitem}
with patch(u'openlp.core.lib.QtGui.QDialog') as MockedQtGuiQDialog: with patch(u'PyQt4.QtGui.QDialog') as mocked_exec:
MockedQtGuiQDialog.return_value = True self.form.exec_()
#does not work yet okWidget = self.form.buttonBox.button(self.form.buttonBox.Ok)
#self.form.exec_() 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.hourSpinBox.value(), 0)
self.assertEqual(self.form.minuteSpinBox.value(), 0) self.assertEqual(self.form.minuteSpinBox.value(), 1)
self.assertEqual(self.form.secondSpinBox.value(), 0) 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')