Add remaining missing coverage and revert loadTheme return type

This commit is contained in:
Veronica Berglyd Olsen
2025-06-03 22:47:17 +02:00
parent bd2353f7bc
commit 334f946870
3 changed files with 34 additions and 11 deletions
+6
View File
@@ -41,6 +41,7 @@ from novelwriter.common import (
readTextFile, simplified, transferCase, uniqueCompact, xmlElement,
xmlIndent, xmlSubElem, yesNo
)
from novelwriter.enum import nwItemClass
from tests.mocked import causeOSError
from tests.tools import writeFile
@@ -804,6 +805,7 @@ def testBaseCommon_NWConfigParser(fncPath):
"list1 = a, b, c\n"
"list2 = 17, 18, 19\n"
"float1 = 4.2\n"
"enum1 = NOVEL\n"
f"path1 = {fncPath}\n"
))
@@ -875,3 +877,7 @@ def testBaseCommon_NWConfigParser(fncPath):
assert cfgParser.rdIntList("nope", "list2", [1]) == [1]
assert cfgParser.rdIntList("main", "blabla", [1]) == [1]
# Read Enum
assert cfgParser.rdEnum("main", "enum1", nwItemClass.NO_CLASS) == nwItemClass.NOVEL
assert cfgParser.rdEnum("main", "blabla", nwItemClass.NO_CLASS) == nwItemClass.NO_CLASS
+20 -5
View File
@@ -24,6 +24,7 @@ import shutil
from pathlib import Path
from shutil import copyfile
from unittest.mock import Mock
import pytest
@@ -32,6 +33,7 @@ from PyQt6.QtGui import QPalette
from PyQt6.QtWidgets import QInputDialog, QMessageBox
from novelwriter import CONFIG, SHARED
from novelwriter.config import DEF_GUI_DARK, DEF_GUI_LIGHT
from novelwriter.constants import nwFiles
from novelwriter.dialogs.editlabel import GuiEditLabel
from novelwriter.enum import nwDocAction, nwDocMode, nwFocus, nwItemType, nwTheme, nwView
@@ -179,22 +181,35 @@ def testGuiMain_ProjectTreeItems(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
@pytest.mark.gui
def testGuiMain_UpdateTheme(qtbot, nwGUI):
"""Test updating the theme in the GUI."""
mainTheme = SHARED.theme
theme = SHARED.theme
CONFIG.themeMode = nwTheme.DARK
CONFIG.darkTheme = "default_dark"
CONFIG.lightTheme = "default_light"
mainTheme.loadTheme()
CONFIG.darkTheme = DEF_GUI_DARK
CONFIG.lightTheme = DEF_GUI_LIGHT
theme.loadTheme()
assert theme.isDarkTheme is True
nwGUI._processConfigChanges(False, True, False, False)
nwGUI._processConfigChanges(True, True, True, True)
# Check editor syntax
syntax = SHARED.theme.syntaxTheme
assert nwGUI.docEditor.palette().color(QPalette.ColorRole.Window) == syntax.back
assert nwGUI.docEditor.docHeader.palette().color(QPalette.ColorRole.Window) == syntax.back
assert nwGUI.docViewer.palette().color(QPalette.ColorRole.Window) == syntax.back
assert nwGUI.docViewer.docHeader.palette().color(QPalette.ColorRole.Window) == syntax.back
# Update by check
CONFIG.themeMode = nwTheme.LIGHT
nwGUI.checkThemeUpdate()
assert theme.isDarkTheme is False
# Through change event
event = Mock()
event.type.return_value = 210
CONFIG.themeMode = nwTheme.DARK
nwGUI.changeEvent(event)
assert theme.isDarkTheme is True
# qtbot.stop()