Move dialog source files to their own folder
This commit is contained in:
@@ -1,70 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
novelWriter – About Dialog Class Tester
|
||||
=======================================
|
||||
|
||||
This file is a part of novelWriter
|
||||
Copyright 2018–2021, Veronica Berglyd Olsen
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
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
|
||||
|
||||
from tools import getGuiItem
|
||||
|
||||
from PyQt5.QtWidgets import QAction, QMessageBox
|
||||
|
||||
from nw.gui import GuiAbout
|
||||
|
||||
keyDelay = 2
|
||||
typeDelay = 1
|
||||
stepDelay = 20
|
||||
|
||||
@pytest.mark.gui
|
||||
def testGuiAbout_Dialog(qtbot, monkeypatch, nwGUI):
|
||||
"""Test the full about dialogs.
|
||||
"""
|
||||
# NW About
|
||||
monkeypatch.setattr(GuiAbout, "exec_", lambda *args: None)
|
||||
nwGUI.mainMenu.aAboutNW.activate(QAction.Trigger)
|
||||
qtbot.waitUntil(lambda: getGuiItem("GuiAbout") is not None, timeout=1000)
|
||||
|
||||
msgAbout = getGuiItem("GuiAbout")
|
||||
assert isinstance(msgAbout, GuiAbout)
|
||||
msgAbout.show()
|
||||
|
||||
assert msgAbout.pageAbout.document().characterCount() > 100
|
||||
assert msgAbout.pageNotes.document().characterCount() > 100
|
||||
assert msgAbout.pageLicense.document().characterCount() > 100
|
||||
|
||||
msgAbout.mainConf.assetPath = "whatever"
|
||||
|
||||
msgAbout._fillNotesPage()
|
||||
assert msgAbout.pageNotes.toPlainText() == "Error loading release notes text ..."
|
||||
|
||||
msgAbout._fillLicensePage()
|
||||
assert msgAbout.pageLicense.toPlainText() == "Error loading licence text ..."
|
||||
|
||||
msgAbout.showReleaseNotes()
|
||||
assert msgAbout.tabBox.currentWidget() == msgAbout.pageNotes
|
||||
|
||||
# Qt About
|
||||
monkeypatch.setattr(QMessageBox, "aboutQt", lambda *args, **kwargs: None)
|
||||
nwGUI.mainMenu.aAboutQt.activate(QAction.Trigger)
|
||||
|
||||
# qtbot.stopForInteraction()
|
||||
msgAbout._doClose()
|
||||
|
||||
# END Test testGuiAbout_Dialog
|
||||
@@ -30,7 +30,7 @@ from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtGui import QTextCursor
|
||||
from PyQt5.QtWidgets import QAction, QMessageBox, QDialog
|
||||
|
||||
from nw.gui.itemeditor import GuiItemEditor
|
||||
from nw.dialogs.itemeditor import GuiItemEditor
|
||||
from nw.gui.doceditor import GuiDocEditor
|
||||
from nw.gui.projtree import GuiProjectTree
|
||||
from nw.enum import nwItemType, nwDocAction, nwWidget
|
||||
|
||||
@@ -1,111 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
novelWriter – Item Editor Dialog Class Tester
|
||||
=============================================
|
||||
|
||||
This file is a part of novelWriter
|
||||
Copyright 2018–2021, Veronica Berglyd Olsen
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
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
|
||||
|
||||
from shutil import copyfile
|
||||
from tools import cmpFiles, getGuiItem
|
||||
|
||||
from PyQt5.QtWidgets import QAction, QMessageBox
|
||||
|
||||
from nw.gui import GuiItemEditor, GuiProjectTree
|
||||
from nw.enum import nwItemLayout
|
||||
|
||||
keyDelay = 2
|
||||
typeDelay = 1
|
||||
stepDelay = 20
|
||||
|
||||
@pytest.mark.gui
|
||||
def testGuiItemEditor_Dialog(qtbot, monkeypatch, nwGUI, fncDir, fncProj, refDir, outDir):
|
||||
"""Test the full item editor dialog.
|
||||
"""
|
||||
projFile = os.path.join(fncProj, "nwProject.nwx")
|
||||
testFile = os.path.join(outDir, "guiItemEditor_Dialog_nwProject.nwx")
|
||||
compFile = os.path.join(refDir, "guiItemEditor_Dialog_nwProject.nwx")
|
||||
|
||||
# Block message box
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *args: QMessageBox.Yes)
|
||||
monkeypatch.setattr(GuiProjectTree, "hasFocus", lambda *args: True)
|
||||
|
||||
# Create new, save, open project
|
||||
nwGUI.theProject.projTree.setSeed(42)
|
||||
assert nwGUI.newProject({"projPath": fncProj})
|
||||
assert nwGUI.openDocument("0e17daca5f3e1")
|
||||
assert nwGUI.treeView.setSelectedHandle("0e17daca5f3e1", doScroll=True)
|
||||
|
||||
monkeypatch.setattr(GuiItemEditor, "exec_", lambda *args: None)
|
||||
nwGUI.mainMenu.aEditItem.activate(QAction.Trigger)
|
||||
qtbot.waitUntil(lambda: getGuiItem("GuiItemEditor") is not None, timeout=1000)
|
||||
|
||||
itemEdit = getGuiItem("GuiItemEditor")
|
||||
assert isinstance(itemEdit, GuiItemEditor)
|
||||
itemEdit.show()
|
||||
|
||||
qtbot.addWidget(itemEdit)
|
||||
|
||||
assert itemEdit.editName.text() == "New Scene"
|
||||
assert itemEdit.editStatus.currentData() == "New"
|
||||
assert itemEdit.editLayout.currentData() == nwItemLayout.SCENE
|
||||
|
||||
for c in "Just a Page":
|
||||
qtbot.keyClick(itemEdit.editName, c, delay=typeDelay)
|
||||
itemEdit.editStatus.setCurrentIndex(1)
|
||||
layoutIdx = itemEdit.editLayout.findData(nwItemLayout.PAGE)
|
||||
itemEdit.editLayout.setCurrentIndex(layoutIdx)
|
||||
|
||||
itemEdit.editExport.setChecked(False)
|
||||
assert not itemEdit.editExport.isChecked()
|
||||
itemEdit._doSave()
|
||||
|
||||
nwGUI.mainMenu.aEditItem.activate(QAction.Trigger)
|
||||
qtbot.waitUntil(lambda: getGuiItem("GuiItemEditor") is not None, timeout=1000)
|
||||
|
||||
itemEdit = getGuiItem("GuiItemEditor")
|
||||
assert isinstance(itemEdit, GuiItemEditor)
|
||||
itemEdit.show()
|
||||
|
||||
qtbot.addWidget(itemEdit)
|
||||
assert itemEdit.editName.text() == "Just a Page"
|
||||
assert itemEdit.editStatus.currentData() == "Note"
|
||||
assert itemEdit.editLayout.currentData() == nwItemLayout.PAGE
|
||||
itemEdit._doClose()
|
||||
|
||||
# Check that the header is updated
|
||||
nwGUI.docEditor.updateDocInfo("0e17daca5f3e1")
|
||||
assert nwGUI.docEditor.docHeader.theTitle.text() == "Novel › New Chapter › Just a Page"
|
||||
assert not nwGUI.docEditor.setCursorLine("where?")
|
||||
assert nwGUI.docEditor.setCursorLine(2)
|
||||
qtbot.wait(stepDelay)
|
||||
assert nwGUI.docEditor.getCursorPosition() == 15
|
||||
|
||||
qtbot.wait(stepDelay)
|
||||
assert nwGUI.saveProject()
|
||||
qtbot.wait(stepDelay)
|
||||
|
||||
# Check the files
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile, [2, 6, 7, 8])
|
||||
|
||||
# qtbot.stopForInteraction()
|
||||
|
||||
# END Test testGuiItemEditor_Dialog
|
||||
@@ -1,185 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
novelWriter – Merge and Split Dialog Classes Tester
|
||||
===================================================
|
||||
|
||||
This file is a part of novelWriter
|
||||
Copyright 2018–2021, Veronica Berglyd Olsen
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
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
|
||||
|
||||
from shutil import copyfile
|
||||
from tools import cmpFiles, getGuiItem
|
||||
|
||||
from PyQt5.QtWidgets import QAction, QMessageBox
|
||||
|
||||
from nw.gui import GuiDocMerge, GuiDocSplit
|
||||
|
||||
keyDelay = 2
|
||||
typeDelay = 1
|
||||
stepDelay = 20
|
||||
|
||||
@pytest.mark.gui
|
||||
def testGuiMergeSplit_Tools(qtbot, monkeypatch, nwGUI, nwLipsum, refDir, outDir):
|
||||
"""Test the full merge and split tools.
|
||||
"""
|
||||
# Block message box
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *args: QMessageBox.Yes)
|
||||
|
||||
nwGUI.theProject.projTree.setSeed(42)
|
||||
assert nwGUI.openProject(nwLipsum)
|
||||
qtbot.wait(stepDelay)
|
||||
|
||||
assert nwGUI.treeView.setSelectedHandle("45e6b01ca35c1")
|
||||
qtbot.wait(stepDelay)
|
||||
|
||||
monkeypatch.setattr(GuiDocMerge, "exec_", lambda *args: None)
|
||||
nwGUI.mainMenu.aMergeDocs.activate(QAction.Trigger)
|
||||
qtbot.waitUntil(lambda: getGuiItem("GuiDocMerge") is not None, timeout=1000)
|
||||
|
||||
nwMerge = getGuiItem("GuiDocMerge")
|
||||
assert isinstance(nwMerge, GuiDocMerge)
|
||||
nwMerge.show()
|
||||
qtbot.wait(stepDelay)
|
||||
|
||||
nwMerge._doMerge()
|
||||
qtbot.wait(stepDelay)
|
||||
|
||||
assert nwGUI.theProject.projTree["73475cb40a568"] is not None
|
||||
|
||||
projFile = os.path.join(nwLipsum, "content", "73475cb40a568.nwd")
|
||||
testFile = os.path.join(outDir, "guiMerge_73475cb40a568.nwd")
|
||||
compFile = os.path.join(refDir, "guiMerge_73475cb40a568.nwd")
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile)
|
||||
|
||||
# Split By Chapter
|
||||
assert nwGUI.treeView.setSelectedHandle("73475cb40a568")
|
||||
qtbot.wait(stepDelay)
|
||||
|
||||
monkeypatch.setattr(GuiDocSplit, "exec_", lambda *args: None)
|
||||
nwGUI.mainMenu.aSplitDoc.activate(QAction.Trigger)
|
||||
qtbot.waitUntil(lambda: getGuiItem("GuiDocSplit") is not None, timeout=1000)
|
||||
|
||||
nwSplit = getGuiItem("GuiDocSplit")
|
||||
assert isinstance(nwSplit, GuiDocSplit)
|
||||
nwSplit.show()
|
||||
qtbot.wait(stepDelay)
|
||||
|
||||
nwSplit.splitLevel.setCurrentIndex(1)
|
||||
qtbot.wait(stepDelay)
|
||||
|
||||
nwSplit._doSplit()
|
||||
assert nwGUI.theProject.projTree["71ee45a3c0db9"] is not None
|
||||
|
||||
# This should give us back the file as it was before
|
||||
projFile = os.path.join(nwLipsum, "content", "71ee45a3c0db9.nwd")
|
||||
testFile = os.path.join(outDir, "guiMerge_71ee45a3c0db9.nwd")
|
||||
compFile = os.path.join(refDir, "guiMerge_73475cb40a568.nwd")
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile, [1, 2, 3])
|
||||
|
||||
# Split By Scene
|
||||
assert nwGUI.treeView.setSelectedHandle("73475cb40a568")
|
||||
qtbot.wait(stepDelay)
|
||||
nwGUI.mainMenu.aSplitDoc.activate(QAction.Trigger)
|
||||
qtbot.waitUntil(lambda: getGuiItem("GuiDocSplit") is not None, timeout=1000)
|
||||
|
||||
nwSplit = getGuiItem("GuiDocSplit")
|
||||
assert isinstance(nwSplit, GuiDocSplit)
|
||||
qtbot.wait(stepDelay)
|
||||
nwSplit.splitLevel.setCurrentIndex(2)
|
||||
qtbot.wait(stepDelay)
|
||||
|
||||
nwSplit._doSplit()
|
||||
|
||||
assert nwGUI.theProject.projTree["25fc0e7096fc6"] is not None
|
||||
assert nwGUI.theProject.projTree["31489056e0916"] is not None
|
||||
assert nwGUI.theProject.projTree["98010bd9270f9"] is not None
|
||||
|
||||
projFile = os.path.join(nwLipsum, "content", "25fc0e7096fc6.nwd")
|
||||
testFile = os.path.join(outDir, "guiSplit_25fc0e7096fc6.nwd")
|
||||
compFile = os.path.join(refDir, "guiSplit_25fc0e7096fc6.nwd")
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile)
|
||||
|
||||
projFile = os.path.join(nwLipsum, "content", "31489056e0916.nwd")
|
||||
testFile = os.path.join(outDir, "guiSplit_31489056e0916.nwd")
|
||||
compFile = os.path.join(refDir, "guiSplit_31489056e0916.nwd")
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile)
|
||||
|
||||
projFile = os.path.join(nwLipsum, "content", "98010bd9270f9.nwd")
|
||||
testFile = os.path.join(outDir, "guiSplit_98010bd9270f9.nwd")
|
||||
compFile = os.path.join(refDir, "guiSplit_98010bd9270f9.nwd")
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile)
|
||||
|
||||
# Split By Section
|
||||
assert nwGUI.treeView.setSelectedHandle("73475cb40a568")
|
||||
qtbot.wait(stepDelay)
|
||||
nwGUI.mainMenu.aSplitDoc.activate(QAction.Trigger)
|
||||
qtbot.waitUntil(lambda: getGuiItem("GuiDocSplit") is not None, timeout=1000)
|
||||
|
||||
nwSplit = getGuiItem("GuiDocSplit")
|
||||
assert isinstance(nwSplit, GuiDocSplit)
|
||||
qtbot.wait(stepDelay)
|
||||
nwSplit.splitLevel.setCurrentIndex(3)
|
||||
qtbot.wait(stepDelay)
|
||||
|
||||
nwSplit._doSplit()
|
||||
|
||||
assert nwGUI.theProject.projTree["1a6562590ef19"] is not None
|
||||
assert nwGUI.theProject.projTree["031b4af5197ec"] is not None
|
||||
assert nwGUI.theProject.projTree["41cfc0d1f2d12"] is not None
|
||||
assert nwGUI.theProject.projTree["2858dcd1057d3"] is not None
|
||||
assert nwGUI.theProject.projTree["2fca346db6561"] is not None
|
||||
|
||||
projFile = os.path.join(nwLipsum, "content", "1a6562590ef19.nwd")
|
||||
testFile = os.path.join(outDir, "guiSplit_1a6562590ef19.nwd")
|
||||
compFile = os.path.join(refDir, "guiSplit_25fc0e7096fc6.nwd")
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile, [1, 2, 3])
|
||||
|
||||
projFile = os.path.join(nwLipsum, "content", "031b4af5197ec.nwd")
|
||||
testFile = os.path.join(outDir, "guiSplit_031b4af5197ec.nwd")
|
||||
compFile = os.path.join(refDir, "guiSplit_031b4af5197ec.nwd")
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile)
|
||||
|
||||
projFile = os.path.join(nwLipsum, "content", "41cfc0d1f2d12.nwd")
|
||||
testFile = os.path.join(outDir, "guiSplit_41cfc0d1f2d12.nwd")
|
||||
compFile = os.path.join(refDir, "guiSplit_41cfc0d1f2d12.nwd")
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile)
|
||||
|
||||
projFile = os.path.join(nwLipsum, "content", "2858dcd1057d3.nwd")
|
||||
testFile = os.path.join(outDir, "guiSplit_2858dcd1057d3.nwd")
|
||||
compFile = os.path.join(refDir, "guiSplit_2858dcd1057d3.nwd")
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile)
|
||||
|
||||
projFile = os.path.join(nwLipsum, "content", "2fca346db6561.nwd")
|
||||
testFile = os.path.join(outDir, "guiSplit_2fca346db6561.nwd")
|
||||
compFile = os.path.join(refDir, "guiSplit_2fca346db6561.nwd")
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile)
|
||||
|
||||
# qtbot.stopForInteraction()
|
||||
|
||||
# END Test testGuiMergeSplit_Tools
|
||||
@@ -1,262 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
novelWriter – Preferences Dialog Class Tester
|
||||
=============================================
|
||||
|
||||
This file is a part of novelWriter
|
||||
Copyright 2018–2021, Veronica Berglyd Olsen
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
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 nw
|
||||
import pytest
|
||||
import os
|
||||
|
||||
from shutil import copyfile
|
||||
from tools import cmpFiles, getGuiItem
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtWidgets import (
|
||||
QDialogButtonBox, QDialog, QAction, QFileDialog, QFontDialog, QMessageBox
|
||||
)
|
||||
|
||||
from nw.gui import GuiPreferences
|
||||
from nw.config import Config
|
||||
from nw.gui.custom import QuotesDialog
|
||||
from nw.constants import nwConst
|
||||
|
||||
keyDelay = 2
|
||||
typeDelay = 1
|
||||
stepDelay = 20
|
||||
|
||||
@pytest.mark.gui
|
||||
def testGuiPreferences_Main(qtbot, monkeypatch, fncDir, outDir, refDir):
|
||||
"""Test the load project wizard.
|
||||
"""
|
||||
# Block message box
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *args: QMessageBox.Yes)
|
||||
monkeypatch.setattr(QMessageBox, "information", lambda *args: QMessageBox.Yes)
|
||||
|
||||
# Must create a clean config and GUI object as the test-wide
|
||||
# nw.CONFIG object is created on import an can be tainted by other tests
|
||||
confFile = os.path.join(fncDir, "novelwriter.conf")
|
||||
if os.path.isfile(confFile):
|
||||
os.unlink(confFile)
|
||||
theConf = Config()
|
||||
theConf.initConfig(fncDir, fncDir)
|
||||
theConf.setLastPath("")
|
||||
origConf = nw.CONFIG
|
||||
nw.CONFIG = theConf
|
||||
|
||||
nwGUI = nw.main(["--testmode", "--config=%s" % fncDir, "--data=%s" % fncDir])
|
||||
qtbot.addWidget(nwGUI)
|
||||
nwGUI.show()
|
||||
qtbot.waitForWindowShown(nwGUI)
|
||||
qtbot.wait(20)
|
||||
|
||||
theConf = nwGUI.mainConf
|
||||
assert theConf.confPath == fncDir
|
||||
theConf.spellTool = nwConst.SP_INTERNAL
|
||||
|
||||
monkeypatch.setattr(GuiPreferences, "exec_", lambda *args: None)
|
||||
monkeypatch.setattr(GuiPreferences, "result", lambda *args: QDialog.Accepted)
|
||||
nwGUI.mainMenu.aPreferences.activate(QAction.Trigger)
|
||||
qtbot.waitUntil(lambda: getGuiItem("GuiPreferences") is not None, timeout=1000)
|
||||
|
||||
nwPrefs = getGuiItem("GuiPreferences")
|
||||
assert isinstance(nwPrefs, GuiPreferences)
|
||||
nwPrefs.show()
|
||||
assert nwPrefs.mainConf.confPath == fncDir
|
||||
|
||||
# General Settings
|
||||
qtbot.wait(keyDelay)
|
||||
tabGeneral = nwPrefs.tabGeneral
|
||||
nwPrefs._tabBox.setCurrentWidget(tabGeneral)
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
assert not tabGeneral.guiDark.isChecked()
|
||||
qtbot.mouseClick(tabGeneral.guiDark, Qt.LeftButton)
|
||||
assert tabGeneral.guiDark.isChecked()
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
assert tabGeneral.showFullPath.isChecked()
|
||||
qtbot.mouseClick(tabGeneral.showFullPath, Qt.LeftButton)
|
||||
assert not tabGeneral.showFullPath.isChecked()
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
assert not tabGeneral.hideVScroll.isChecked()
|
||||
qtbot.mouseClick(tabGeneral.hideVScroll, Qt.LeftButton)
|
||||
assert tabGeneral.hideVScroll.isChecked()
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
assert not tabGeneral.hideHScroll.isChecked()
|
||||
qtbot.mouseClick(tabGeneral.hideHScroll, Qt.LeftButton)
|
||||
assert tabGeneral.hideHScroll.isChecked()
|
||||
|
||||
# Check font button
|
||||
monkeypatch.setattr(QFontDialog, "getFont", lambda font, obj: (font, True))
|
||||
qtbot.mouseClick(tabGeneral.fontButton, Qt.LeftButton)
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
tabGeneral.guiFontSize.setValue(12)
|
||||
|
||||
# Projects Settings
|
||||
qtbot.wait(keyDelay)
|
||||
tabProjects = nwPrefs.tabProjects
|
||||
nwPrefs._tabBox.setCurrentWidget(tabProjects)
|
||||
tabProjects.backupPath = "no/where"
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
assert not tabProjects.backupOnClose.isChecked()
|
||||
qtbot.mouseClick(tabProjects.backupOnClose, Qt.LeftButton)
|
||||
assert tabProjects.backupOnClose.isChecked()
|
||||
|
||||
# qtbot.stopForInteraction()
|
||||
|
||||
# Check Browse button
|
||||
monkeypatch.setattr(QFileDialog, "getExistingDirectory", lambda *args, **kwargs: "")
|
||||
assert not tabProjects._backupFolder()
|
||||
monkeypatch.setattr(QFileDialog, "getExistingDirectory", lambda *args, **kwargs: "some/dir")
|
||||
qtbot.mouseClick(tabProjects.backupGetPath, Qt.LeftButton)
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
tabProjects.autoSaveDoc.setValue(20)
|
||||
tabProjects.autoSaveProj.setValue(40)
|
||||
|
||||
# Document Settings
|
||||
qtbot.wait(keyDelay)
|
||||
tabDocs = nwPrefs.tabDocs
|
||||
nwPrefs._tabBox.setCurrentWidget(tabDocs)
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
qtbot.mouseClick(tabDocs.fontButton, Qt.LeftButton)
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
tabDocs.textSize.setValue(13)
|
||||
tabDocs.textWidth.setValue(700)
|
||||
tabDocs.focusWidth.setValue(900)
|
||||
tabDocs.textMargin.setValue(45)
|
||||
tabDocs.tabWidth.setValue(45)
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
assert not tabDocs.textFixedW.isChecked()
|
||||
qtbot.mouseClick(tabDocs.textFixedW, Qt.LeftButton)
|
||||
assert tabDocs.textFixedW.isChecked()
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
assert not tabDocs.hideFocusFooter.isChecked()
|
||||
qtbot.mouseClick(tabDocs.hideFocusFooter, Qt.LeftButton)
|
||||
assert tabDocs.hideFocusFooter.isChecked()
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
assert not tabDocs.doJustify.isChecked()
|
||||
qtbot.mouseClick(tabDocs.doJustify, Qt.LeftButton)
|
||||
assert tabDocs.doJustify.isChecked()
|
||||
|
||||
# Editor Settings
|
||||
qtbot.wait(keyDelay)
|
||||
tabEditor = nwPrefs.tabEditor
|
||||
nwPrefs._tabBox.setCurrentWidget(tabEditor)
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
assert not tabEditor.showTabsNSpaces.isChecked()
|
||||
qtbot.mouseClick(tabEditor.showTabsNSpaces, Qt.LeftButton)
|
||||
assert tabEditor.showTabsNSpaces.isChecked()
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
assert not tabEditor.showLineEndings.isChecked()
|
||||
qtbot.mouseClick(tabEditor.showLineEndings, Qt.LeftButton)
|
||||
assert tabEditor.showLineEndings.isChecked()
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
assert tabEditor.scrollPastEnd.isChecked()
|
||||
qtbot.mouseClick(tabEditor.scrollPastEnd, Qt.LeftButton)
|
||||
assert not tabEditor.scrollPastEnd.isChecked()
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
assert not tabEditor.autoScroll.isChecked()
|
||||
qtbot.mouseClick(tabEditor.autoScroll, Qt.LeftButton)
|
||||
assert tabEditor.autoScroll.isChecked()
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
tabEditor.bigDocLimit.setValue(500)
|
||||
|
||||
# Syntax Settings
|
||||
qtbot.wait(keyDelay)
|
||||
tabSyntax = nwPrefs.tabSyntax
|
||||
nwPrefs._tabBox.setCurrentWidget(tabSyntax)
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
assert tabSyntax.highlightQuotes.isChecked()
|
||||
qtbot.mouseClick(tabSyntax.highlightQuotes, Qt.LeftButton)
|
||||
assert not tabSyntax.highlightQuotes.isChecked()
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
assert tabSyntax.highlightEmph.isChecked()
|
||||
qtbot.mouseClick(tabSyntax.highlightEmph, Qt.LeftButton)
|
||||
assert not tabSyntax.highlightEmph.isChecked()
|
||||
|
||||
# Automation Settings
|
||||
qtbot.wait(keyDelay)
|
||||
tabAuto = nwPrefs.tabAuto
|
||||
nwPrefs._tabBox.setCurrentWidget(tabAuto)
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
assert tabAuto.autoSelect.isChecked()
|
||||
qtbot.mouseClick(tabAuto.autoSelect, Qt.LeftButton)
|
||||
assert not tabAuto.autoSelect.isChecked()
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
assert tabAuto.doReplace.isChecked()
|
||||
qtbot.mouseClick(tabAuto.doReplace, Qt.LeftButton)
|
||||
assert not tabAuto.doReplace.isChecked()
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
assert not tabAuto.doReplaceSQuote.isEnabled()
|
||||
assert not tabAuto.doReplaceDQuote.isEnabled()
|
||||
assert not tabAuto.doReplaceDash.isEnabled()
|
||||
assert not tabAuto.doReplaceDots.isEnabled()
|
||||
|
||||
# Quotation Style
|
||||
qtbot.wait(keyDelay)
|
||||
tabQuote = nwPrefs.tabQuote
|
||||
nwPrefs._tabBox.setCurrentWidget(tabQuote)
|
||||
|
||||
monkeypatch.setattr(QuotesDialog, "selectedQuote", "'")
|
||||
monkeypatch.setattr(QuotesDialog, "exec_", lambda *args: QDialog.Accepted)
|
||||
qtbot.mouseClick(tabQuote.btnDoubleStyleC, Qt.LeftButton)
|
||||
|
||||
# Save and Check Config
|
||||
qtbot.mouseClick(nwPrefs.buttonBox.button(QDialogButtonBox.Ok), Qt.LeftButton)
|
||||
nwPrefs._doClose()
|
||||
|
||||
assert theConf.confChanged
|
||||
theConf.lastPath = ""
|
||||
|
||||
assert nwGUI.mainConf.saveConfig()
|
||||
projFile = os.path.join(fncDir, "novelwriter.conf")
|
||||
testFile = os.path.join(outDir, "guiPreferences_novelwriter.conf")
|
||||
compFile = os.path.join(refDir, "guiPreferences_novelwriter.conf")
|
||||
copyfile(projFile, testFile)
|
||||
ignoreLines = [2, 9, 10, 13, 14, 15, 16, 17, 18, 19, 20, 7, 30, 31]
|
||||
assert cmpFiles(testFile, compFile, ignoreLines)
|
||||
|
||||
# Clean up
|
||||
nw.CONFIG = origConf
|
||||
nwGUI.closeMain()
|
||||
|
||||
# qtbot.stopForInteraction()
|
||||
|
||||
# END Test testGuiPreferences_Main
|
||||
@@ -1,117 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
novelWriter – Project Load Dialog Class Tester
|
||||
==============================================
|
||||
|
||||
This file is a part of novelWriter
|
||||
Copyright 2018–2021, Veronica Berglyd Olsen
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
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
|
||||
|
||||
from tools import getGuiItem
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtWidgets import (
|
||||
QDialogButtonBox, QTreeWidgetItem, QDialog, QAction, QFileDialog,
|
||||
QMessageBox
|
||||
)
|
||||
|
||||
from nw.gui import GuiProjectLoad
|
||||
|
||||
keyDelay = 2
|
||||
typeDelay = 1
|
||||
stepDelay = 20
|
||||
|
||||
@pytest.mark.gui
|
||||
def testGuiLoadProject_Main(qtbot, monkeypatch, nwGUI, nwMinimal):
|
||||
"""Test the load project wizard.
|
||||
"""
|
||||
# Block message box
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *args: QMessageBox.Yes)
|
||||
|
||||
assert nwGUI.openProject(nwMinimal)
|
||||
assert nwGUI.closeProject()
|
||||
|
||||
qtbot.wait(stepDelay)
|
||||
monkeypatch.setattr(GuiProjectLoad, "exec_", lambda *args: None)
|
||||
monkeypatch.setattr(GuiProjectLoad, "result", lambda *args: QDialog.Accepted)
|
||||
nwGUI.mainMenu.aOpenProject.activate(QAction.Trigger)
|
||||
qtbot.waitUntil(lambda: getGuiItem("GuiProjectLoad") is not None, timeout=1000)
|
||||
|
||||
nwLoad = getGuiItem("GuiProjectLoad")
|
||||
assert isinstance(nwLoad, GuiProjectLoad)
|
||||
nwLoad.show()
|
||||
|
||||
qtbot.wait(stepDelay)
|
||||
recentCount = nwLoad.listBox.topLevelItemCount()
|
||||
assert recentCount > 0
|
||||
|
||||
qtbot.wait(stepDelay)
|
||||
selItem = nwLoad.listBox.topLevelItem(0)
|
||||
selPath = selItem.data(nwLoad.C_NAME, Qt.UserRole)
|
||||
assert isinstance(selItem, QTreeWidgetItem)
|
||||
|
||||
qtbot.wait(stepDelay)
|
||||
nwLoad.selPath.setText("")
|
||||
nwLoad.listBox.setCurrentItem(selItem)
|
||||
nwLoad._doSelectRecent()
|
||||
assert nwLoad.selPath.text() == selPath
|
||||
|
||||
qtbot.wait(stepDelay)
|
||||
qtbot.mouseClick(nwLoad.buttonBox.button(QDialogButtonBox.Open), Qt.LeftButton)
|
||||
assert nwLoad.openPath == selPath
|
||||
assert nwLoad.openState == nwLoad.OPEN_STATE
|
||||
|
||||
# Just create a new project load from scratch for the rest of the test
|
||||
del nwLoad
|
||||
|
||||
qtbot.wait(stepDelay)
|
||||
nwGUI.mainMenu.aOpenProject.activate(QAction.Trigger)
|
||||
qtbot.waitUntil(lambda: getGuiItem("GuiProjectLoad") is not None, timeout=1000)
|
||||
|
||||
qtbot.wait(stepDelay)
|
||||
nwLoad = getGuiItem("GuiProjectLoad")
|
||||
assert isinstance(nwLoad, GuiProjectLoad)
|
||||
nwLoad.show()
|
||||
|
||||
qtbot.wait(stepDelay)
|
||||
qtbot.mouseClick(nwLoad.buttonBox.button(QDialogButtonBox.Cancel), Qt.LeftButton)
|
||||
assert nwLoad.openPath is None
|
||||
assert nwLoad.openState == nwLoad.NONE_STATE
|
||||
|
||||
qtbot.wait(stepDelay)
|
||||
nwLoad.show()
|
||||
qtbot.mouseClick(nwLoad.newButton, Qt.LeftButton)
|
||||
assert nwLoad.openPath is None
|
||||
assert nwLoad.openState == nwLoad.NEW_STATE
|
||||
|
||||
qtbot.wait(stepDelay)
|
||||
nwLoad.show()
|
||||
nwLoad._doDeleteRecent()
|
||||
assert nwLoad.listBox.topLevelItemCount() == recentCount - 1
|
||||
|
||||
getFile = os.path.join(nwMinimal, "nwProject.nwx")
|
||||
monkeypatch.setattr(QFileDialog, "getOpenFileName", lambda *args, **kwargs: (getFile, None))
|
||||
qtbot.mouseClick(nwLoad.browseButton, Qt.LeftButton)
|
||||
assert nwLoad.openPath == nwMinimal
|
||||
assert nwLoad.openState == nwLoad.OPEN_STATE
|
||||
|
||||
nwLoad.close()
|
||||
# qtbot.stopForInteraction()
|
||||
|
||||
# END Test testGuiLoadProject_Main
|
||||
@@ -1,246 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
novelWriter – Project Settings Dialog Class Tester
|
||||
==================================================
|
||||
|
||||
This file is a part of novelWriter
|
||||
Copyright 2018–2021, Veronica Berglyd Olsen
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
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
|
||||
|
||||
from shutil import copyfile
|
||||
from tools import cmpFiles, getGuiItem
|
||||
|
||||
from PyQt5.QtGui import QColor
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtWidgets import (
|
||||
QDialog, QAction, QMessageBox, QColorDialog, QTreeWidgetItem
|
||||
)
|
||||
|
||||
from nw.gui import GuiProjectSettings
|
||||
|
||||
keyDelay = 2
|
||||
typeDelay = 1
|
||||
stepDelay = 20
|
||||
|
||||
@pytest.mark.gui
|
||||
def testGuiProjSettings_Dialog(qtbot, monkeypatch, nwGUI, fncDir, fncProj, outDir, refDir):
|
||||
"""Test the full project settings dialog.
|
||||
"""
|
||||
projFile = os.path.join(fncProj, "nwProject.nwx")
|
||||
testFile = os.path.join(outDir, "guiProjSettings_Dialog_nwProject.nwx")
|
||||
compFile = os.path.join(refDir, "guiProjSettings_Dialog_nwProject.nwx")
|
||||
|
||||
# Block message box
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *args: QMessageBox.Yes)
|
||||
monkeypatch.setattr(QMessageBox, "critical", lambda *args: QMessageBox.Yes)
|
||||
|
||||
# Check that we cannot open when there is no project
|
||||
nwGUI.mainMenu.aProjectSettings.activate(QAction.Trigger)
|
||||
assert getGuiItem("GuiProjectSettings") is None
|
||||
|
||||
# Create new project
|
||||
nwGUI.theProject.projTree.setSeed(42)
|
||||
assert nwGUI.newProject({"projPath": fncProj})
|
||||
nwGUI.mainConf.backupPath = fncDir
|
||||
|
||||
nwGUI.theProject.setSpellLang("en")
|
||||
nwGUI.theProject.setBookAuthors("Jane Smith\nJohn Smith")
|
||||
nwGUI.theProject.setAutoReplace({"A": "B", "C": "D"})
|
||||
|
||||
# Get the dialog object
|
||||
monkeypatch.setattr(GuiProjectSettings, "exec_", lambda *args: None)
|
||||
monkeypatch.setattr(GuiProjectSettings, "result", lambda *args: QDialog.Accepted)
|
||||
nwGUI.mainMenu.aProjectSettings.activate(QAction.Trigger)
|
||||
qtbot.waitUntil(lambda: getGuiItem("GuiProjectSettings") is not None, timeout=1000)
|
||||
|
||||
projEdit = getGuiItem("GuiProjectSettings")
|
||||
assert isinstance(projEdit, GuiProjectSettings)
|
||||
projEdit.show()
|
||||
qtbot.addWidget(projEdit)
|
||||
|
||||
# Settings Tab
|
||||
# ============
|
||||
|
||||
assert projEdit.tabMain.editName.text() == "New Project"
|
||||
assert projEdit.tabMain.editTitle.text() == ""
|
||||
assert projEdit.tabMain.editAuthors.toPlainText() == "Jane Smith\nJohn Smith"
|
||||
assert projEdit.tabMain.spellLang.currentData() == "en"
|
||||
assert projEdit.tabMain.doBackup.isChecked() is False
|
||||
|
||||
qtbot.wait(stepDelay)
|
||||
projEdit.tabMain.editName.setText("")
|
||||
for c in "Project Name":
|
||||
qtbot.keyClick(projEdit.tabMain.editName, c, delay=typeDelay)
|
||||
for c in "Project Title":
|
||||
qtbot.keyClick(projEdit.tabMain.editTitle, c, delay=typeDelay)
|
||||
|
||||
projEdit.tabMain.editAuthors.clear()
|
||||
for c in "Jane Doe":
|
||||
qtbot.keyClick(projEdit.tabMain.editAuthors, c, delay=typeDelay)
|
||||
qtbot.keyClick(projEdit.tabMain.editAuthors, Qt.Key_Return, delay=keyDelay)
|
||||
for c in "John Doh":
|
||||
qtbot.keyClick(projEdit.tabMain.editAuthors, c, delay=typeDelay)
|
||||
qtbot.keyClick(projEdit.tabMain.editAuthors, Qt.Key_Return, delay=keyDelay)
|
||||
|
||||
qtbot.wait(stepDelay)
|
||||
assert projEdit.tabMain.editName.text() == "Project Name"
|
||||
assert projEdit.tabMain.editTitle.text() == "Project Title"
|
||||
assert projEdit.tabMain.editAuthors.toPlainText() == "Jane Doe\nJohn Doh\n"
|
||||
|
||||
# Status Tab
|
||||
# ==========
|
||||
|
||||
projEdit._tabBox.setCurrentWidget(projEdit.tabStatus)
|
||||
|
||||
assert projEdit.tabStatus.colChanged is False
|
||||
assert projEdit.tabStatus.getNewList() is None
|
||||
assert projEdit.tabStatus.listBox.topLevelItemCount() == 4
|
||||
|
||||
# Fake drag'n'drop should change changed status
|
||||
projEdit.tabStatus._rowsMoved()
|
||||
assert projEdit.tabStatus.colChanged is True
|
||||
projEdit.tabStatus.colChanged = False
|
||||
|
||||
projEdit.tabStatus.listBox.clearSelection()
|
||||
assert projEdit.tabStatus._getSelectedItem() is None
|
||||
projEdit.tabStatus.listBox.topLevelItem(0).setSelected(True)
|
||||
assert isinstance(projEdit.tabStatus._getSelectedItem(), QTreeWidgetItem)
|
||||
|
||||
# Can't delete the first item (it's in use)
|
||||
projEdit.tabStatus.listBox.clearSelection()
|
||||
projEdit.tabStatus.listBox.topLevelItem(0).setSelected(True)
|
||||
qtbot.mouseClick(projEdit.tabStatus.delButton, Qt.LeftButton)
|
||||
assert projEdit.tabStatus.listBox.topLevelItemCount() == 4
|
||||
|
||||
# Can delete the third item
|
||||
projEdit.tabStatus.listBox.clearSelection()
|
||||
projEdit.tabStatus.listBox.topLevelItem(2).setSelected(True)
|
||||
qtbot.mouseClick(projEdit.tabStatus.delButton, Qt.LeftButton)
|
||||
assert projEdit.tabStatus.listBox.topLevelItemCount() == 3
|
||||
|
||||
# Add a new item
|
||||
monkeypatch.setattr(QColorDialog, "getColor", lambda *args: QColor(20, 30, 40))
|
||||
qtbot.mouseClick(projEdit.tabStatus.addButton, Qt.LeftButton)
|
||||
projEdit.tabStatus.listBox.topLevelItem(3).setSelected(True)
|
||||
for n in range(8):
|
||||
qtbot.keyClick(projEdit.tabStatus.editName, Qt.Key_Backspace, delay=typeDelay)
|
||||
for c in "Final":
|
||||
qtbot.keyClick(projEdit.tabStatus.editName, c, delay=typeDelay)
|
||||
qtbot.mouseClick(projEdit.tabStatus.colButton, Qt.LeftButton)
|
||||
qtbot.mouseClick(projEdit.tabStatus.saveButton, Qt.LeftButton)
|
||||
assert projEdit.tabStatus.listBox.topLevelItemCount() == 4
|
||||
qtbot.wait(stepDelay)
|
||||
|
||||
assert projEdit.tabStatus.colChanged is True
|
||||
assert projEdit.tabStatus.getNewList() == [
|
||||
("New", 100, 100, 100, "New"),
|
||||
("Note", 200, 50, 0, "Note"),
|
||||
("Finished", 50, 200, 0, "Finished"),
|
||||
("Final", 20, 30, 40, None)
|
||||
]
|
||||
|
||||
# Importance Tab
|
||||
# ==============
|
||||
|
||||
projEdit._tabBox.setCurrentWidget(projEdit.tabImport)
|
||||
projEdit.tabStatus.listBox.clearSelection()
|
||||
projEdit.tabImport.listBox.topLevelItem(3).setSelected(True)
|
||||
qtbot.mouseClick(projEdit.tabImport.delButton, Qt.LeftButton)
|
||||
qtbot.mouseClick(projEdit.tabImport.addButton, Qt.LeftButton)
|
||||
projEdit.tabStatus.listBox.clearSelection()
|
||||
projEdit.tabImport.listBox.topLevelItem(3).setSelected(True)
|
||||
for n in range(8):
|
||||
qtbot.keyClick(projEdit.tabImport.editName, Qt.Key_Backspace, delay=typeDelay)
|
||||
for c in "Final":
|
||||
qtbot.keyClick(projEdit.tabImport.editName, c, delay=typeDelay)
|
||||
qtbot.mouseClick(projEdit.tabImport.saveButton, Qt.LeftButton)
|
||||
qtbot.wait(stepDelay)
|
||||
|
||||
# Auto-Replace Tab
|
||||
# ================
|
||||
|
||||
qtbot.wait(stepDelay)
|
||||
projEdit._tabBox.setCurrentWidget(projEdit.tabReplace)
|
||||
|
||||
assert projEdit.tabReplace.listBox.topLevelItem(0).text(0) == "<A>"
|
||||
assert projEdit.tabReplace.listBox.topLevelItem(0).text(1) == "B"
|
||||
assert projEdit.tabReplace.listBox.topLevelItem(1).text(0) == "<C>"
|
||||
assert projEdit.tabReplace.listBox.topLevelItem(1).text(1) == "D"
|
||||
|
||||
qtbot.mouseClick(projEdit.tabReplace.addButton, Qt.LeftButton)
|
||||
projEdit.tabReplace.listBox.topLevelItem(2).setSelected(True)
|
||||
projEdit.tabReplace.editKey.setText("")
|
||||
for c in "Th is ":
|
||||
qtbot.keyClick(projEdit.tabReplace.editKey, c, delay=typeDelay)
|
||||
projEdit.tabReplace.editValue.setText("")
|
||||
for c in "With This Stuff ":
|
||||
qtbot.keyClick(projEdit.tabReplace.editValue, c, delay=typeDelay)
|
||||
qtbot.mouseClick(projEdit.tabReplace.saveButton, Qt.LeftButton)
|
||||
|
||||
qtbot.wait(stepDelay)
|
||||
projEdit.tabReplace.listBox.clearSelection()
|
||||
assert not projEdit.tabReplace._saveEntry()
|
||||
assert not projEdit.tabReplace._delEntry()
|
||||
qtbot.mouseClick(projEdit.tabReplace.addButton, Qt.LeftButton)
|
||||
|
||||
newIdx = -1
|
||||
for i in range(projEdit.tabReplace.listBox.topLevelItemCount()):
|
||||
if projEdit.tabReplace.listBox.topLevelItem(i).text(0) == "<keyword4>":
|
||||
newIdx = i
|
||||
break
|
||||
|
||||
assert newIdx >= 0
|
||||
newItem = projEdit.tabReplace.listBox.topLevelItem(newIdx)
|
||||
projEdit.tabReplace.listBox.setCurrentItem(newItem)
|
||||
qtbot.mouseClick(projEdit.tabReplace.delButton, Qt.LeftButton)
|
||||
qtbot.wait(stepDelay)
|
||||
|
||||
# Save & Check
|
||||
# ============
|
||||
|
||||
projEdit._doSave()
|
||||
|
||||
# Open again, and check project settings
|
||||
nwGUI.mainMenu.aProjectSettings.activate(QAction.Trigger)
|
||||
qtbot.waitUntil(lambda: getGuiItem("GuiProjectSettings") is not None, timeout=1000)
|
||||
|
||||
projEdit = getGuiItem("GuiProjectSettings")
|
||||
assert isinstance(projEdit, GuiProjectSettings)
|
||||
|
||||
qtbot.addWidget(projEdit)
|
||||
assert projEdit.tabMain.editName.text() == "Project Name"
|
||||
assert projEdit.tabMain.editTitle.text() == "Project Title"
|
||||
theAuth = projEdit.tabMain.editAuthors.toPlainText().strip().splitlines()
|
||||
assert len(theAuth) == 2
|
||||
assert theAuth[0] == "Jane Doe"
|
||||
assert theAuth[1] == "John Doh"
|
||||
|
||||
projEdit._doClose()
|
||||
qtbot.wait(stepDelay)
|
||||
|
||||
assert nwGUI.saveProject()
|
||||
qtbot.wait(stepDelay)
|
||||
|
||||
# Check the files
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile, [2, 8, 9, 10])
|
||||
|
||||
# qtbot.stopForInteraction()
|
||||
|
||||
# END Test testGuiProjSettings_Dialog
|
||||
@@ -1,133 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
novelWriter – Other Dialog Classes Tester
|
||||
=========================================
|
||||
|
||||
This file is a part of novelWriter
|
||||
Copyright 2018–2021, Veronica Berglyd Olsen
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
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 os
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtWidgets import QDialog, QMessageBox, QAction
|
||||
|
||||
from tools import writeFile, readFile, getGuiItem
|
||||
from dummy import causeOSError
|
||||
|
||||
from nw.gui.wordlist import GuiWordList
|
||||
from nw.constants import nwFiles
|
||||
|
||||
keyDelay = 2
|
||||
typeDelay = 1
|
||||
stepDelay = 20
|
||||
|
||||
def testGuiWordList_Dialog(qtbot, monkeypatch, nwGUI, nwMinimal, tmpDir):
|
||||
"""test the word list editor.
|
||||
"""
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *args: QMessageBox.Yes)
|
||||
monkeypatch.setattr(QMessageBox, "critical", lambda *args: QMessageBox.Yes)
|
||||
monkeypatch.setattr(GuiWordList, "exec_", lambda *args: None)
|
||||
monkeypatch.setattr(GuiWordList, "result", lambda *args: QDialog.Accepted)
|
||||
monkeypatch.setattr(GuiWordList, "accept", lambda *args: None)
|
||||
|
||||
# Open project
|
||||
nwGUI.openProject(nwMinimal)
|
||||
qtbot.wait(stepDelay)
|
||||
dictFile = os.path.join(nwMinimal, "meta", nwFiles.PROJ_DICT)
|
||||
|
||||
# Load the dialog
|
||||
nwGUI.mainMenu.aEditWordList.activate(QAction.Trigger)
|
||||
qtbot.waitUntil(lambda: getGuiItem("GuiWordList") is not None, timeout=1000)
|
||||
|
||||
wList = getGuiItem("GuiWordList")
|
||||
assert isinstance(wList, GuiWordList)
|
||||
wList.show()
|
||||
qtbot.wait(stepDelay)
|
||||
|
||||
# List should be blank
|
||||
assert wList.listBox.count() == 0
|
||||
|
||||
# Add words
|
||||
writeFile(dictFile, (
|
||||
"word_a\n"
|
||||
"word_c\n"
|
||||
"word_g\n"
|
||||
" \n" # Should be ignored
|
||||
"word_f\n"
|
||||
"word_b\n"
|
||||
))
|
||||
qtbot.wait(stepDelay)
|
||||
assert wList._loadWordList()
|
||||
|
||||
# Check that the content was loaded
|
||||
assert wList.listBox.item(0).text() == "word_a"
|
||||
assert wList.listBox.item(1).text() == "word_b"
|
||||
assert wList.listBox.item(2).text() == "word_c"
|
||||
assert wList.listBox.item(3).text() == "word_f"
|
||||
assert wList.listBox.item(4).text() == "word_g"
|
||||
|
||||
# Add a blank word
|
||||
wList.newEntry.setText(" ")
|
||||
assert not wList._doAdd()
|
||||
|
||||
# Add an existing word
|
||||
wList.newEntry.setText("word_c")
|
||||
assert not wList._doAdd()
|
||||
|
||||
# Add a new word
|
||||
wList.newEntry.setText("word_d")
|
||||
assert wList._doAdd()
|
||||
|
||||
# Check that the content now
|
||||
assert wList.listBox.item(0).text() == "word_a"
|
||||
assert wList.listBox.item(1).text() == "word_b"
|
||||
assert wList.listBox.item(2).text() == "word_c"
|
||||
assert wList.listBox.item(3).text() == "word_d"
|
||||
assert wList.listBox.item(4).text() == "word_f"
|
||||
assert wList.listBox.item(5).text() == "word_g"
|
||||
|
||||
# Delete a word
|
||||
wList.newEntry.setText("delete_me")
|
||||
assert wList._doAdd()
|
||||
assert wList.listBox.item(0).text() == "delete_me"
|
||||
|
||||
delItem = wList.listBox.findItems("delete_me", Qt.MatchExactly)[0]
|
||||
assert delItem.text() == "delete_me"
|
||||
delItem.setSelected(True)
|
||||
wList._doDelete()
|
||||
assert wList.listBox.findItems("delete_me", Qt.MatchExactly) == []
|
||||
assert wList.listBox.item(0).text() == "word_a"
|
||||
|
||||
# Save files
|
||||
assert wList._doSave()
|
||||
assert readFile(dictFile) == (
|
||||
"word_a\n"
|
||||
"word_b\n"
|
||||
"word_c\n"
|
||||
"word_d\n"
|
||||
"word_f\n"
|
||||
"word_g\n"
|
||||
)
|
||||
|
||||
# Save again and make it fail
|
||||
monkeypatch.setattr("builtins.open", causeOSError)
|
||||
assert not wList._doSave()
|
||||
|
||||
# qtbot.stopForInteraction()
|
||||
wList._doClose()
|
||||
|
||||
# END Test testGuiWordList_Dialog
|
||||
Reference in New Issue
Block a user