From 2962b8dc14a3eeb63d0bf0c8fb0a4f13ca35f83c Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Fri, 16 Feb 2024 13:39:01 +0000 Subject: [PATCH] Fix more non-linux test --- appveyor.yml | 2 +- openlp/core/widgets/edits.py | 2 +- tests/openlp_core/common/test_init.py | 14 +++++++------- tests/openlp_core/test_app.py | 4 +++- tests/openlp_core/ui/test_mainwindow.py | 7 ++++++- tests/openlp_core/widgets/test_edits.py | 6 +++--- 6 files changed, 21 insertions(+), 14 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index a471385c0..6fc3c2ba5 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -51,7 +51,7 @@ test_script: cd $env:APPVEYOR_BUILD_FOLDER # Run the tests python -m pytest tests - if ($? -eq $False) { + if ($LastExitCode -ne 0) { throw "The tests failed!" } # Go back to the user root folder diff --git a/openlp/core/widgets/edits.py b/openlp/core/widgets/edits.py index 6246f6a28..b9d74b81a 100644 --- a/openlp/core/widgets/edits.py +++ b/openlp/core/widgets/edits.py @@ -266,7 +266,7 @@ class PathEdit(QtWidgets.QWidget): """ if path: self._path = Path(path) - text = path_to_str(path) + text = path_to_str(self._path) self.line_edit.setText(text) self.line_edit.setToolTip(text) diff --git a/tests/openlp_core/common/test_init.py b/tests/openlp_core/common/test_init.py index 74085c5d8..20a6aa2cc 100644 --- a/tests/openlp_core/common/test_init.py +++ b/tests/openlp_core/common/test_init.py @@ -50,6 +50,12 @@ ip6_link_local = 'fe80::223:14ff:fe99:d315' ip6_bad = 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' +if is_win(): + p_prefix = 'C:\\' +else: + p_prefix = '/' + + def test_extension_loader_no_files_found(): """ Test the `extension_loader` function when no files are found @@ -91,12 +97,6 @@ def test_extension_loader_files_found(): assert "/app/dir/community" not in sys.path, "Community path has been added to the application sys.path" -if is_win(): - p_prefix = 'C:\\' -else: - p_prefix = '/' - - def test_extension_loader_files_found_community(): """ Test the `extension_loader` function when it successfully finds and loads some files @@ -130,7 +130,7 @@ def test_extension_loader_import_error(): with patch('openlp.core.common.applocation.AppLocation.get_directory', return_value=Path(p_prefix, 'app', 'dir', 'openlp')), \ patch.object(Path, 'glob', return_value=[ - Path('/', 'app', 'dir', 'openlp', 'import_dir', 'file1.py')]), \ + Path(p_prefix, 'app', 'dir', 'openlp', 'import_dir', 'file1.py')]), \ patch('openlp.core.common.import_openlp_module', side_effect=ImportError()), \ patch('openlp.core.common.log') as mocked_logger: diff --git a/tests/openlp_core/test_app.py b/tests/openlp_core/test_app.py index 9ace5978b..915192b4c 100644 --- a/tests/openlp_core/test_app.py +++ b/tests/openlp_core/test_app.py @@ -58,7 +58,7 @@ 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.devicePixelRatio.return_value = 1.0 + mock_qapp.return_value.devicePixelRatio.return_value = 1.0 mock_warn.return_value = True openlp_instance = MagicMock() mock_openlp.return_value = openlp_instance @@ -344,6 +344,7 @@ def test_main_future_settings(mock_move: MagicMock, mock_get_path: MagicMock, mo settings.from_future = MagicMock(return_value=True) settings.version_mismatched = MagicMock(return_value=True) settings.clear = MagicMock() + settings.upgrade_settings = MagicMock() settings.setValue('core/application version', '3.0.1') mock_warn.return_value = QtWidgets.QMessageBox.Yes MOCKED_VERSION = { @@ -362,6 +363,7 @@ def test_main_future_settings(mock_move: MagicMock, mock_get_path: MagicMock, mo assert result is True mock_move.assert_called_once() settings.clear.assert_called_once_with() + settings.upgrade_settings.assert_called_once_with() mock_warn.assert_called_once() diff --git a/tests/openlp_core/ui/test_mainwindow.py b/tests/openlp_core/ui/test_mainwindow.py index 21dab9b9b..fea199928 100644 --- a/tests/openlp_core/ui/test_mainwindow.py +++ b/tests/openlp_core/ui/test_mainwindow.py @@ -97,6 +97,7 @@ def main_window_reduced(settings, state): # Mock classes and methods used by mainwindow. with patch('openlp.core.ui.mainwindow.SettingsForm'), \ patch('openlp.core.ui.mainwindow.OpenLPDockWidget'), \ + patch('openlp.core.ui.mainwindow.QtCore.QTimer.singleShot'), \ patch('openlp.core.ui.mainwindow.QtWidgets.QToolBox'), \ patch('openlp.core.ui.mainwindow.QtWidgets.QMainWindow.addDockWidget'), \ patch('openlp.core.ui.mainwindow.ServiceManager'), \ @@ -757,8 +758,10 @@ def test_load_settings_view_mode_live(mocked_view_mode, main_window, settings): mocked_view_mode.assert_called_with(True, True, True, True, False, True) +@patch('openlp.core.ui.mainwindow.QtCore.QTimer.singleShot') @patch('openlp.core.ui.mainwindow.QtWidgets.QMessageBox.information') -def test_screen_changed_modal(mocked_information: MagicMock, main_window: MainWindow): +def test_screen_changed_modal(mocked_information: MagicMock, mocked_timer_singleshot: MagicMock, + main_window: MainWindow): """ Test that the screen changed modal is shown whether a 'config_screen_changed' event is dispatched """ @@ -774,8 +777,10 @@ def test_screen_changed_modal(mocked_information: MagicMock, main_window: MainWi mocked_information.assert_called_once() +@patch('openlp.core.ui.mainwindow.QtCore.QTimer.singleShot') @patch('openlp.core.ui.mainwindow.QtWidgets.QMessageBox.information') def test_screen_changed_modal_sets_timestamp_after_blocking_on_modal(mocked_information: MagicMock, + mocked_timer_singleshot: MagicMock, main_window: MainWindow): """ Test that the screen changed modal latest shown timestamp is set after showing warning message, so diff --git a/tests/openlp_core/widgets/test_edits.py b/tests/openlp_core/widgets/test_edits.py index 2676805dc..c9df98844 100755 --- a/tests/openlp_core/widgets/test_edits.py +++ b/tests/openlp_core/widgets/test_edits.py @@ -21,7 +21,6 @@ """ This module contains tests for the openlp.core.widgets.edits module """ -import os import pytest from pathlib import Path from unittest.mock import MagicMock, PropertyMock, patch, call @@ -29,6 +28,7 @@ from typing import Any from PyQt5 import QtCore, QtGui, QtTest, QtWidgets +from openlp.core.common.path import path_to_str from openlp.core.common.platform import is_win from openlp.core.common.registry import Registry from openlp.core.widgets.dialogs import FileDialog @@ -89,7 +89,7 @@ def test_path_getter(path_edit: PathEdit): if is_win(): - p_prefix = 'C:/' + p_prefix = 'C:\\' else: p_prefix = '' @@ -113,7 +113,7 @@ def test_path_setter(prop: Any, expected: Any, path_edit: PathEdit): # should have also been set. if expected is not None: assert path_edit._path == Path(*expected) - os_normalised_str = os.path.join(*expected) + os_normalised_str = path_to_str(Path(*expected)) path_edit.line_edit.setToolTip.assert_called_once_with(os_normalised_str) path_edit.line_edit.setText.assert_called_once_with(os_normalised_str) else: