openlp/tests/functional/openlp_core_lib/test_screen.py

60 lines
1.9 KiB
Python
Raw Normal View History

2013-02-16 10:28:37 +00:00
"""
Package to test the openlp.core.lib.screenlist package.
"""
2013-02-16 12:27:13 +00:00
import copy
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 = {
u'primary': False,
u'number': 1,
u'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()
self.desktop.primaryScreen.return_value = SCREEN[u'primary']
self.desktop.screenCount.return_value = SCREEN[u'number']
self.desktop.screenGeometry.return_value = SCREEN[u'size']
self.application = QtGui.QApplication.instance()
2013-02-17 07:54:43 +00:00
Registry.create()
self.application.setOrganizationName(u'OpenLP-tests')
self.application.setOrganizationDomain(u'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
self.desktop.screenCount.return_value = SCREEN[u'number'] + 1
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)
assert old_screen_count + 1 == new_screen_count, u'The new_screens list should be bigger'
assert SCREEN == self.screens.screen_list.pop(), u'The 2nd screen should be identical to the first screen'