openlp/tests/functional/openlp_core/test_init.py

158 lines
7.5 KiB
Python
Raw Normal View History

2015-10-15 18:06:16 +00:00
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2016-12-31 11:01:36 +00:00
# Copyright (c) 2008-2017 OpenLP Developers #
2015-10-15 18:06:16 +00:00
# --------------------------------------------------------------------------- #
# 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 #
###############################################################################
import sys
from unittest import TestCase
2017-03-10 05:42:38 +00:00
from unittest.mock import MagicMock, patch
2015-10-15 18:06:16 +00:00
from openlp.core import parse_options
2017-03-10 05:42:38 +00:00
class TestInitFunctions(TestCase):
2015-10-15 18:06:16 +00:00
2016-05-31 21:40:13 +00:00
def test_parse_options_basic(self):
2015-10-15 18:06:16 +00:00
"""
2015-10-16 16:17:38 +00:00
Test the parse options process works
2015-10-15 18:06:16 +00:00
"""
# GIVEN: a a set of system arguments.
sys.argv[1:] = []
# WHEN: We we parse them to expand to options
2016-03-31 16:24:44 +00:00
args = parse_options(None)
2015-10-15 18:06:16 +00:00
# THEN: the following fields will have been extracted.
self.assertFalse(args.dev_version, 'The dev_version flag should be False')
self.assertEquals(args.loglevel, 'warning', 'The log level should be set to warning')
self.assertFalse(args.no_error_form, 'The no_error_form should be set to False')
self.assertFalse(args.portable, 'The portable flag should be set to false')
2015-12-17 21:43:49 +00:00
self.assertEquals(args.style, None, 'There are no style flags to be processed')
2015-10-15 18:06:16 +00:00
self.assertEquals(args.rargs, [], 'The service file should be blank')
2016-05-31 21:40:13 +00:00
def test_parse_options_debug(self):
2015-10-15 18:06:16 +00:00
"""
Test the parse options process works for debug only
"""
# GIVEN: a a set of system arguments.
sys.argv[1:] = ['-l debug']
# WHEN: We we parse them to expand to options
2016-03-31 16:24:44 +00:00
args = parse_options(None)
2015-10-15 18:06:16 +00:00
# THEN: the following fields will have been extracted.
self.assertFalse(args.dev_version, 'The dev_version flag should be False')
self.assertEquals(args.loglevel, ' debug', 'The log level should be set to debug')
self.assertFalse(args.no_error_form, 'The no_error_form should be set to False')
self.assertFalse(args.portable, 'The portable flag should be set to false')
2015-12-17 21:43:49 +00:00
self.assertEquals(args.style, None, 'There are no style flags to be processed')
2015-10-15 18:06:16 +00:00
self.assertEquals(args.rargs, [], 'The service file should be blank')
2016-05-31 21:40:13 +00:00
def test_parse_options_debug_and_portable(self):
2015-10-15 18:06:16 +00:00
"""
Test the parse options process works for debug and portable
"""
# GIVEN: a a set of system arguments.
sys.argv[1:] = ['--portable']
# WHEN: We we parse them to expand to options
2016-03-31 16:24:44 +00:00
args = parse_options(None)
2015-10-15 18:06:16 +00:00
# THEN: the following fields will have been extracted.
self.assertFalse(args.dev_version, 'The dev_version flag should be False')
self.assertEquals(args.loglevel, 'warning', 'The log level should be set to warning')
self.assertFalse(args.no_error_form, 'The no_error_form should be set to False')
self.assertTrue(args.portable, 'The portable flag should be set to true')
2015-12-17 21:43:49 +00:00
self.assertEquals(args.style, None, 'There are no style flags to be processed')
2015-10-15 18:06:16 +00:00
self.assertEquals(args.rargs, [], 'The service file should be blank')
2016-05-31 21:40:13 +00:00
def test_parse_options_all_no_file(self):
2015-10-15 18:06:16 +00:00
"""
Test the parse options process works with two options
"""
# GIVEN: a a set of system arguments.
sys.argv[1:] = ['-l debug', '-d']
# WHEN: We we parse them to expand to options
2016-03-31 16:24:44 +00:00
args = parse_options(None)
2015-10-15 18:06:16 +00:00
# THEN: the following fields will have been extracted.
self.assertTrue(args.dev_version, 'The dev_version flag should be True')
self.assertEquals(args.loglevel, ' debug', 'The log level should be set to debug')
self.assertFalse(args.no_error_form, 'The no_error_form should be set to False')
self.assertFalse(args.portable, 'The portable flag should be set to false')
2015-12-17 21:43:49 +00:00
self.assertEquals(args.style, None, 'There are no style flags to be processed')
2015-10-15 18:06:16 +00:00
self.assertEquals(args.rargs, [], 'The service file should be blank')
2016-05-31 21:40:13 +00:00
def test_parse_options_file(self):
2015-10-15 18:06:16 +00:00
"""
Test the parse options process works with a file
"""
# GIVEN: a a set of system arguments.
sys.argv[1:] = ['dummy_temp']
# WHEN: We we parse them to expand to options
2016-03-31 16:24:44 +00:00
args = parse_options(None)
2015-10-15 18:06:16 +00:00
# THEN: the following fields will have been extracted.
self.assertFalse(args.dev_version, 'The dev_version flag should be False')
self.assertEquals(args.loglevel, 'warning', 'The log level should be set to warning')
self.assertFalse(args.no_error_form, 'The no_error_form should be set to False')
self.assertFalse(args.portable, 'The portable flag should be set to false')
2015-12-17 21:43:49 +00:00
self.assertEquals(args.style, None, 'There are no style flags to be processed')
2015-10-15 18:06:16 +00:00
self.assertEquals(args.rargs, 'dummy_temp', 'The service file should not be blank')
2016-05-31 21:40:13 +00:00
def test_parse_options_file_and_debug(self):
2015-10-15 18:06:16 +00:00
"""
2017-03-10 05:42:38 +00:00
Test the parse options process works with a file and the debug log level
2015-10-15 18:06:16 +00:00
"""
# GIVEN: a a set of system arguments.
sys.argv[1:] = ['-l debug', 'dummy_temp']
# WHEN: We we parse them to expand to options
2016-03-31 16:24:44 +00:00
args = parse_options(None)
2015-10-15 18:06:16 +00:00
# THEN: the following fields will have been extracted.
self.assertFalse(args.dev_version, 'The dev_version flag should be False')
self.assertEquals(args.loglevel, ' debug', 'The log level should be set to debug')
self.assertFalse(args.no_error_form, 'The no_error_form should be set to False')
self.assertFalse(args.portable, 'The portable flag should be set to false')
2015-12-17 21:43:49 +00:00
self.assertEquals(args.style, None, 'There are no style flags to be processed')
2015-10-15 18:06:16 +00:00
self.assertEquals(args.rargs, 'dummy_temp', 'The service file should not be blank')
2017-03-10 05:42:38 +00:00
class TestOpenLP(TestCase):
"""
Test the OpenLP app class
"""
@patch('openlp.core.QtWidgets.QApplication.exec')
def test_exec(self, mocked_exec):
"""
Test the exec method
"""
# GIVEN: An app
app = OpenLP([])
app.shared_memory = MagicMock()
mocked_exec.return_value = False
# WHEN: exec() is called
result = app.exec()
# THEN: The right things should be called
assert app.is_event_loop_active is True
mocked_exec.assert_called_once_with()
app.shared_memory.detach.assert_called_once_with()
assert result is False
del app