openlp/tests/functional/openlp_core_lib/test_screen.py

60 lines
1.8 KiB
Python
Raw Normal View History

2013-02-16 10:28:37 +00:00
"""
Package to test the openlp.core.lib.screenlist package.
"""
2013-04-23 19:08:07 +00:00
2013-02-16 10:28:37 +00:00
from unittest import TestCase
2013-02-16 12:42:25 +00:00
from mock import MagicMock
2013-02-16 12:33:54 +00:00
from PyQt4 import QtGui, QtCore
2013-02-16 10:28:37 +00:00
2013-02-17 07:54:43 +00:00
from openlp.core.lib import Registry, ScreenList
2013-02-16 10:28:37 +00:00
SCREEN = {
2013-08-31 18:17:38 +00:00
'primary': False,
'number': 1,
'size': QtCore.QRect(0, 0, 1024, 768)
}
2013-02-16 12:27:13 +00:00
class TestScreenList(TestCase):
2013-02-16 10:28:37 +00:00
def setUp(self):
"""
Set up the components need for all tests.
"""
2013-03-07 12:34:35 +00:00
# Mocked out desktop object
self.desktop = MagicMock()
2013-08-31 18:17:38 +00:00
self.desktop.primaryScreen.return_value = SCREEN['primary']
self.desktop.screenCount.return_value = SCREEN['number']
self.desktop.screenGeometry.return_value = SCREEN['size']
2013-03-07 12:34:35 +00:00
self.application = QtGui.QApplication.instance()
2013-02-17 07:54:43 +00:00
Registry.create()
2013-08-31 18:17:38 +00:00
self.application.setOrganizationName('OpenLP-tests')
self.application.setOrganizationDomain('openlp.org')
2013-03-07 12:34:35 +00:00
self.screens = ScreenList.create(self.desktop)
2013-02-16 10:28:37 +00:00
2013-02-16 15:02:19 +00:00
def tearDown(self):
"""
Delete QApplication.
2013-02-16 15:02:19 +00:00
"""
2013-02-17 07:54:43 +00:00
del self.screens
2013-02-16 15:02:19 +00:00
del self.application
2013-02-16 10:28:37 +00:00
def add_desktop_test(self):
"""
2013-03-07 12:34:35 +00:00
Test the ScreenList.screen_count_changed method to check if new monitors are detected by OpenLP.
2013-02-16 10:28:37 +00:00
"""
2013-03-07 12:34:35 +00:00
# GIVEN: The screen list at its current size
old_screen_count = len(self.screens.screen_list)
# WHEN: We add a new screen
2013-08-31 18:17:38 +00:00
self.desktop.screenCount.return_value = SCREEN['number'] + 1
2013-03-07 12:34:35 +00:00
self.screens.screen_count_changed(old_screen_count)
# THEN: The screen should have been added and the screens should be identical
new_screen_count = len(self.screens.screen_list)
2013-08-31 18:17:38 +00:00
assert old_screen_count + 1 == new_screen_count, 'The new_screens list should be bigger'
assert SCREEN == self.screens.screen_list.pop(), 'The 2nd screen should be identical to the first screen'