openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #19424
[Merge] lp:~trb143/openlp/tests_only into lp:openlp
Tim Bentley has proposed merging lp:~trb143/openlp/tests_only into lp:openlp.
Requested reviews:
Andreas Preikschat (googol)
For more details, see:
https://code.launchpad.net/~trb143/openlp/tests_only/+merge/148928
More tests for the Service Item.
Fix the tests framework so it works on Jenkins
--
https://code.launchpad.net/~trb143/openlp/tests_only/+merge/148928
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/core/lib/serviceitem.py'
--- openlp/core/lib/serviceitem.py 2013-02-05 08:05:28 +0000
+++ openlp/core/lib/serviceitem.py 2013-02-17 08:00:29 +0000
@@ -634,7 +634,7 @@
"""
self.is_valid = True
for frame in self._raw_frames:
- if self.is_image() and not os.path.exists((frame[u'path'])):
+ if self.is_image() and not os.path.exists(frame[u'path']):
self.is_valid = False
elif self.is_command():
file_name = os.path.join(frame[u'path'], frame[u'title'])
=== modified file 'openlp/core/lib/settings.py'
--- openlp/core/lib/settings.py 2013-02-10 16:05:52 +0000
+++ openlp/core/lib/settings.py 2013-02-17 08:00:29 +0000
@@ -140,6 +140,7 @@
# circular dependency.
u'general/display on monitor': True,
u'general/override position': False,
+ u'images/background color': u'#000000',
u'media/players': u'webkit',
u'media/override player': QtCore.Qt.Unchecked,
u'players/background color': u'#000000',
=== modified file 'openlp/plugins/images/imageplugin.py'
--- openlp/plugins/images/imageplugin.py 2013-02-16 09:24:06 +0000
+++ openlp/plugins/images/imageplugin.py 2013-02-17 08:00:29 +0000
@@ -37,7 +37,6 @@
log = logging.getLogger(__name__)
__default_settings__ = {
- u'images/background color': u'#000000',
u'images/images files': []
}
=== modified file 'tests/functional/__init__.py'
--- tests/functional/__init__.py 2013-02-16 15:02:19 +0000
+++ tests/functional/__init__.py 2013-02-17 08:00:29 +0000
@@ -7,7 +7,3 @@
sip.setapi(u'QUrl', 2)
sip.setapi(u'QVariant', 2)
-from PyQt4 import QtGui
-
-# Only one QApplication can be created. Use QtGui.QApplication.instance() when you need to "create" a QApplication.
-application = QtGui.QApplication([])
=== modified file 'tests/functional/openlp_core_lib/test_image_manager.py'
--- tests/functional/openlp_core_lib/test_image_manager.py 2013-02-16 15:02:19 +0000
+++ tests/functional/openlp_core_lib/test_image_manager.py 2013-02-17 08:00:29 +0000
@@ -20,7 +20,7 @@
Create the UI
"""
Registry.create()
- self.app = QtGui.QApplication.instance()
+ self.app = QtGui.QApplication([])
ScreenList.create(self.app.desktop())
self.image_manager = ImageManager()
=== modified file 'tests/functional/openlp_core_lib/test_registry.py'
--- tests/functional/openlp_core_lib/test_registry.py 2013-02-16 12:01:10 +0000
+++ tests/functional/openlp_core_lib/test_registry.py 2013-02-17 08:00:29 +0000
@@ -11,7 +11,6 @@
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'..', u'..', u'resources'))
-
class TestRegistry(TestCase):
def registry_service_test(self):
=== modified file 'tests/functional/openlp_core_lib/test_screen.py'
--- tests/functional/openlp_core_lib/test_screen.py 2013-02-16 18:14:41 +0000
+++ tests/functional/openlp_core_lib/test_screen.py 2013-02-17 08:00:29 +0000
@@ -7,7 +7,7 @@
from mock import MagicMock
from PyQt4 import QtGui, QtCore
-from openlp.core.lib import ScreenList
+from openlp.core.lib import Registry, ScreenList
SCREEN = {
@@ -23,18 +23,22 @@
"""
Set up the components need for all tests.
"""
- self.application = QtGui.QApplication.instance()
+ Registry.create()
+ self.application = QtGui.QApplication([])
+ self.application.setOrganizationName(u'OpenLP-tests')
+ self.application.setOrganizationDomain(u'openlp.org')
self.screens = ScreenList.create(self.application.desktop())
def tearDown(self):
"""
Delete QApplication.
"""
+ del self.screens
del self.application
def add_desktop_test(self):
"""
- Test the ScreenList class' screen_count_changed method to check if new monitors are detected by OpenLP.
+ Test the ScreenList class' - screen_count_changed method to check if new monitors are detected by OpenLP.
"""
# GIVEN: The screen list.
old_screens = copy.deepcopy(self.screens.screen_list)
@@ -52,4 +56,3 @@
# THEN: The screens should be identically.
assert SCREEN == new_screens.pop(), u'The new screen should be identically to the screen defined above.'
-
=== modified file 'tests/functional/openlp_core_lib/test_serviceitem.py'
--- tests/functional/openlp_core_lib/test_serviceitem.py 2013-02-16 20:42:29 +0000
+++ tests/functional/openlp_core_lib/test_serviceitem.py 2013-02-17 08:00:29 +0000
@@ -4,9 +4,9 @@
import os
import cPickle
from unittest import TestCase
-from mock import MagicMock
+from mock import MagicMock, patch
-from openlp.core.lib import ServiceItem, Registry
+from openlp.core.lib import ItemCapabilities, ServiceItem, Registry
VERSE = u'The Lord said to {r}Noah{/r}: \n'\
@@ -17,7 +17,8 @@
'{r}C{/r}{b}h{/b}{bl}i{/bl}{y}l{/y}{g}d{/g}{pk}'\
'r{/pk}{o}e{/o}{pp}n{/pp} of the Lord\n'
FOOTER = [u'Arky Arky (Unknown)', u'Public Domain', u'CCLI 123456']
-TESTPATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'..', u'..', u'resources'))
+
+TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'..', u'..', u'resources'))
class TestServiceItem(TestCase):
@@ -26,7 +27,7 @@
"""
Set up the Registry
"""
- registry = Registry.create()
+ Registry.create()
mocked_renderer = MagicMock()
mocked_renderer.format_slide.return_value = [VERSE]
Registry().register(u'renderer', mocked_renderer)
@@ -77,7 +78,7 @@
service_item.name = u'test'
# WHEN: adding image to a service item
- test_image = os.path.join(TESTPATH, u'church.jpg')
+ test_image = os.path.join(TEST_PATH, u'church.jpg')
service_item.add_from_image(test_image, u'Image Title')
# THEN: We should get back a valid service item
@@ -101,9 +102,9 @@
# THEN: We should have two parts of the service.
assert len(service) == 2, u'A saved service has two parts'
- assert service[u'header'][u'name'] == u'test' , u'A test plugin was returned'
- assert service[u'data'][0][u'title'] == u'Image Title' , u'The first title name matches the request'
- assert service[u'data'][0][u'path'] == test_image , u'The first image name matches'
+ assert service[u'header'][u'name'] == u'test', u'A test plugin was returned'
+ assert service[u'data'][0][u'title'] == u'Image Title', u'The first title name matches the request'
+ assert service[u'data'][0][u'path'] == test_image, u'The first image name matches'
assert service[u'data'][0][u'title'] != service[u'data'][1][u'title'], \
u'The individual titles should not match'
assert service[u'data'][0][u'path'] == service[u'data'][1][u'path'], u'The file paths should match'
@@ -132,8 +133,8 @@
service_item.name = u'test'
# WHEN: adding image to a service item
- test_file = os.path.join(TESTPATH, u'church.jpg')
- service_item.add_from_command(TESTPATH, u'church.jpg', test_file)
+ test_file = os.path.join(TEST_PATH, u'church.jpg')
+ service_item.add_from_command(TEST_PATH, u'church.jpg', test_file)
# THEN: We should get back a valid service item
assert service_item.is_valid is True, u'The new service item should be valid'
@@ -148,10 +149,10 @@
# THEN: We should have two parts of the service.
assert len(service) == 2, u'A saved service has two parts'
- assert service[u'header'][u'name'] == u'test' , u'A test plugin'
- assert service[u'data'][0][u'title'] == u'church.jpg' , u'The first title name '
- assert service[u'data'][0][u'path'] == TESTPATH , u'The first image name'
- assert service[u'data'][0][u'image'] == test_file , u'The first image name'
+ assert service[u'header'][u'name'] == u'test', u'A test plugin'
+ assert service[u'data'][0][u'title'] == u'church.jpg', u'The first title name '
+ assert service[u'data'][0][u'path'] == TEST_PATH, u'The first image name'
+ assert service[u'data'][0][u'image'] == test_file, u'The first image name'
# WHEN validating a service item
service_item.validate_item([u'jpg'])
@@ -171,11 +172,10 @@
"""
# GIVEN: A new service item and a mocked add icon function
service_item = ServiceItem(None)
- mocked_add_icon = MagicMock()
- service_item.add_icon = mocked_add_icon
+ service_item.add_icon = MagicMock()
# WHEN: adding a custom from a saved Service
- line = self.convert_file_service_item(u'serviceitem_custom1.osd')
+ line = self.convert_file_service_item(u'serviceitem_custom_1.osd')
service_item.set_from_service(line)
# THEN: We should get back a valid service item
@@ -183,30 +183,92 @@
assert len(service_item._display_frames) == 0, u'The service item has no display frames'
assert len(service_item.capabilities) == 5, u'There are 5 default custom item capabilities'
service_item.render(True)
- assert (service_item.get_display_title()) == u'Test Custom', u'The custom title should be correct'
+ assert service_item.get_display_title() == u'Test Custom', u'The custom title should be correct'
+ assert service_item.get_frames()[0][u'text'] == VERSE[:-1], \
+ u'The returned text matches the input, except the last line feed'
+ assert service_item.get_rendered_frame(1) == VERSE.split(u'\n', 1)[0], u'The first line has been returned'
+ assert service_item.get_frame_title(0) == u'Slide 1', u'The title of the first slide is returned'
+ assert service_item.get_frame_title(1) == u'Slide 2', u'The title of the second slide is returned'
+ assert service_item.get_frame_title(2) == u'', u'The title of the first slide is returned'
def serviceitem_load_image_from_service_test(self):
"""
Test the Service Item - adding an image from a saved service
"""
# GIVEN: A new service item and a mocked add icon function
- service_item = ServiceItem(None)
- mocked_add_icon = MagicMock()
- service_item.add_icon = mocked_add_icon
-
- # WHEN: adding a custom from a saved Service
-
- # THEN: We should get back a valid service item
- assert service_item.is_valid is True, u'The new service item should be valid'
-
+ image_name = u'image_1.jpg'
+ test_file = os.path.join(TEST_PATH, image_name)
+ frame_array = {u'path': test_file, u'title': image_name}
+
+ service_item = ServiceItem(None)
+ service_item.add_icon = MagicMock()
+
+ # WHEN: adding an image from a saved Service and mocked exists
+ line = self.convert_file_service_item(u'serviceitem_image_1.osd')
+ with patch('os.path.exists'):
+ service_item.set_from_service(line, TEST_PATH)
+
+ # THEN: We should get back a valid service item
+ assert service_item.is_valid is True, u'The new service item should be valid'
+ print service_item.get_rendered_frame(0)
+ assert service_item.get_rendered_frame(0) == test_file, u'The first frame matches the path to the image'
+ assert service_item.get_frames()[0] == frame_array, u'The return matches the frame array1'
+ assert service_item.get_frame_path(0) == test_file, u'The frame path matches the full path to the image'
+ assert service_item.get_frame_title(0) == image_name, u'The frame title matches the image name'
+ assert service_item.get_display_title() == image_name, u'The display title matches the first image name'
+ assert service_item.is_image() is True, u'This service item is an Image'
+ assert service_item.is_capable(ItemCapabilities.CanMaintain) is True, u'This service item can be Maintained'
+ assert service_item.is_capable(ItemCapabilities.CanPreview) is True, u'This service item can be Previewed'
+ assert service_item.is_capable(ItemCapabilities.CanLoop) is True, u'This service item can be made to Loop'
+ assert service_item.is_capable(ItemCapabilities.CanAppend) is True, \
+ u'This service item can have new items added'
+
+ def serviceitem_load_image_from_local_service_test(self):
+ """
+ Test the Service Item - adding an image from a saved local service
+ """
+ # GIVEN: A new service item and a mocked add icon function
+ image_name1 = u'image_1.jpg'
+ image_name2 = u'image_2.jpg'
+ test_file1 = os.path.join(u'/home/openlp', image_name1)
+ test_file2 = os.path.join(u'/home/openlp', image_name2)
+ frame_array1 = {u'path': test_file1, u'title': image_name1}
+ frame_array2 = {u'path': test_file2, u'title': image_name2}
+
+ service_item = ServiceItem(None)
+ service_item.add_icon = MagicMock()
+
+ # WHEN: adding an image from a saved Service and mocked exists
+ line = self.convert_file_service_item(u'serviceitem_image_2.osd')
+ with patch('os.path.exists'):
+ service_item.set_from_service(line)
+
+ # THEN: We should get back a valid service item
+ assert service_item.is_valid is True, u'The new service item should be valid'
+ assert service_item.get_rendered_frame(0) == test_file1, u'The first frame matches the path to the image'
+ assert service_item.get_rendered_frame(1) == test_file2, u'The Second frame matches the path to the image'
+ assert service_item.get_frames()[0] == frame_array1, u'The return matches the frame array1'
+ assert service_item.get_frames()[1] == frame_array2, u'The return matches the frame array2'
+ assert service_item.get_frame_path(0) == test_file1, u'The frame path matches the full path to the image'
+ assert service_item.get_frame_path(1) == test_file2, u'The frame path matches the full path to the image'
+ assert service_item.get_frame_title(0) == image_name1, u'The 1st frame title matches the image name'
+ assert service_item.get_frame_title(1) == image_name2, u'The 2nd frame title matches the image name'
+ assert service_item.get_display_title().lower() == service_item.name, \
+ u'The plugin name matches the display title, as there are > 1 Images'
+ assert service_item.is_image() is True, u'This service item is an image '
+ assert service_item.is_capable(ItemCapabilities.CanMaintain) is True, u'This service item can be Maintained'
+ assert service_item.is_capable(ItemCapabilities.CanPreview) is True, u'This service item can be Previewed'
+ assert service_item.is_capable(ItemCapabilities.CanLoop) is True, u'This service item can be made to Loop'
+ assert service_item.is_capable(ItemCapabilities.CanAppend) is True, \
+ u'This service item can have new items added'
def convert_file_service_item(self, name):
- service_file = os.path.join(TESTPATH, name)
+ service_file = os.path.join(TEST_PATH, name)
try:
open_file = open(service_file, u'r')
items = cPickle.load(open_file)
first_line = items[0]
- except:
+ except IOError:
first_line = u''
return first_line
=== modified file 'tests/interfaces/__init__.py'
--- tests/interfaces/__init__.py 2013-02-16 18:04:17 +0000
+++ tests/interfaces/__init__.py 2013-02-17 08:00:29 +0000
@@ -7,7 +7,3 @@
sip.setapi(u'QUrl', 2)
sip.setapi(u'QVariant', 2)
-from PyQt4 import QtGui
-
-# Only one QApplication can be created. Use QtGui.QApplication.instance() when you need to "create" a QApplication.
-application = QtGui.QApplication([])
=== modified file 'tests/interfaces/openlp_core_lib/test_pluginmanager.py'
--- tests/interfaces/openlp_core_lib/test_pluginmanager.py 2013-02-16 18:06:23 +0000
+++ tests/interfaces/openlp_core_lib/test_pluginmanager.py 2013-02-17 08:00:29 +0000
@@ -6,7 +6,7 @@
from tempfile import mkstemp
from unittest import TestCase
-from mock import MagicMock, patch
+from mock import MagicMock
from PyQt4 import QtGui
from openlp.core.lib.pluginmanager import PluginManager
@@ -26,7 +26,7 @@
Settings().set_filename(self.ini_file)
Registry.create()
Registry().register(u'service_list', MagicMock())
- self.app = QtGui.QApplication.instance()
+ self.app = QtGui.QApplication([])
self.main_window = QtGui.QMainWindow()
Registry().register(u'main_window', self.main_window)
self.plugins_dir = os.path.abspath(os.path.join(os.path.basename(__file__), u'..', u'openlp', u'plugins'))
@@ -34,6 +34,7 @@
def tearDown(self):
os.unlink(self.ini_file)
del self.app
+ del self.main_window
def find_plugins_test(self):
"""
=== modified file 'tests/interfaces/openlp_core_ui/test_filerenamedialog.py'
--- tests/interfaces/openlp_core_ui/test_filerenamedialog.py 2013-02-16 15:02:19 +0000
+++ tests/interfaces/openlp_core_ui/test_filerenamedialog.py 2013-02-17 08:00:29 +0000
@@ -14,8 +14,8 @@
"""
Create the UI
"""
- registry = Registry.create()
- self.app = QtGui.QApplication.instance()
+ Registry.create()
+ self.app = QtGui.QApplication([])
self.main_window = QtGui.QMainWindow()
Registry().register(u'main_window', self.main_window)
self.form = filerenameform.FileRenameForm()
@@ -78,6 +78,6 @@
# WHEN: 'Typing' a string containing invalid file characters.
QtTest.QTest.keyClicks(self.form.fileNameEdit, u'I/n\\v?a*l|i<d> \F[i\l]e" :N+a%me')
- # THEN: The text in the QLineEdit should be the same as the input string with the invalid chatacters filtered
+ # THEN: The text in the QLineEdit should be the same as the input string with the invalid characters filtered
# out.
self.assertEqual(self.form.fileNameEdit.text(), u'Invalid File Name')
=== modified file 'tests/interfaces/openlp_core_ui/test_servicemanager.py'
--- tests/interfaces/openlp_core_ui/test_servicemanager.py 2013-02-16 15:02:19 +0000
+++ tests/interfaces/openlp_core_ui/test_servicemanager.py 2013-02-17 08:00:29 +0000
@@ -18,7 +18,7 @@
Create the UI
"""
Registry.create()
- self.app = QtGui.QApplication.instance()
+ self.app = QtGui.QApplication([])
ScreenList.create(self.app.desktop())
Registry().register(u'application', MagicMock())
self.main_window = MainWindow()
=== modified file 'tests/interfaces/openlp_core_ui/test_servicenotedialog.py'
--- tests/interfaces/openlp_core_ui/test_servicenotedialog.py 2013-02-16 16:05:39 +0000
+++ tests/interfaces/openlp_core_ui/test_servicenotedialog.py 2013-02-17 08:00:29 +0000
@@ -17,7 +17,7 @@
Create the UI
"""
Registry.create()
- self.app = QtGui.QApplication.instance()
+ self.app = QtGui.QApplication([])
self.main_window = QtGui.QMainWindow()
Registry().register(u'main_window', self.main_window)
self.form = servicenoteform.ServiceNoteForm()
=== modified file 'tests/interfaces/openlp_core_ui/test_starttimedialog.py'
--- tests/interfaces/openlp_core_ui/test_starttimedialog.py 2013-02-16 15:02:19 +0000
+++ tests/interfaces/openlp_core_ui/test_starttimedialog.py 2013-02-17 08:00:29 +0000
@@ -17,7 +17,7 @@
Create the UI
"""
Registry.create()
- self.app = QtGui.QApplication.instance()
+ self.app = QtGui.QApplication([])
self.main_window = QtGui.QMainWindow()
Registry().register(u'main_window', self.main_window)
self.form = starttimeform.StartTimeForm()
=== renamed file 'tests/resources/serviceitem_custom1.osd' => 'tests/resources/serviceitem_custom_1.osd'
=== renamed file 'tests/resources/serviceitem_image1.osd' => 'tests/resources/serviceitem_image_1.osd'
--- tests/resources/serviceitem_image1.osd 2013-01-21 06:52:55 +0000
+++ tests/resources/serviceitem_image_1.osd 2013-02-17 08:00:29 +0000
@@ -74,6 +74,6 @@
p32
ssg15
(lp33
-VIMG_7453.JPG
+Vimage_1.jpg
p34
assa.
\ No newline at end of file
=== added file 'tests/resources/serviceitem_image_2.osd'
--- tests/resources/serviceitem_image_2.osd 1970-01-01 00:00:00 +0000
+++ tests/resources/serviceitem_image_2.osd 2013-02-17 08:00:29 +0000
@@ -0,0 +1,101 @@
+(lp1
+(dp2
+Vserviceitem
+p3
+(dp4
+Vheader
+p5
+(dp6
+Vxml_version
+p7
+NsVauto_play_slides_loop
+p8
+I00
+sVauto_play_slides_once
+p9
+I00
+sVwill_auto_start
+p10
+I00
+sVtitle
+p11
+VImages
+p12
+sVcapabilities
+p13
+(lp14
+I3
+aI1
+aI5
+aI6
+asVtheme
+p15
+I-1
+sVbackground_audio
+p16
+(lp17
+sVicon
+p18
+V:/plugins/plugin_images.png
+p19
+sVtype
+p20
+I2
+sVstart_time
+p21
+I0
+sVfrom_plugin
+p22
+I00
+sVmedia_length
+p23
+I0
+sVdata
+p24
+V
+sVtimed_slide_interval
+p25
+I0
+sVaudit
+p26
+V
+sVsearch
+p27
+V
+sVname
+p28
+Vimages
+p29
+sVfooter
+p30
+(lp31
+sVnotes
+p32
+V
+sVplugin
+p33
+g29
+sVtheme_overwritten
+p34
+I00
+sVend_time
+p35
+I0
+ssg24
+(lp36
+(dp37
+Vpath
+p38
+V/home/openlp/image_1.jpg
+p39
+sg11
+Vimage_1.jpg
+p40
+sa(dp41
+g38
+V/home/openlp/image_2.jpg
+p42
+sg11
+Vimage_2.jpg
+p43
+sassa.
\ No newline at end of file
Follow ups