openlp/tests/functional/openlp_core_lib/test_screen.py

81 lines
3.4 KiB
Python

# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2015 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 #
###############################################################################
"""
Package to test the openlp.core.lib.screenlist package.
"""
from unittest import TestCase
from PyQt4 import QtGui, QtCore
from openlp.core.common import Registry
from openlp.core.lib import ScreenList
from tests.functional import MagicMock
SCREEN = {
'primary': False,
'number': 1,
'size': QtCore.QRect(0, 0, 1024, 768)
}
class TestScreenList(TestCase):
def setUp(self):
"""
Set up the components need for all tests.
"""
# Mocked out desktop object
self.desktop = MagicMock()
self.desktop.primaryScreen.return_value = SCREEN['primary']
self.desktop.screenCount.return_value = SCREEN['number']
self.desktop.screenGeometry.return_value = SCREEN['size']
self.application = QtGui.QApplication.instance()
Registry.create()
self.application.setOrganizationName('OpenLP-tests')
self.application.setOrganizationDomain('openlp.org')
self.screens = ScreenList.create(self.desktop)
def tearDown(self):
"""
Delete QApplication.
"""
del self.screens
del self.application
def add_desktop_test(self):
"""
Test the ScreenList.screen_count_changed method to check if new monitors are detected by OpenLP.
"""
# 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['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)
self.assertEqual(old_screen_count + 1, new_screen_count, 'The new_screens list should be bigger')
self.assertEqual(SCREEN, self.screens.screen_list.pop(),
'The 2nd screen should be identical to the first screen')