openlp/tests/functional/openlp_core/display/test_screens.py

81 lines
3.4 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2017-12-29 09:15:48 +00:00
# Copyright (c) 2008-2018 OpenLP Developers #
# --------------------------------------------------------------------------- #
# This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the Free #
# Software Foundation; version 2 of the License. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
# more details. #
# #
# You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
2013-02-16 10:28:37 +00:00
"""
Package to test the openlp.core.lib.screenlist package.
"""
from unittest import TestCase
from unittest.mock import MagicMock
2013-02-16 10:28:37 +00:00
2015-11-07 00:49:40 +00:00
from PyQt5 import QtCore, QtWidgets
2013-02-16 10:28:37 +00:00
2017-10-07 07:05:07 +00:00
from openlp.core.common.registry import Registry
2017-10-10 07:08:44 +00:00
from openlp.core.display.screens import 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
2015-11-07 00:49:40 +00:00
self.application = QtWidgets.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
2016-05-31 21:40:13 +00:00
def test_add_desktop(self):
2013-02-16 10:28:37 +00:00
"""
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)
2017-12-17 14:12:27 +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'