fix a bit of the tests

This commit is contained in:
Tim Bentley 2018-03-29 17:25:10 +01:00
parent db0f131e15
commit fada29080c
2 changed files with 7 additions and 43 deletions

View File

@ -142,6 +142,7 @@ class OpenLP(QtWidgets.QApplication):
""" """
QtWidgets.QMessageBox.critical(None, UiStrings().Error, UiStrings().OpenLPStart, QtWidgets.QMessageBox.critical(None, UiStrings().Error, UiStrings().OpenLPStart,
QtWidgets.QMessageBox.StandardButtons(QtWidgets.QMessageBox.Ok)) QtWidgets.QMessageBox.StandardButtons(QtWidgets.QMessageBox.Ok))
@staticmethod @staticmethod
def is_data_path_missing(): def is_data_path_missing():
""" """
@ -293,8 +294,7 @@ def parse_options(args=None):
parser.add_argument('-l', '--log-level', dest='loglevel', default='warning', metavar='LEVEL', parser.add_argument('-l', '--log-level', dest='loglevel', default='warning', metavar='LEVEL',
help='Set logging to LEVEL level. Valid values are "debug", "info", "warning".') help='Set logging to LEVEL level. Valid values are "debug", "info", "warning".')
parser.add_argument('-p', '--portable', dest='portable', action='store_true', parser.add_argument('-p', '--portable', dest='portable', action='store_true',
help='Specify if this should be run as a portable app, ' help='Specify if this should be run as a portable app, ')
'off a USB flash drive (not implemented).')
parser.add_argument('-w', '--no-web-server', dest='no_web_server', action='store_true', parser.add_argument('-w', '--no-web-server', dest='no_web_server', action='store_true',
help='Turn off the Web and Socket Server ') help='Turn off the Web and Socket Server ')
parser.add_argument('rargs', nargs='?', default=[]) parser.add_argument('rargs', nargs='?', default=[])

View File

@ -138,13 +138,11 @@ class TestOpenLP(TestCase, TestMixin):
Test the OpenLP app class Test the OpenLP app class
""" """
def setUp(self): def setUp(self):
self.setup_application()
self.build_settings() self.build_settings()
# self.qapplication_patcher = patch('openlp.core.app.QtGui.QApplication')
# self.mocked_qapplication = self.qapplication_patcher.start()
self.openlp = OpenLP([]) self.openlp = OpenLP([])
def tearDown(self): def tearDown(self):
# self.qapplication_patcher.stop()
self.destroy_settings() self.destroy_settings()
del self.openlp del self.openlp
self.openlp = None self.openlp = None
@ -165,55 +163,21 @@ class TestOpenLP(TestCase, TestMixin):
self.mocked_qapplication.exec.assert_called_once_with() self.mocked_qapplication.exec.assert_called_once_with()
assert result is False assert result is False
@skip("This one fails")
@patch('openlp.core.app.QtWidgets.QMessageBox.critical') @patch('openlp.core.app.QtWidgets.QMessageBox.critical')
@patch('openlp.core.app.QtWidgets.QMessageBox.StandardButtons') @patch('openlp.core.app.QtWidgets.QMessageBox.StandardButtons')
@patch('openlp.core.app.QtCore.QSharedMemory') def test_is_already_running_is_running(self, MockedStandardButtons, mocked_critical):
def test_is_already_running_is_running_continue(self, MockedSharedMemory, MockedStandardButtons, mocked_critical):
""" """
Test the is_already_running() method when OpenLP IS running and the user chooses to continue Test the is_already_running() method when OpenLP IS running and the user chooses to continue
""" """
# GIVEN: An OpenLP app and some mocks # GIVEN: An OpenLP app and some mocks
mocked_shared_memory = MagicMock()
mocked_shared_memory.attach.return_value = True
MockedSharedMemory.return_value = mocked_shared_memory
MockedStandardButtons.return_value = 0 MockedStandardButtons.return_value = 0
mocked_critical.return_value = QtWidgets.QMessageBox.Yes mocked_critical.return_value = QtWidgets.QMessageBox.Ok
# WHEN: is_already_running() is called # WHEN: is_already_running() is called
result = self.openlp.is_already_running() self.openlp.is_already_running()
# THEN: The result should be false # THEN: The result should be false
MockedSharedMemory.assert_called_once_with('OpenLP') MockedStandardButtons.assert_called_once_with(QtWidgets.QMessageBox.Ok)
mocked_shared_memory.attach.assert_called_once_with()
MockedStandardButtons.assert_called_once_with(QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
mocked_critical.assert_called_once_with(None, 'Error', 'OpenLP is already running. Do you wish to continue?', 0)
assert result is False
@skip("This one fails")
@patch('openlp.core.app.QtWidgets.QMessageBox.critical')
@patch('openlp.core.app.QtWidgets.QMessageBox.StandardButtons')
@patch('openlp.core.app.QtCore.QSharedMemory')
def test_is_already_running_is_running_stop(self, MockedSharedMemory, MockedStandardButtons, mocked_critical):
"""
Test the is_already_running() method when OpenLP IS running and the user chooses to stop
"""
# GIVEN: An OpenLP app and some mocks
mocked_shared_memory = MagicMock()
mocked_shared_memory.attach.return_value = True
MockedSharedMemory.return_value = mocked_shared_memory
MockedStandardButtons.return_value = 0
mocked_critical.return_value = QtWidgets.QMessageBox.No
# WHEN: is_already_running() is called
result = self.openlp.is_already_running()
# THEN: The result should be false
MockedSharedMemory.assert_called_once_with('OpenLP')
mocked_shared_memory.attach.assert_called_once_with()
MockedStandardButtons.assert_called_once_with(QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
mocked_critical.assert_called_once_with(None, 'Error', 'OpenLP is already running. Do you wish to continue?', 0)
assert result is True
@skip("This one fails") @skip("This one fails")
def test_process_events(self): def test_process_events(self):