forked from openlp/openlp
Add test
This commit is contained in:
parent
d6b8cd1d2a
commit
833c6fb800
@ -269,6 +269,29 @@ class OpenLP(OpenLPMixin, QtGui.QApplication):
|
|||||||
else:
|
else:
|
||||||
return QtGui.QApplication.event(self, event)
|
return QtGui.QApplication.event(self, event)
|
||||||
|
|
||||||
|
def parse_options(args):
|
||||||
|
"""
|
||||||
|
Parse the command line arguments
|
||||||
|
|
||||||
|
:param args: list of command line arguments
|
||||||
|
:return: a tuple of parsed options of type optparse.Value and a list of remaining argsZ
|
||||||
|
"""
|
||||||
|
print(args)
|
||||||
|
print(sys.argv)
|
||||||
|
# Set up command line options.
|
||||||
|
usage = 'Usage: %prog [options] [qt-options]'
|
||||||
|
parser = OptionParser(usage=usage)
|
||||||
|
parser.add_option('-e', '--no-error-form', dest='no_error_form', action='store_true',
|
||||||
|
help='Disable the error notification form.')
|
||||||
|
parser.add_option('-l', '--log-level', dest='loglevel', default='warning', metavar='LEVEL',
|
||||||
|
help='Set logging to LEVEL level. Valid values are "debug", "info", "warning".')
|
||||||
|
parser.add_option('-p', '--portable', dest='portable', action='store_true',
|
||||||
|
help='Specify if this should be run as a portable app, off a USB flash drive (not implemented).')
|
||||||
|
parser.add_option('-d', '--dev-version', dest='dev_version', action='store_true',
|
||||||
|
help='Ignore the version file and pull the version directly from Bazaar')
|
||||||
|
parser.add_option('-s', '--style', dest='style', help='Set the Qt4 style (passed directly to Qt4).')
|
||||||
|
# Parse command line options and deal with them. Use args supplied pragmatically if possible.
|
||||||
|
return parser.parse_args(args) if args else parser.parse_args()
|
||||||
|
|
||||||
def set_up_logging(log_path):
|
def set_up_logging(log_path):
|
||||||
"""
|
"""
|
||||||
@ -291,21 +314,7 @@ def main(args=None):
|
|||||||
|
|
||||||
:param args: Some args
|
:param args: Some args
|
||||||
"""
|
"""
|
||||||
# Set up command line options.
|
(options, args) = parse_options(args)
|
||||||
usage = 'Usage: %prog [options] [qt-options]'
|
|
||||||
parser = OptionParser(usage=usage)
|
|
||||||
parser.add_option('-e', '--no-error-form', dest='no_error_form', action='store_true',
|
|
||||||
help='Disable the error notification form.')
|
|
||||||
parser.add_option('-l', '--log-level', dest='loglevel', default='warning', metavar='LEVEL',
|
|
||||||
help='Set logging to LEVEL level. Valid values are "debug", "info", "warning".')
|
|
||||||
parser.add_option('-p', '--portable', dest='portable', action='store_true',
|
|
||||||
help='Specify if this should be run as a portable app, off a USB flash drive (not implemented).')
|
|
||||||
parser.add_option('-d', '--dev-version', dest='dev_version', action='store_true',
|
|
||||||
help='Ignore the version file and pull the version directly from Bazaar')
|
|
||||||
parser.add_option('-s', '--style', dest='style', help='Set the Qt4 style (passed directly to Qt4).')
|
|
||||||
# Parse command line options and deal with them.
|
|
||||||
# Use args supplied pragmatically if possible.
|
|
||||||
(options, args) = parser.parse_args(args) if args else parser.parse_args()
|
|
||||||
qt_args = []
|
qt_args = []
|
||||||
if options.loglevel.lower() in ['d', 'debug']:
|
if options.loglevel.lower() in ['d', 'debug']:
|
||||||
log.setLevel(logging.DEBUG)
|
log.setLevel(logging.DEBUG)
|
||||||
|
@ -146,6 +146,7 @@ class PresentationPlugin(Plugin):
|
|||||||
"""
|
"""
|
||||||
Perform tasks on application startup.
|
Perform tasks on application startup.
|
||||||
"""
|
"""
|
||||||
|
# TODO: Can be removed when the upgrade path from 2.0.x to 2.2.x is no longer needed
|
||||||
super().app_startup()
|
super().app_startup()
|
||||||
files_from_config = Settings().value('presentations/presentations files')
|
files_from_config = Settings().value('presentations/presentations files')
|
||||||
for file in files_from_config:
|
for file in files_from_config:
|
||||||
|
@ -29,13 +29,14 @@
|
|||||||
"""
|
"""
|
||||||
Package to test the openlp.core.__init__ package.
|
Package to test the openlp.core.__init__ package.
|
||||||
"""
|
"""
|
||||||
|
from optparse import Values
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
|
|
||||||
from openlp.core import OpenLP
|
from openlp.core import OpenLP, parse_options
|
||||||
from openlp.core.common import Settings
|
from openlp.core.common import Settings
|
||||||
from tests.helpers.testmixin import TestMixin
|
from tests.helpers.testmixin import TestMixin
|
||||||
|
|
||||||
@ -119,3 +120,17 @@ class TestInit(TestCase, TestMixin):
|
|||||||
# THEN: It should ask if we want to create a backup
|
# THEN: It should ask if we want to create a backup
|
||||||
self.assertEqual(Settings().value('core/application version'), '2.2.0', 'Version should be upgraded!')
|
self.assertEqual(Settings().value('core/application version'), '2.2.0', 'Version should be upgraded!')
|
||||||
self.assertEqual(mocked_question.call_count, 1, 'A question should have been asked!')
|
self.assertEqual(mocked_question.call_count, 1, 'A question should have been asked!')
|
||||||
|
|
||||||
|
def parse_options_short_options_test(self):
|
||||||
|
"""
|
||||||
|
Test that parse_options parses short options correctly
|
||||||
|
"""
|
||||||
|
# GIVEN: A list of vaild short options
|
||||||
|
options = ['-e', 'extra', '-l', 'debug', 'qt', '-pd', 'args', '-s', 'style']
|
||||||
|
|
||||||
|
# WHEN: Calling parse_options
|
||||||
|
resluts = parse_options(options)
|
||||||
|
|
||||||
|
# THEN: A tuple should be returned with the parsed options and left over args
|
||||||
|
self.assertEqual(resluts, (Values({'no_error_form': True, 'dev_version': True, 'portable': True,
|
||||||
|
'style': 'style', 'loglevel': 'debug'}),['extra', 'qt', 'args']))
|
||||||
|
Loading…
Reference in New Issue
Block a user