Skip to content

Commit

Permalink
Testing: Use config_dialog fixture in test_change_ui_theme_and_color_…
Browse files Browse the repository at this point in the history
…scheme

This simplifies the test and also fixes an error when interacting with
other tests for Preferences.
  • Loading branch information
ccordoba12 committed Dec 9, 2021
1 parent 3e56bed commit 720b4de
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
39 changes: 21 additions & 18 deletions spyder/plugins/appearance/tests/test_confpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,45 @@
# (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')

# 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()
Expand Down
1 change: 1 addition & 0 deletions spyder/plugins/preferences/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 720b4de

Please sign in to comment.