Update tests and test coverage
This commit is contained in:
@@ -30,7 +30,7 @@ import pytest
|
||||
|
||||
from PyQt6.QtCore import Qt
|
||||
from PyQt6.QtGui import QPalette
|
||||
from PyQt6.QtWidgets import QInputDialog, QMessageBox
|
||||
from PyQt6.QtWidgets import QInputDialog
|
||||
|
||||
from novelwriter import CONFIG, SHARED, __hexversion__
|
||||
from novelwriter.common import jsonEncode
|
||||
@@ -42,6 +42,7 @@ from novelwriter.gui.doceditor import GuiDocEditor
|
||||
from novelwriter.gui.noveltree import GuiNovelView
|
||||
from novelwriter.gui.outline import GuiOutlineView
|
||||
from novelwriter.gui.projtree import GuiProjectTree
|
||||
from novelwriter.shared import _GuiAlert
|
||||
from novelwriter.tools.welcome import GuiWelcome
|
||||
from novelwriter.types import QtModCtrl, QtModShift
|
||||
|
||||
@@ -104,7 +105,7 @@ def testGuiMain_Launch(qtbot, monkeypatch, nwGUI, projPath):
|
||||
|
||||
# Check that closes can be blocked
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr(QMessageBox, "result", lambda *a: QMessageBox.StandardButton.No)
|
||||
mp.setattr(_GuiAlert, "finalState", False)
|
||||
assert nwGUI.openProject(projPath) is True
|
||||
assert nwGUI.closeMain() is False
|
||||
nwGUI.closeProject()
|
||||
@@ -841,7 +842,7 @@ def testGuiMain_OpenClose(qtbot, monkeypatch, nwGUI, projPath, fncPath, mockRnd)
|
||||
# Block closing
|
||||
assert SHARED.hasProject is True
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr(QMessageBox, "result", lambda *a: QMessageBox.StandardButton.No)
|
||||
mp.setattr(_GuiAlert, "finalState", False)
|
||||
assert nwGUI.openProject(projPath) is False
|
||||
assert SHARED.hasProject is True
|
||||
|
||||
@@ -854,7 +855,7 @@ def testGuiMain_OpenClose(qtbot, monkeypatch, nwGUI, projPath, fncPath, mockRnd)
|
||||
shutil.copyfile(lockBack, lockPath)
|
||||
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr(QMessageBox, "result", lambda *a: QMessageBox.StandardButton.No)
|
||||
mp.setattr(_GuiAlert, "finalState", False)
|
||||
assert nwGUI.openProject(projPath) is False
|
||||
|
||||
assert nwGUI.openProject(projPath) is True
|
||||
|
||||
@@ -24,7 +24,7 @@ import sys
|
||||
|
||||
import pytest
|
||||
|
||||
from PyQt6.QtWidgets import QApplication, QDialog, QMessageBox
|
||||
from PyQt6.QtWidgets import QApplication, QDialog
|
||||
|
||||
from novelwriter import CONFIG, SHARED
|
||||
from novelwriter.dialogs.about import GuiAbout
|
||||
@@ -49,8 +49,6 @@ LANG_DATA = CONFIG.listLanguages(CONFIG.LANG_NW)
|
||||
def testGuiI18n_Localisation(qtbot, monkeypatch, language, nwGUI, projPath):
|
||||
"""Test loading the gui with a specific language."""
|
||||
monkeypatch.setattr(QDialog, "exec", lambda *a: None)
|
||||
monkeypatch.setattr(QMessageBox, "exec", lambda *a: None)
|
||||
monkeypatch.setattr(QMessageBox, "result", lambda *a: QMessageBox.StandardButton.Yes)
|
||||
|
||||
# Set the test language
|
||||
CONFIG.guiLocale = language
|
||||
|
||||
@@ -25,12 +25,13 @@ from unittest.mock import MagicMock
|
||||
import pytest
|
||||
|
||||
from PyQt6.QtGui import QAction, QDesktopServices, QTextBlock
|
||||
from PyQt6.QtWidgets import QFileDialog, QMessageBox
|
||||
from PyQt6.QtWidgets import QFileDialog
|
||||
|
||||
from novelwriter import CONFIG, SHARED
|
||||
from novelwriter.constants import nwKeyWords, nwShortcode, nwStats, nwUnicode
|
||||
from novelwriter.enum import nwDocAction, nwDocInsert
|
||||
from novelwriter.gui.doceditor import GuiDocEditor
|
||||
from novelwriter.shared import _GuiAlert
|
||||
from novelwriter.types import QtKeepAnchor, QtMoveRight, QtSelectWord
|
||||
|
||||
from tests.tools import C, buildTestProject, writeFile
|
||||
@@ -575,7 +576,7 @@ def testGuiMainMenu_Insert(qtbot, monkeypatch, nwGUI, fncPath, projPath, mockRnd
|
||||
|
||||
# The document isn't empty, so the message box should pop
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr(QMessageBox, "result", lambda *a, **k: QMessageBox.StandardButton.No)
|
||||
mp.setattr(_GuiAlert, "finalState", False)
|
||||
assert not nwGUI.importDocument()
|
||||
assert docEditor.getText() == "Bar"
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ import pytest
|
||||
|
||||
from PyQt6.QtCore import QEvent, QItemSelectionModel, QModelIndex, QPointF
|
||||
from PyQt6.QtGui import QMouseEvent
|
||||
from PyQt6.QtWidgets import QMenu, QMessageBox
|
||||
from PyQt6.QtWidgets import QMenu
|
||||
|
||||
from novelwriter import CONFIG, SHARED
|
||||
from novelwriter.dialogs.docmerge import GuiDocMerge
|
||||
@@ -34,6 +34,7 @@ from novelwriter.dialogs.docsplit import GuiDocSplit
|
||||
from novelwriter.dialogs.editlabel import GuiEditLabel
|
||||
from novelwriter.enum import nwDocMode, nwItemClass, nwItemLayout, nwItemType
|
||||
from novelwriter.gui.projtree import _TreeContextMenu
|
||||
from novelwriter.shared import _GuiAlert
|
||||
from novelwriter.types import (
|
||||
QtAccepted, QtModNone, QtMouseLeft, QtMouseMiddle, QtRejected,
|
||||
QtScrollAlwaysOff, QtScrollAsNeeded
|
||||
@@ -627,7 +628,7 @@ def testGuiProjTree_DeleteRequest(qtbot, caplog, monkeypatch, nwGUI, projPath, m
|
||||
|
||||
# User can cancel move to trash
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr(QMessageBox, "result", lambda *a: QMessageBox.StandardButton.No)
|
||||
mp.setattr(_GuiAlert, "finalState", False)
|
||||
projTree.processDeleteRequest(hScenes, askFirst=True)
|
||||
assert [n.item.itemName for n in tree.model.root.allChildren()] == [
|
||||
"Novel", "Title Page", "New Folder", "New Chapter", "New Scene",
|
||||
@@ -645,7 +646,7 @@ def testGuiProjTree_DeleteRequest(qtbot, caplog, monkeypatch, nwGUI, projPath, m
|
||||
|
||||
# User can block permanent deletion
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr(QMessageBox, "result", lambda *a: QMessageBox.StandardButton.No)
|
||||
mp.setattr(_GuiAlert, "finalState", False)
|
||||
projTree.processDeleteRequest(hScenes[0:2], askFirst=True)
|
||||
assert [n.item.itemName for n in tree.model.root.allChildren()] == [
|
||||
"Novel", "Title Page", "New Folder", "New Chapter", "New Scene",
|
||||
@@ -677,7 +678,7 @@ def testGuiProjTree_DeleteRequest(qtbot, caplog, monkeypatch, nwGUI, projPath, m
|
||||
|
||||
# Trash can be completely emptied, but user can block it
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr(QMessageBox, "result", lambda *a: QMessageBox.StandardButton.No)
|
||||
mp.setattr(_GuiAlert, "finalState", False)
|
||||
projTree.emptyTrash()
|
||||
assert [n.item.itemName for n in tree.model.root.allChildren()] == [
|
||||
"Novel", "Title Page", "Chapter Folder", "Plot", "Characters", "Trash",
|
||||
@@ -995,7 +996,7 @@ def testGuiProjTree_Duplicate(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
|
||||
|
||||
# Duplicate title page, but select no
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr(QMessageBox, "result", lambda *a: QtRejected)
|
||||
mp.setattr(_GuiAlert, "finalState", False)
|
||||
projTree.duplicateFromHandle(C.hTitlePage)
|
||||
assert [n.item.itemName for n in tree.model.root.allChildren()] == [
|
||||
"Novel", "Title Page", "New Folder", "New Chapter", "New Scene",
|
||||
@@ -1302,7 +1303,7 @@ def testGuiProjTree_ContextMenu(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
|
||||
|
||||
# Click no on the dialog
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr(QMessageBox, "result", lambda *a: QtRejected)
|
||||
mp.setattr(_GuiAlert, "finalState", False)
|
||||
ctxMenu._convertFolderToFile(nwItemLayout.DOCUMENT)
|
||||
assert nodeOne.item.isFolderType()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user