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
|
|
|
|
|
|
|
|
from openlp.core import parse_options
|
|
|
|
from tests.helpers.testmixin import TestMixin
|
|
|
|
|
|
|
|
|
|
|
|
class TestInitFunctions(TestMixin, TestCase):
|
|
|
|
|
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
|
|
|
"""
|
|
|
|
Test the parse options process works with a file
|
|
|
|
|
|
|
|
"""
|
|
|
|
# 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')
|