From 78c32e434cdebfbc82d5f9ac74cd5082886c835c Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Sat, 23 Mar 2024 21:43:19 -0700 Subject: [PATCH] Further fix #1871 by adding the Application name as early as possible --- openlp/core/app.py | 4 ++-- tests/openlp_core/test_app.py | 29 +++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/openlp/core/app.py b/openlp/core/app.py index 552c2e8b4..d41703b53 100644 --- a/openlp/core/app.py +++ b/openlp/core/app.py @@ -502,9 +502,11 @@ def main(): app = OpenLP() Registry.create() QtWidgets.QApplication.setOrganizationName('OpenLP') + QtWidgets.QApplication.setApplicationName('OpenLP') QtWidgets.QApplication.setOrganizationDomain('openlp.org') if args.portable: # This has to be done here so that we can load the settings before instantiating the application object + QtWidgets.QApplication.setApplicationName('OpenLPPortable') portable_path, settings = setup_portable_settings(args.portablepath) else: settings = Settings() @@ -529,7 +531,6 @@ def main(): font.setPointSizeF(font.pointSizeF() * application.devicePixelRatio()) application.setFont(font) if args.portable: - application.setApplicationName('OpenLPPortable') data_path = portable_path / 'Data' set_up_logging(portable_path / 'Other') set_up_web_engine_cache(portable_path / 'Other' / 'web_cache') @@ -540,7 +541,6 @@ def main(): settings.setValue('advanced/is portable', True) settings.sync() else: - application.setApplicationName('OpenLP') set_up_logging(AppLocation.get_directory(AppLocation.CacheDir)) set_up_web_engine_cache(AppLocation.get_directory(AppLocation.CacheDir) / 'web_cache') settings.init_default_shortcuts() diff --git a/tests/openlp_core/test_app.py b/tests/openlp_core/test_app.py index 915192b4c..10ccb41a8 100644 --- a/tests/openlp_core/test_app.py +++ b/tests/openlp_core/test_app.py @@ -19,15 +19,15 @@ # along with this program. If not, see . # ########################################################################## import sys -import pytest - +from argparse import Namespace from pathlib import Path from tempfile import mkdtemp - from unittest.mock import MagicMock, patch +import pytest from PyQt5 import QtCore, QtWidgets + # Mock QtWebEngineWidgets sys.modules['PyQt5.QtWebEngineWidgets'] = MagicMock() @@ -37,14 +37,20 @@ from openlp.core.common.settings import Settings @pytest.fixture -def app_main_env(): +def mocked_qapp(): + patcher = patch('openlp.core.app.QtWidgets.QApplication') + yield patcher.start() + patcher.stop() + + +@pytest.fixture +def app_main_env(mocked_qapp): with patch('openlp.core.app.Settings') as mock_settings, \ patch('openlp.core.app.Registry') as mock_registry, \ patch('openlp.core.app.AppLocation') as mock_apploc, \ patch('openlp.core.app.LanguageManager'), \ patch('openlp.core.app.qInitResources'), \ - patch('openlp.core.app.parse_options'), \ - patch('openlp.core.app.QtWidgets.QApplication') as mock_qapp, \ + patch('openlp.core.app.parse_options') as mocked_parse_options, \ patch('openlp.core.app.QtWidgets.QMessageBox.warning') as mock_warn, \ patch('openlp.core.app.QtWidgets.QMessageBox.information'), \ patch('openlp.core.app.OpenLP') as mock_openlp, \ @@ -58,7 +64,10 @@ def app_main_env(): openlp_server.is_another_instance_running.return_value = False mock_apploc.get_data_path.return_value = Path() mock_apploc.get_directory.return_value = Path() - mock_qapp.return_value.devicePixelRatio.return_value = 1.0 + mocked_parse_options.return_value = Namespace(no_error_form=False, loglevel='warning', portable=False, + portablepath=None, no_web_server=False, display_custom_path=None, + rargs=[]) + mocked_qapp.return_value.devicePixelRatio.return_value = 1.0 mock_warn.return_value = True openlp_instance = MagicMock() mock_openlp.return_value = openlp_instance @@ -311,7 +320,8 @@ def test_backup_on_upgrade(mocked_question, mocked_get_version, qapp, settings): @patch('openlp.core.app.backup_if_version_changed') @patch('openlp.core.app.set_up_web_engine_cache') @patch('openlp.core.app.set_up_logging') -def test_main(mock_logging, mock_web_cache, mock_backup, mock_sys, mock_openlp, app_main_env): +def test_main(mock_logging: MagicMock, mock_web_cache: MagicMock, mock_backup: MagicMock, mock_sys: MagicMock, + mock_openlp: MagicMock, mocked_qapp: MagicMock, app_main_env: None): """ Test the main method performs primary actions """ @@ -329,6 +339,9 @@ def test_main(mock_logging, mock_web_cache, mock_backup, mock_sys, mock_openlp, mock_logging.assert_called_once() mock_web_cache.assert_called_once() mock_sys.exit.assert_called_once() + mocked_qapp.setOrganizationName.assert_called_once_with('OpenLP') + mocked_qapp.setApplicationName.assert_called_once_with('OpenLP') + mocked_qapp.setOrganizationDomain.assert_called_once_with('openlp.org') @patch('openlp.core.app.QtWidgets.QMessageBox.warning')