From 720b4dea20637136a4a8401f6db30226b1b6bb89 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Thu, 9 Dec 2021 13:38:25 -0500 Subject: [PATCH] Testing: Use config_dialog fixture in test_change_ui_theme_and_color_scheme This simplifies the test and also fixes an error when interacting with other tests for Preferences. --- .../plugins/appearance/tests/test_confpage.py | 39 ++++++++++--------- spyder/plugins/preferences/tests/conftest.py | 1 + 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/spyder/plugins/appearance/tests/test_confpage.py b/spyder/plugins/appearance/tests/test_confpage.py index 8f29272a426..c011f0342c9 100644 --- a/spyder/plugins/appearance/tests/test_confpage.py +++ b/spyder/plugins/appearance/tests/test_confpage.py @@ -6,35 +6,33 @@ # (see LICENSE.txt for details) # ----------------------------------------------------------------------------- +# Third-party imports +import pytest + # Local imports from spyder.api.plugins import Plugins -from spyder.api.plugin_registration.registry import PLUGIN_REGISTRY from spyder.plugins.appearance.plugin import Appearance from spyder.plugins.preferences.api import SpyderConfigPage -from spyder.plugins.preferences.tests.conftest import MainWindowMock -from spyder.utils.stylesheet import APP_STYLESHEET +from spyder.plugins.preferences.tests.conftest import ( + config_dialog, MainWindowMock) -def test_change_ui_theme_and_color_scheme(qtbot, mocker): +@pytest.mark.parametrize( + 'config_dialog', + [[MainWindowMock, [], [Appearance]]], + indirect=True) +def test_change_ui_theme_and_color_scheme(config_dialog, mocker, qtbot): """Test that changing color scheme or UI theme works as expected.""" # Patch methods whose calls we want to check mocker.patch.object(SpyderConfigPage, "prompt_restart_required") - # Create main window - main = MainWindowMock() - main.setStyleSheet(str(APP_STYLESHEET)) - - # Register Appearance - appearance = PLUGIN_REGISTRY.register_plugin(main, Appearance) + # Get reference to main window and appearance + main = config_dialog.parent() + appearance = main.get_plugin(Plugins.Appearance) - # Create preferences page - preferences = main.get_plugin(Plugins.Preferences) - preferences.open_dialog(None) - - # Get widget page to interact with - container = preferences.get_container() - dlg = container.dialog - widget = dlg.get_page() + # Get reference to Preferences dialog and widget page to interact with + dlg = config_dialog + widget = config_dialog.get_page() # List of color schemes names = widget.get_option('names') @@ -42,6 +40,11 @@ def test_change_ui_theme_and_color_scheme(qtbot, mocker): # Assert no restarts have been requested so far. assert SpyderConfigPage.prompt_restart_required.call_count == 0 + # Assert default UI theme is 'automatic' and interface is dark. The other + # tests below depend on this. + assert appearance.get_conf('ui_theme') == 'automatic' + assert appearance._is_dark_interface + # Change to another dark color scheme widget.schemes_combobox.setCurrentIndex(names.index('monokai')) dlg.apply_btn.click() diff --git a/spyder/plugins/preferences/tests/conftest.py b/spyder/plugins/preferences/tests/conftest.py index f26d533ff4c..496b3bbad80 100644 --- a/spyder/plugins/preferences/tests/conftest.py +++ b/spyder/plugins/preferences/tests/conftest.py @@ -101,6 +101,7 @@ def get_plugin(self, plugin_name, error=False): setattr(self._main, 'set_prefs_size', types.MethodType(set_prefs_size, self._main)) + PLUGIN_REGISTRY.reset() PLUGIN_REGISTRY.sig_plugin_ready.connect(self._main.register_plugin) PLUGIN_REGISTRY.register_plugin(self._main, Preferences)