Update test coverage

This commit is contained in:
Veronica Berglyd Olsen
2026-07-18 19:45:43 +02:00
parent 9861ea7ddd
commit a65aa4d828
7 changed files with 67 additions and 11 deletions

View File

@@ -851,7 +851,9 @@ class GuiOutlineHeaderMenu(QMenu):
@pyqtSlot(bool)
def _forwardToggled(self, isChecked: bool) -> None:
"""Forward the toggled state of the sending action's column."""
if isinstance(action := self.sender(), QAction) and isinstance(tItem := action.data(), nwOutline):
if isinstance(action := self.sender(), QAction) and isinstance(
tItem := action.data(), nwOutline
): # pragma: no branch
self.columnToggled.emit(isChecked, tItem)

View File

@@ -16,11 +16,12 @@ if __name__ == "__main__":
parser = argparse.ArgumentParser(usage="run_tests.py [--flags]")
parser.add_argument("-o", action="store_true", help="Run off screen")
parser.add_argument("-r", action="store_true", help="Generate xml coverage report")
parser.add_argument("-rh", action="store_true", help="Generate html coverage report")
parser.add_argument("--html", action="store_true", help="Generate html coverage report")
parser.add_argument("-t", action="store_true", help="Generate terminal coverage report")
parser.add_argument("-u", action="store_true", help="Generate uncovered terminal report")
parser.add_argument("-lf", action="store_true", help="Re-run failed tests")
parser.add_argument("-sw", action="store_true", help="Run tests stepwise")
parser.add_argument("-l", action="store_true", help="Generate uncovered terminal report with missing lines")
parser.add_argument("--failed", action="store_true", help="Re-run failed tests")
parser.add_argument("--step", action="store_true", help="Run tests stepwise")
parser.add_argument("-m", help="Test modules", metavar="MARKEXPR")
parser.add_argument("-k", help="Test filters", metavar="EXPRESSION")
@@ -32,7 +33,7 @@ if __name__ == "__main__":
if args.r or args.t or args.u:
cmd = ["coverage", "run"]
if args.lf or args.sw:
if args.failed or args.step:
cmd += ["--append"]
cmd += ["-m"]
else:
@@ -41,9 +42,9 @@ if __name__ == "__main__":
cmd += ["pytest", "-vv"]
if args.o:
env["QT_QPA_PLATFORM"] = "offscreen"
if args.lf:
if args.failed:
cmd += ["--last-failed"]
if args.sw:
if args.step:
cmd += ["--stepwise"]
if args.m:
cmd += ["-m", args.m]
@@ -55,11 +56,13 @@ if __name__ == "__main__":
if args.r:
subprocess.call(["coverage", "xml"])
if args.rh:
if args.html:
subprocess.call(["coverage", "html"])
if args.t and not args.u:
subprocess.call(["coverage", "report"])
if args.u:
subprocess.call(["coverage", "report", "--skip-covered"])
if args.l:
subprocess.call(["coverage", "report", "--skip-covered", "--show-missing"])
tmpConf.unlink(missing_ok=True)

View File

@@ -185,6 +185,14 @@ def testGuiDocEditor_Init(qtbot, nwGUI, projPath, ipsumText, mockRnd):
docEditor.docHeader.setHandle(C.hInvalid)
assert docEditor.docHeader.itemTitle.text() == titleBefore
# Toggle tool bar from header
with qtbot.waitSignal(docEditor.docHeader.toggleToolBarRequest, timeout=1000):
docEditor.docHeader.tbButton.click()
# Toggle focus mode from header
with qtbot.waitSignal(docEditor.toggleFocusModeRequest, timeout=1000):
docEditor.docHeader.minmaxButton.click()
# Close from header
with qtbot.waitSignal(docEditor.docHeader.closeDocumentRequest, timeout=1000):
docEditor.docHeader.closeButton.click()

View File

@@ -32,7 +32,7 @@ from novelwriter import CONFIG, SHARED
from novelwriter.constants import nwKeyWords, nwShortcode, nwStats, nwUnicode
from novelwriter.core.project import NWProject
from novelwriter.editor.editor import GuiDocEditor
from novelwriter.enum import nwDocAction, nwDocInsert
from novelwriter.enum import nwDocAction, nwDocInsert, nwFocus, nwView
from novelwriter.shared import _GuiAlert
from novelwriter.types import QtKeepAnchor, QtMoveRight, QtSelectWord
@@ -603,4 +603,23 @@ def testGuiMainMenu_Insert(qtbot, monkeypatch, nwGUI, fncPath, projPath, mockRnd
path = str(projPath / "content" / "000000000000f.nwd")
assert SHARED.lastAlert[-1] == f"File Location: {path}"
# Focus and View Change
# ======================
with qtbot.waitSignal(mainMenu.requestFocusChange, timeout=1000) as signal:
mainMenu.aFocusTree.activate(QAction.ActionEvent.Trigger)
assert signal.args == [nwFocus.TREE]
with qtbot.waitSignal(mainMenu.requestFocusChange, timeout=1000) as signal:
mainMenu.aFocusDocument.activate(QAction.ActionEvent.Trigger)
assert signal.args == [nwFocus.DOCUMENT]
with qtbot.waitSignal(mainMenu.requestFocusChange, timeout=1000) as signal:
mainMenu.aFocusOutline.activate(QAction.ActionEvent.Trigger)
assert signal.args == [nwFocus.OUTLINE]
with qtbot.waitSignal(mainMenu.requestViewChange, timeout=1000) as signal:
mainMenu.aFindProj.activate(QAction.ActionEvent.Trigger)
assert signal.args == [nwView.SEARCH]
# qtbot.stop()

View File

@@ -280,7 +280,12 @@ def testGuiOutline_Content(qtbot, monkeypatch, nwGUI, prjLipsum, fncPath, tstPat
assert outlineData.titleValue.text() == "Scene One"
# Click POV Link
assert outlineData.tagValues[nwKeyWords.POV_KEY][1].text() == "<a href='Bod'>Bod</a>"
povLabel = outlineData.tagValues[nwKeyWords.POV_KEY][1]
assert povLabel.text() == "<a href='Bod'>Bod</a>"
with qtbot.waitSignal(outlineData.itemTagClicked, timeout=1000) as signal:
povLabel.linkActivated.emit("Bod")
assert signal.args == ["Bod"]
outlineView._tagClicked("Bod")
assert nwGUI.docViewer.docHandle == "4c4f28287af27"

View File

@@ -25,7 +25,23 @@ import pytest
from novelwriter import CONFIG
from novelwriter.constants import nwLabels
from novelwriter.enum import nwTheme
from novelwriter.enum import nwTheme, nwView
@pytest.mark.gui
def testGuiSideBar_ViewChange(qtbot, nwGUI):
"""Test the view change buttons on the side bar."""
sidebar = nwGUI.sideBar
buttons = [
(sidebar.tbProject, nwView.PROJECT),
(sidebar.tbNovel, nwView.NOVEL),
(sidebar.tbSearch, nwView.SEARCH),
(sidebar.tbOutline, nwView.OUTLINE),
]
for button, view in buttons:
with qtbot.waitSignal(sidebar.requestViewChange, timeout=1000) as signal:
button.click()
assert signal.args == [view]
@pytest.mark.gui

View File

@@ -537,6 +537,9 @@ def testGuiDocViewer_FooterAndErrors(qtbot, monkeypatch, nwGUI, projPath, mockRn
nwGUI.viewDocument(C.hSceneDoc)
fullLength = len(docViewer.toPlainText())
with qtbot.waitSignal(docViewer.togglePanelVisibility, timeout=1000):
docViewer.docFooter.showHide.click()
docViewer.docFooter._doToggleSynopsis(False)
noSynopLength = len(docViewer.toPlainText())
assert noSynopLength < fullLength