Update test coverage
This commit is contained in:
@@ -192,10 +192,7 @@ class NWStatus:
|
||||
def refreshIcons(self) -> None:
|
||||
"""Refresh all icons."""
|
||||
for entry in self._store.values():
|
||||
if entry.theme != CUSTOM_COL:
|
||||
print("<", entry.color.name(QColor.NameFormat.HexRgb))
|
||||
entry.color = SHARED.theme.parseColor(entry.theme)
|
||||
print(">", entry.color.name(QColor.NameFormat.HexRgb))
|
||||
entry.color = SHARED.theme.parseColor(entry.theme)
|
||||
entry.icon = NWStatus.createIcon(self._height, entry.color, entry.shape)
|
||||
return
|
||||
|
||||
|
||||
+15
-1
@@ -34,6 +34,8 @@ from PyQt6.QtWidgets import QMessageBox
|
||||
sys.path.insert(1, str(Path(__file__).parent.parent.absolute()))
|
||||
|
||||
from novelwriter import CONFIG, SHARED
|
||||
from novelwriter.config import DEF_GUI_DARK, DEF_GUI_LIGHT
|
||||
from novelwriter.enum import nwTheme
|
||||
|
||||
from tests.mocked import MockGuiMain
|
||||
from tests.tools import cleanProject
|
||||
@@ -60,6 +62,10 @@ def resetConfigVars():
|
||||
CONFIG._dLocale = QLocale("en_GB")
|
||||
CONFIG._manuals = {"manual": _TMP_ROOT / "manual.pdf"}
|
||||
CONFIG.guiLocale = "en_GB"
|
||||
CONFIG.darkTheme = DEF_GUI_DARK
|
||||
CONFIG.lightTheme = DEF_GUI_LIGHT
|
||||
CONFIG.themeMode = nwTheme.LIGHT
|
||||
CONFIG.emphLabels = True # Ensures better coverage, off by default
|
||||
return
|
||||
|
||||
|
||||
@@ -157,13 +163,21 @@ def mockGUI(qtbot, monkeypatch):
|
||||
monkeypatch.setattr(QMessageBox, "result", lambda *a: QMessageBox.StandardButton.Yes)
|
||||
gui = MockGuiMain()
|
||||
theme = GuiTheme()
|
||||
theme.loadTheme()
|
||||
monkeypatch.setattr(SHARED, "_gui", gui)
|
||||
monkeypatch.setattr(SHARED, "_theme", theme)
|
||||
|
||||
return gui
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def mockGUIwithTheme(mockGUI):
|
||||
"""Create a mock instance of novelWriter's main GUI class with the
|
||||
theme instance initialised.
|
||||
"""
|
||||
SHARED.theme.initThemes()
|
||||
return mockGUI
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def nwGUI(qtbot, monkeypatch, functionFixture):
|
||||
"""Create an instance of the novelWriter GUI."""
|
||||
|
||||
@@ -324,13 +324,32 @@ def testCoreStatus_Entries(mockGUI, mockRnd):
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreStatus_Pack(mockGUI, mockRnd):
|
||||
def testCoreStatus_RefreshIcons(mockGUIwithTheme, mockRnd):
|
||||
"""Test refreshing the icons of the NWStatus class."""
|
||||
nStatus = NWStatus(NWStatus.STATUS)
|
||||
nStatus.add(None, "New", "default", "SQUARE", 0)
|
||||
nStatus.add(None, "Note", "red", "CIRCLE", 0)
|
||||
nStatus.add(None, "Draft", "yellow", "SQUARE", 0)
|
||||
nStatus.add(None, "Finished", "green", "SQUARE", 0)
|
||||
|
||||
beforeIcons = [nStatus[statusKeys[i]].icon for i in range(4)]
|
||||
|
||||
# Refreshing the icons should generate new ones
|
||||
nStatus.refreshIcons()
|
||||
afterIcons = [nStatus[statusKeys[i]].icon for i in range(4)]
|
||||
|
||||
for before, after in zip(beforeIcons, afterIcons, strict=False):
|
||||
assert before is not after
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreStatus_Pack(mockGUIwithTheme, mockRnd):
|
||||
"""Test data packing of the NWStatus class."""
|
||||
nStatus = NWStatus(NWStatus.STATUS)
|
||||
nStatus.add(None, "New", "#646464", "SQUARE", 0)
|
||||
nStatus.add(None, "Note", "#c83200", "CIRCLE", 0)
|
||||
nStatus.add(None, "Draft", "#c89600", "SQUARE", 0)
|
||||
nStatus.add(None, "Finished", "#32c800", "SQUARE", 0)
|
||||
nStatus.add(None, "Finished", "default", "SQUARE", 0)
|
||||
|
||||
countTo = [3, 5, 7, 9]
|
||||
for i, n in enumerate(countTo):
|
||||
@@ -360,7 +379,7 @@ def testCoreStatus_Pack(mockGUI, mockRnd):
|
||||
("Finished", {
|
||||
"key": statusKeys[3],
|
||||
"count": "9",
|
||||
"color": "#32c800",
|
||||
"color": "default",
|
||||
"shape": "SQUARE",
|
||||
}),
|
||||
]
|
||||
|
||||
@@ -196,11 +196,11 @@ def testDlgPreferences_Settings(qtbot, monkeypatch, nwGUI, fncPath, tstPaths):
|
||||
# Project View
|
||||
prefs.iconColTree.setCurrentData("faded", "default")
|
||||
prefs.iconColDocs.setChecked(True)
|
||||
prefs.emphLabels.setChecked(True)
|
||||
prefs.emphLabels.setChecked(False)
|
||||
|
||||
assert CONFIG.iconColTree == DEF_TREECOL
|
||||
assert CONFIG.iconColDocs is False
|
||||
assert CONFIG.emphLabels is False
|
||||
assert CONFIG.emphLabels is True
|
||||
|
||||
# Behaviour
|
||||
prefs.autoSaveDoc.stepUp()
|
||||
@@ -362,7 +362,7 @@ def testDlgPreferences_Settings(qtbot, monkeypatch, nwGUI, fncPath, tstPaths):
|
||||
# Project View
|
||||
assert CONFIG.iconColTree == "faded"
|
||||
assert CONFIG.iconColDocs is True
|
||||
assert CONFIG.emphLabels is True
|
||||
assert CONFIG.emphLabels is False
|
||||
|
||||
# Behaviour
|
||||
assert CONFIG.autoSaveDoc == 31
|
||||
|
||||
@@ -267,8 +267,7 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd):
|
||||
# Change some settings
|
||||
CONFIG.hideHScroll = True
|
||||
CONFIG.hideVScroll = True
|
||||
CONFIG.autoScrollPos = 80
|
||||
CONFIG.autoScroll = True
|
||||
CONFIG.autoScroll = False
|
||||
|
||||
# Add a Character File
|
||||
nwGUI._changeView(nwView.PROJECT)
|
||||
|
||||
Reference in New Issue
Block a user