Update tests

This commit is contained in:
Veronica Berglyd Olsen
2022-04-20 21:50:07 +02:00
parent e32eb21fbf
commit 607f9409d2
30 changed files with 740 additions and 781 deletions
+15 -13
View File
@@ -19,21 +19,21 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import pytest
import os
import pytest
from tools import getGuiItem, readFile, writeFile
from mock import causeOSError
from tools import getGuiItem, readFile, writeFile
from PyQt5.QtWidgets import QAction, QMessageBox, QDialog
from novelwriter.dialogs import GuiDocMerge, GuiItemEditor
from novelwriter.enum import nwItemType, nwWidget
from novelwriter.dialogs import GuiDocMerge, GuiItemEditor
from novelwriter.core.tree import NWTree
@pytest.mark.gui
def testDlgMerge_Main(qtbot, monkeypatch, nwGUI, fncProj):
def testDlgMerge_Main(qtbot, monkeypatch, nwGUI, fncProj, mockRnd):
"""Test the merge documents tool.
"""
# Block message box
@@ -41,17 +41,17 @@ def testDlgMerge_Main(qtbot, monkeypatch, nwGUI, fncProj):
monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Ok)
# Create a new project
nwGUI.theProject.projTree.setSeed(42)
assert nwGUI.newProject({"projPath": fncProj})
# Handles for new objects
hChapterDir = "31489056e0916"
hChapterOne = "98010bd9270f9"
hSceneOne = "0e17daca5f3e1"
hSceneTwo = "1a6562590ef19"
hSceneThree = "031b4af5197ec"
hSceneFour = "41cfc0d1f2d12"
hMergedDoc = "2858dcd1057d3"
hNovelRoot = "0000000000008"
hChapterDir = "000000000000d"
hChapterOne = "000000000000e"
hSceneOne = "000000000000f"
hSceneTwo = "0000000000010"
hSceneThree = "0000000000011"
hSceneFour = "0000000000012"
hMergedDoc = "0000000000023"
# Add Project Content
monkeypatch.setattr(GuiItemEditor, "exec_", lambda *a: QDialog.Accepted)
@@ -137,7 +137,7 @@ def testDlgMerge_Main(qtbot, monkeypatch, nwGUI, fncProj):
assert os.path.isfile(mergedFile)
assert readFile(mergedFile) == (
"%%%%~name: New Chapter\n"
"%%%%~path: 73475cb40a568/2858dcd1057d3\n"
"%%%%~path: %s/%s\n"
"%%%%~kind: NOVEL/DOCUMENT\n"
"%s\n\n"
"%s\n\n"
@@ -145,6 +145,8 @@ def testDlgMerge_Main(qtbot, monkeypatch, nwGUI, fncProj):
"%s\n\n"
"%s\n\n"
) % (
hNovelRoot,
hMergedDoc,
tChapterOne.strip(),
tSceneOne.strip(),
tSceneTwo.strip(),
+30 -30
View File
@@ -19,22 +19,22 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import pytest
import os
import pytest
from tools import getGuiItem, readFile, writeFile
from mock import causeOSError
from tools import getGuiItem, readFile, writeFile
from PyQt5.QtWidgets import QAction, QMessageBox, QDialog
from novelwriter.dialogs import GuiDocSplit, GuiItemEditor
from novelwriter.enum import nwItemType, nwWidget
from novelwriter.core.document import NWDoc
from novelwriter.dialogs import GuiDocSplit, GuiItemEditor
from novelwriter.core.tree import NWTree
from novelwriter.core.document import NWDoc
@pytest.mark.gui
def testDlgSplit_Main(qtbot, monkeypatch, nwGUI, fncProj):
def testDlgSplit_Main(qtbot, monkeypatch, nwGUI, fncProj, mockRnd):
"""Test the split document tool.
"""
# Block message box
@@ -42,20 +42,20 @@ def testDlgSplit_Main(qtbot, monkeypatch, nwGUI, fncProj):
monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Ok)
# Create a new project
nwGUI.theProject.projTree.setSeed(42)
assert nwGUI.newProject({"projPath": fncProj}) is True
# Handles for new objects
hNovelRoot = "73475cb40a568"
hChapterDir = "31489056e0916"
hToSplit = "1a6562590ef19"
hPartition = "41cfc0d1f2d12"
hChapterOne = "2858dcd1057d3"
hSceneOne = "2fca346db6561"
hSceneTwo = "02d20bbd7e394"
hSceneThree = "7688b6ef52555"
hSceneFour = "c837649cce43f"
hSceneFive = "6208ef0f7750c"
hNovelRoot = "0000000000008"
hChapterDir = "000000000000d"
hToSplit = "0000000000010"
hNewFolder = "0000000000021"
hPartition = "0000000000022"
hChapterOne = "0000000000023"
hSceneOne = "0000000000024"
hSceneTwo = "0000000000025"
hSceneThree = "0000000000026"
hSceneFour = "0000000000027"
hSceneFive = "0000000000028"
# Add Project Content
monkeypatch.setattr(GuiItemEditor, "exec_", lambda *a: QDialog.Accepted)
@@ -173,52 +173,52 @@ def testDlgSplit_Main(qtbot, monkeypatch, nwGUI, fncProj):
assert readFile(os.path.join(contentDir, hPartition+".nwd")) == (
"%%%%~name: Nantucket\n"
"%%%%~path: 031b4af5197ec/%s\n"
"%%%%~path: %s/%s\n"
"%%%%~kind: NOVEL/DOCUMENT\n"
"%s\n\n"
) % (hPartition, tPartition)
) % (hNewFolder, hPartition, tPartition)
assert readFile(os.path.join(contentDir, hChapterOne+".nwd")) == (
"%%%%~name: Chapter One\n"
"%%%%~path: 031b4af5197ec/%s\n"
"%%%%~path: %s/%s\n"
"%%%%~kind: NOVEL/DOCUMENT\n"
"%s\n\n"
) % (hChapterOne, tChapterOne)
) % (hNewFolder, hChapterOne, tChapterOne)
assert readFile(os.path.join(contentDir, hSceneOne+".nwd")) == (
"%%%%~name: Scene One\n"
"%%%%~path: 031b4af5197ec/%s\n"
"%%%%~path: %s/%s\n"
"%%%%~kind: NOVEL/DOCUMENT\n"
"%s\n\n"
) % (hSceneOne, tSceneOne)
) % (hNewFolder, hSceneOne, tSceneOne)
assert readFile(os.path.join(contentDir, hSceneTwo+".nwd")) == (
"%%%%~name: Scene Two\n"
"%%%%~path: 031b4af5197ec/%s\n"
"%%%%~path: %s/%s\n"
"%%%%~kind: NOVEL/DOCUMENT\n"
"%s\n\n"
) % (hSceneTwo, tSceneTwo)
) % (hNewFolder, hSceneTwo, tSceneTwo)
assert readFile(os.path.join(contentDir, hSceneThree+".nwd")) == (
"%%%%~name: Scene Three\n"
"%%%%~path: 031b4af5197ec/%s\n"
"%%%%~path: %s/%s\n"
"%%%%~kind: NOVEL/DOCUMENT\n"
"%s\n\n"
) % (hSceneThree, tSceneThree)
) % (hNewFolder, hSceneThree, tSceneThree)
assert readFile(os.path.join(contentDir, hSceneFour+".nwd")) == (
"%%%%~name: Scene Four\n"
"%%%%~path: 031b4af5197ec/%s\n"
"%%%%~path: %s/%s\n"
"%%%%~kind: NOVEL/DOCUMENT\n"
"%s\n\n"
) % (hSceneFour, tSceneFour)
) % (hNewFolder, hSceneFour, tSceneFour)
assert readFile(os.path.join(contentDir, hSceneFive+".nwd")) == (
"%%%%~name: The End\n"
"%%%%~path: 031b4af5197ec/%s\n"
"%%%%~path: %s/%s\n"
"%%%%~kind: NOVEL/DOCUMENT\n"
"%s\n\n"
) % (hSceneFive, tSceneFive)
) % (hNewFolder, hSceneFive, tSceneFive)
# OS error
with monkeypatch.context() as mp:
+35 -37
View File
@@ -20,7 +20,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import pytest
import random
from tools import getGuiItem
@@ -31,9 +30,12 @@ from novelwriter.enum import nwItemLayout, nwItemType
from novelwriter.dialogs import GuiItemEditor
from novelwriter.core.tree import NWTree
statusKeys = ["s000000", "s000001", "s000002", "s000003"]
importKeys = ["i000004", "i000005", "i000006", "i000007"]
@pytest.mark.gui
def testDlgItemEditor_Dialog(qtbot, monkeypatch, nwGUI, fncProj):
def testDlgItemEditor_Dialog(qtbot, monkeypatch, nwGUI, fncProj, mockRnd):
"""Test launching the item editor dialog from GuiMain.
"""
# Block message box
@@ -46,15 +48,15 @@ def testDlgItemEditor_Dialog(qtbot, monkeypatch, nwGUI, fncProj):
assert nwGUI.editItem() is False
# Create and Open Project
nwGUI.theProject.projTree.setSeed(42)
assert nwGUI.newProject({"projPath": fncProj})
tHandle = "000000000000f"
# No Selection
nwGUI.treeView.clearSelection()
assert nwGUI.editItem() is False
# Force opening from editor
assert nwGUI.openDocument("0e17daca5f3e1")
assert nwGUI.openDocument(tHandle)
nwGUI.isFocusMode = True
# Block Tree Lookup
@@ -63,9 +65,9 @@ def testDlgItemEditor_Dialog(qtbot, monkeypatch, nwGUI, fncProj):
assert nwGUI.editItem() is False
# Invalid Type
nwGUI.theProject.projTree["0e17daca5f3e1"]._type = nwItemType.NO_TYPE
nwGUI.theProject.projTree[tHandle]._type = nwItemType.NO_TYPE
assert nwGUI.editItem() is False
nwGUI.theProject.projTree["0e17daca5f3e1"]._type = nwItemType.FILE
nwGUI.theProject.projTree[tHandle]._type = nwItemType.FILE
# Open Properly
assert nwGUI.editItem() is True
@@ -89,7 +91,7 @@ def testDlgItemEditor_Dialog(qtbot, monkeypatch, nwGUI, fncProj):
@pytest.mark.gui
def testDlgItemEditor_Novel(qtbot, monkeypatch, nwGUI, fncProj, constData):
def testDlgItemEditor_Novel(qtbot, monkeypatch, nwGUI, fncProj, mockRnd):
"""Test the item editor dialog for a novel document.
"""
# Block message box
@@ -97,13 +99,13 @@ def testDlgItemEditor_Novel(qtbot, monkeypatch, nwGUI, fncProj, constData):
monkeypatch.setattr(GuiProjectTree, "hasFocus", lambda *a: True)
# Create Project and Open Document
random.seed(42)
nwGUI.theProject.projTree.setSeed(42)
assert nwGUI.newProject({"projPath": fncProj})
assert nwGUI.theProject.statusItems.name(constData.statusKeys[0]) == "New"
assert nwGUI.theProject.statusItems.name(constData.statusKeys[1]) == "Note"
tHandle = "000000000000f"
assert nwGUI.openDocument("0e17daca5f3e1") is True
assert nwGUI.theProject.statusItems.name(statusKeys[0]) == "New"
assert nwGUI.theProject.statusItems.name(statusKeys[1]) == "Note"
assert nwGUI.openDocument(tHandle) is True
# Check that an invalid handle is managed
itemEdit = GuiItemEditor(nwGUI, "whatever")
@@ -111,12 +113,12 @@ def testDlgItemEditor_Novel(qtbot, monkeypatch, nwGUI, fncProj, constData):
itemEdit._doClose()
# Edit a Document
itemEdit = GuiItemEditor(nwGUI, "0e17daca5f3e1")
itemEdit = GuiItemEditor(nwGUI, tHandle)
itemEdit.show()
# Check Existing Settings
assert itemEdit.editName.text() == "New Scene"
assert itemEdit.editStatus.currentData() == constData.statusKeys[0]
assert itemEdit.editStatus.currentData() == statusKeys[0]
assert itemEdit.editLayout.currentData() == nwItemLayout.DOCUMENT
assert itemEdit.editExport.isChecked() is True
@@ -130,12 +132,12 @@ def testDlgItemEditor_Novel(qtbot, monkeypatch, nwGUI, fncProj, constData):
# Check New Settings
itemEdit._doSave()
assert itemEdit.theItem.itemName == "Great Scene"
assert itemEdit.theItem.itemStatus == constData.statusKeys[1]
assert itemEdit.theItem.itemStatus == statusKeys[1]
assert itemEdit.theItem.itemLayout == nwItemLayout.NOTE
assert itemEdit.theItem.isExported is False
# Check that the editor header is updated
nwGUI.docEditor.updateDocInfo("0e17daca5f3e1")
nwGUI.docEditor.updateDocInfo(tHandle)
assert nwGUI.docEditor.docHeader.theTitle.text() == "Novel New Chapter Great Scene"
itemEdit.close()
@@ -146,7 +148,7 @@ def testDlgItemEditor_Novel(qtbot, monkeypatch, nwGUI, fncProj, constData):
@pytest.mark.gui
def testDlgItemEditor_Note(qtbot, monkeypatch, nwGUI, fncProj, constData):
def testDlgItemEditor_Note(qtbot, monkeypatch, nwGUI, fncProj, mockRnd):
"""Test the item editor dialog for a project note.
"""
# Block message box
@@ -154,29 +156,27 @@ def testDlgItemEditor_Note(qtbot, monkeypatch, nwGUI, fncProj, constData):
monkeypatch.setattr(GuiProjectTree, "hasFocus", lambda *a: True)
# Create Project and Open Document
random.seed(42)
nwGUI.theProject.projTree.setSeed(42)
assert nwGUI.newProject({"projPath": fncProj})
assert nwGUI.theProject.statusItems.name(constData.statusKeys[0]) == "New"
assert nwGUI.theProject.statusItems.name(constData.statusKeys[1]) == "Note"
assert nwGUI.theProject.importItems.name(constData.importKeys[0]) == "New"
assert nwGUI.theProject.importItems.name(constData.importKeys[1]) == "Minor"
assert nwGUI.theProject.statusItems.name(statusKeys[0]) == "New"
assert nwGUI.theProject.statusItems.name(statusKeys[1]) == "Note"
assert nwGUI.theProject.importItems.name(importKeys[0]) == "New"
assert nwGUI.theProject.importItems.name(importKeys[1]) == "Minor"
# Create Note
nwGUI.treeView.clearSelection()
nwGUI.treeView._getTreeItem("71ee45a3c0db9").setSelected(True)
nwGUI.treeView._getTreeItem("000000000000a").setSelected(True)
nwGUI.treeView.newTreeItem(nwItemType.FILE, None)
# Open Note
assert nwGUI.openDocument("1a6562590ef19")
assert nwGUI.openDocument("0000000000010")
# Edit a Document
itemEdit = GuiItemEditor(nwGUI, "1a6562590ef19")
itemEdit = GuiItemEditor(nwGUI, "0000000000010")
itemEdit.show()
# Check Existing Settings
assert itemEdit.editName.text() == "New Note"
assert itemEdit.editStatus.currentData() == constData.importKeys[0]
assert itemEdit.editStatus.currentData() == importKeys[0]
assert itemEdit.editLayout.currentData() == nwItemLayout.NOTE
assert itemEdit.editExport.isChecked() is True
@@ -188,8 +188,8 @@ def testDlgItemEditor_Note(qtbot, monkeypatch, nwGUI, fncProj, constData):
# Check New Settings
assert itemEdit.theItem.itemName == "New Character"
assert itemEdit.theItem.itemStatus == constData.statusKeys[0]
assert itemEdit.theItem.itemImport == constData.importKeys[1]
assert itemEdit.theItem.itemStatus == statusKeys[0]
assert itemEdit.theItem.itemImport == importKeys[1]
assert itemEdit.theItem.itemLayout == nwItemLayout.NOTE
assert itemEdit.theItem.isExported is False
@@ -201,7 +201,7 @@ def testDlgItemEditor_Note(qtbot, monkeypatch, nwGUI, fncProj, constData):
@pytest.mark.gui
def testDlgItemEditor_Folder(qtbot, monkeypatch, nwGUI, fncProj, constData):
def testDlgItemEditor_Folder(qtbot, monkeypatch, nwGUI, fncProj, mockRnd):
"""Test the item editor dialog for a folder.
"""
# Block message box
@@ -209,20 +209,18 @@ def testDlgItemEditor_Folder(qtbot, monkeypatch, nwGUI, fncProj, constData):
monkeypatch.setattr(GuiProjectTree, "hasFocus", lambda *a: True)
# Create Project and Open Document
random.seed(42)
nwGUI.theProject.projTree.setSeed(42)
assert nwGUI.newProject({"projPath": fncProj})
# Edit a Folder
itemEdit = GuiItemEditor(nwGUI, "31489056e0916")
itemEdit = GuiItemEditor(nwGUI, "000000000000d")
itemEdit.show()
assert nwGUI.theProject.statusItems.name(constData.statusKeys[0]) == "New"
assert nwGUI.theProject.statusItems.name(constData.statusKeys[1]) == "Note"
assert nwGUI.theProject.statusItems.name(statusKeys[0]) == "New"
assert nwGUI.theProject.statusItems.name(statusKeys[1]) == "Note"
# Check Existing Settings
assert itemEdit.editName.text() == "New Chapter"
assert itemEdit.editStatus.currentData() == constData.statusKeys[0]
assert itemEdit.editStatus.currentData() == statusKeys[0]
assert itemEdit.editLayout.currentData() == nwItemLayout.NO_LAYOUT
assert itemEdit.editExport.isChecked() is False
@@ -236,7 +234,7 @@ def testDlgItemEditor_Folder(qtbot, monkeypatch, nwGUI, fncProj, constData):
# Check New Settings
itemEdit._doSave()
assert itemEdit.theItem.itemName == "Chapter One"
assert itemEdit.theItem.itemStatus == constData.statusKeys[1]
assert itemEdit.theItem.itemStatus == statusKeys[1]
assert itemEdit.theItem.itemLayout == nwItemLayout.NO_LAYOUT
assert itemEdit.theItem.isExported is False
+11 -12
View File
@@ -21,7 +21,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
import os
import pytest
import random
from shutil import copyfile
from tools import cmpFiles, getGuiItem
@@ -35,11 +34,13 @@ from novelwriter.dialogs import GuiProjectSettings
keyDelay = 2
typeDelay = 1
stepDelay = 20
statusKeys = ["s000000", "s000001", "s000002", "s000003"]
importKeys = ["i000004", "i000005", "i000006", "i000007"]
@pytest.mark.gui
def testDlgProjSettings_Dialog(
qtbot, monkeypatch, nwGUI, fncDir, fncProj, outDir, refDir, constData
qtbot, monkeypatch, nwGUI, fncDir, fncProj, outDir, refDir, mockRnd
):
"""Test the full project settings dialog.
"""
@@ -56,8 +57,6 @@ def testDlgProjSettings_Dialog(
assert getGuiItem("GuiProjectSettings") is None
# Create new project
random.seed(42)
nwGUI.theProject.projTree.setSeed(42)
assert nwGUI.newProject({"projPath": fncProj})
nwGUI.mainConf.backupPath = fncDir
@@ -145,15 +144,15 @@ def testDlgProjSettings_Dialog(
assert projEdit.tabStatus.getNewList() == (
[
{
"key": constData.statusKeys[0],
"key": statusKeys[0],
"name": "New",
"cols": (100, 100, 100)
}, {
"key": constData.statusKeys[1],
"key": statusKeys[1],
"name": "Note",
"cols": (200, 50, 0)
}, {
"key": constData.statusKeys[3],
"key": statusKeys[3],
"name": "Finished",
"cols": (50, 200, 0)
}, {
@@ -162,7 +161,7 @@ def testDlgProjSettings_Dialog(
"cols": (20, 30, 40)
}
], [
constData.statusKeys[2] # Deleted item
statusKeys[2] # Deleted item
]
)
@@ -170,25 +169,25 @@ def testDlgProjSettings_Dialog(
projEdit.tabStatus.listBox.clearSelection()
projEdit.tabStatus._moveItem(1)
assert [x["key"] for x in projEdit.tabStatus.getNewList()[0]] == [
constData.statusKeys[0], constData.statusKeys[1], constData.statusKeys[3], None
statusKeys[0], statusKeys[1], statusKeys[3], None
]
projEdit.tabStatus.listBox.clearSelection()
projEdit.tabStatus.listBox.topLevelItem(0).setSelected(True)
projEdit.tabStatus._moveItem(-1)
assert [x["key"] for x in projEdit.tabStatus.getNewList()[0]] == [
constData.statusKeys[0], constData.statusKeys[1], constData.statusKeys[3], None
statusKeys[0], statusKeys[1], statusKeys[3], None
]
projEdit.tabStatus.listBox.clearSelection()
projEdit.tabStatus.listBox.topLevelItem(3).setSelected(True)
projEdit.tabStatus._moveItem(-1)
assert [x["key"] for x in projEdit.tabStatus.getNewList()[0]] == [
constData.statusKeys[0], constData.statusKeys[1], None, constData.statusKeys[3]
statusKeys[0], statusKeys[1], None, statusKeys[3]
]
projEdit.tabStatus._moveItem(1)
assert [x["key"] for x in projEdit.tabStatus.getNewList()[0]] == [
constData.statusKeys[0], constData.statusKeys[1], constData.statusKeys[3], None
statusKeys[0], statusKeys[1], statusKeys[3], None
]
# Importance Tab