Rename package from 'nw' to 'novelwriter' (#868)

* Rename nw folder to novelwriter
* Rename nw to novelwriter in auxiliary files
* Rename nw to novelwriter in main app source
* Rename nw to novelwriter in tests
* Make setup script for pdf docs less spammy
This commit is contained in:
Veronica Berglyd Olsen
2021-08-26 17:33:54 +02:00
committed by GitHub
parent 2cf2eb9f55
commit 3403d98c72
396 changed files with 595 additions and 566 deletions
+4 -4
View File
@@ -37,7 +37,7 @@ xvfb-run pytest-3 -v
To add test coverage, run the following:
```bash
pytest-3 -v --cov=nw --cov-report=html
pytest-3 -v --cov=novelwriter --cov-report=html
```
The `--cov-report` switch generates an html report, omit it to print a coverage summary to the
@@ -52,9 +52,9 @@ pytest-3 -v -m core
Available markers are:
* `base` for unit tests covering the non-gui classes of the `nw` folder..
* `core` for unit tests covering the classes in the `nw/core` folder.
* `gui` for unit and integrations tests covering the classes in the `nw/gui` folder.
* `base` for unit tests covering the non-gui classes of the `novelwriter` folder..
* `core` for unit tests covering the classes in the `novelwriter/core` folder.
* `gui` for unit and integrations tests covering the classes in the `novelwriter/gui` folder.
You can filter tests further with the `-k` switch, all the way down to a single test. You can for
+6 -6
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 os
import sys
import pytest
import shutil
import os
from mock import MockGuiMain
from tools import cleanProject
sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
import nw # noqa: E402
import novelwriter # noqa: E402
from PyQt5.QtWidgets import QMessageBox # noqa: E402
from nw.config import Config # noqa: E402
from novelwriter.config import Config # noqa: E402
##
@@ -145,7 +145,7 @@ def fncConf(fncDir):
def mockGUI(monkeypatch, tmpConf):
"""Create a mock instance of novelWriter's main GUI class.
"""
monkeypatch.setattr("nw.CONFIG", tmpConf)
monkeypatch.setattr("novelwriter.CONFIG", tmpConf)
theGui = MockGuiMain()
theGui.mainConf = tmpConf
return theGui
@@ -156,8 +156,8 @@ def nwGUI(qtbot, monkeypatch, fncDir, fncConf):
"""Create an instance of the novelWriter GUI.
"""
monkeypatch.setattr(QMessageBox, "warning", lambda *a: QMessageBox.Yes)
monkeypatch.setattr("nw.CONFIG", fncConf)
nwGUI = nw.main(["--testmode", "--config=%s" % fncDir, "--data=%s" % fncDir])
monkeypatch.setattr("novelwriter.CONFIG", fncConf)
nwGUI = novelwriter.main(["--testmode", "--config=%s" % fncDir, "--data=%s" % fncDir])
qtbot.addWidget(nwGUI)
nwGUI.show()
qtbot.wait(20)
+1 -1
View File
@@ -27,7 +27,7 @@ from datetime import datetime
from tools import writeFile
from nw.common import (
from novelwriter.common import (
checkString, checkInt, checkBool, checkHandle, isHandle, isTitleTag,
isItemClass, isItemType, isItemLayout, hexToInt, formatInt,
formatTimeStamp, formatTime, parseTimeStamp, splitVersionNumber,
+2 -2
View File
@@ -28,8 +28,8 @@ from shutil import copyfile
from mock import causeOSError, MockApp
from tools import cmpFiles, writeFile
from nw.config import Config
from nw.constants import nwConst, nwFiles
from novelwriter.config import Config
from novelwriter.constants import nwConst, nwFiles
@pytest.mark.base
+4 -4
View File
@@ -19,14 +19,14 @@ 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 novelwriter
from PyQt5.QtWidgets import QMessageBox, qApp
from mock import causeException
from nw.error import NWErrorMessage, exceptionHandler
from novelwriter.error import NWErrorMessage, exceptionHandler
@pytest.mark.base
@@ -37,7 +37,7 @@ def testBaseError_Dialog(qtbot, monkeypatch, fncDir, tmpDir):
monkeypatch.setattr(QMessageBox, "warning", lambda *a: QMessageBox.Yes)
qApp.closeAllWindows()
nwGUI = nw.main(["--testmode", "--config=%s" % fncDir, "--data=%s" % tmpDir])
nwGUI = novelwriter.main(["--testmode", "--config=%s" % fncDir, "--data=%s" % tmpDir])
qtbot.addWidget(nwGUI)
nwGUI.show()
qtbot.wait(20)
@@ -84,7 +84,7 @@ def testBaseError_Handler(qtbot, monkeypatch, fncDir, tmpDir):
monkeypatch.setattr(QMessageBox, "warning", lambda *a: QMessageBox.Yes)
qApp.closeAllWindows()
nwGUI = nw.main(["--testmode", "--config=%s" % fncDir, "--data=%s" % tmpDir])
nwGUI = novelwriter.main(["--testmode", "--config=%s" % fncDir, "--data=%s" % tmpDir])
qtbot.addWidget(nwGUI)
nwGUI.show()
qtbot.wait(20)
+38 -38
View File
@@ -19,10 +19,10 @@ 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 sys
import pytest
import logging
import sys
import novelwriter
from mock import MockGuiMain
@@ -31,37 +31,37 @@ from mock import MockGuiMain
def testBaseInit_Launch(caplog, monkeypatch, tmpDir):
"""Check launching the main GUI.
"""
monkeypatch.setattr("nw.guimain.GuiMain", MockGuiMain)
monkeypatch.setattr("novelwriter.guimain.GuiMain", MockGuiMain)
# TestMode Launch
nwGUI = nw.main(["--testmode", "--config=%s" % tmpDir, "--data=%s" % tmpDir])
nwGUI = novelwriter.main(["--testmode", "--config=%s" % tmpDir, "--data=%s" % tmpDir])
assert isinstance(nwGUI, MockGuiMain)
# Darwin Launch
caplog.clear()
osDarwin = nw.CONFIG.osDarwin
nw.CONFIG.osDarwin = True
osDarwin = novelwriter.CONFIG.osDarwin
novelwriter.CONFIG.osDarwin = True
with monkeypatch.context() as mp:
mp.setitem(sys.modules, "Foundation", None)
nwGUI = nw.main(["--testmode", "--config=%s" % tmpDir, "--data=%s" % tmpDir])
nwGUI = novelwriter.main(["--testmode", "--config=%s" % tmpDir, "--data=%s" % tmpDir])
assert isinstance(nwGUI, MockGuiMain)
assert "Failed" in caplog.text
nw.CONFIG.osDarwin = osDarwin
novelwriter.CONFIG.osDarwin = osDarwin
# Windows Launch
caplog.clear()
osWindows = nw.CONFIG.osWindows
nw.CONFIG.osWindows = True
osWindows = novelwriter.CONFIG.osWindows
novelwriter.CONFIG.osWindows = True
with monkeypatch.context() as mp:
mp.setitem(sys.modules, "ctypes", None)
nwGUI = nw.main(["--testmode", "--config=%s" % tmpDir, "--data=%s" % tmpDir])
nwGUI = novelwriter.main(["--testmode", "--config=%s" % tmpDir, "--data=%s" % tmpDir])
assert isinstance(nwGUI, MockGuiMain)
if not sys.platform.startswith("darwin"):
# For some reason, the test doesn't work on macOS
assert "Failed" in caplog.text
nw.CONFIG.osWindows = osWindows
novelwriter.CONFIG.osWindows = osWindows
# Normal Launch
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.__init__", lambda *a: None)
@@ -71,7 +71,7 @@ def testBaseInit_Launch(caplog, monkeypatch, tmpDir):
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.setOrganizationDomain", lambda *a: None)
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.exec_", lambda *a: 0)
with pytest.raises(SystemExit) as ex:
nw.main(["--config=%s" % tmpDir, "--data=%s" % tmpDir])
novelwriter.main(["--config=%s" % tmpDir, "--data=%s" % tmpDir])
assert ex.value.code == 0
# END Test testBaseInit_Launch
@@ -81,52 +81,52 @@ def testBaseInit_Launch(caplog, monkeypatch, tmpDir):
def testBaseInit_Options(monkeypatch, tmpDir):
"""Test command line options for logging level.
"""
monkeypatch.setattr("nw.guimain.GuiMain", MockGuiMain)
monkeypatch.setattr("novelwriter.guimain.GuiMain", MockGuiMain)
monkeypatch.setattr(sys, "argv", [
"novelWriter.py", "--testmode", "--config=%s" % tmpDir, "--data=%s" % tmpDir
])
# Defaults w/None Args
nwGUI = nw.main()
assert nw.logger.getEffectiveLevel() == logging.WARNING
nwGUI = novelwriter.main()
assert novelwriter.logger.getEffectiveLevel() == logging.WARNING
assert nwGUI.closeMain() == "closeMain"
# Defaults
nwGUI = nw.main(
nwGUI = novelwriter.main(
["--testmode", "--config=%s" % tmpDir, "--data=%s" % tmpDir, "--style=Fusion"]
)
assert nw.logger.getEffectiveLevel() == logging.WARNING
assert novelwriter.logger.getEffectiveLevel() == logging.WARNING
assert nwGUI.closeMain() == "closeMain"
# Log Levels
nwGUI = nw.main(
nwGUI = novelwriter.main(
["--testmode", "--info", "--config=%s" % tmpDir, "--data=%s" % tmpDir]
)
assert nw.logger.getEffectiveLevel() == logging.INFO
assert novelwriter.logger.getEffectiveLevel() == logging.INFO
assert nwGUI.closeMain() == "closeMain"
nwGUI = nw.main(
nwGUI = novelwriter.main(
["--testmode", "--debug", "--config=%s" % tmpDir, "--data=%s" % tmpDir]
)
assert nw.logger.getEffectiveLevel() == logging.DEBUG
assert novelwriter.logger.getEffectiveLevel() == logging.DEBUG
assert nwGUI.closeMain() == "closeMain"
nwGUI = nw.main(
nwGUI = novelwriter.main(
["--testmode", "--verbose", "--config=%s" % tmpDir, "--data=%s" % tmpDir]
)
assert nw.logger.getEffectiveLevel() == 5
assert novelwriter.logger.getEffectiveLevel() == 5
assert nwGUI.closeMain() == "closeMain"
# Help and Version
with pytest.raises(SystemExit) as ex:
nwGUI = nw.main(
nwGUI = novelwriter.main(
["--testmode", "--help", "--config=%s" % tmpDir, "--data=%s" % tmpDir]
)
assert nwGUI.closeMain() == "closeMain"
assert ex.value.code == 0
with pytest.raises(SystemExit) as ex:
nwGUI = nw.main(
nwGUI = novelwriter.main(
["--testmode", "--version", "--config=%s" % tmpDir, "--data=%s" % tmpDir]
)
assert nwGUI.closeMain() == "closeMain"
@@ -134,17 +134,17 @@ def testBaseInit_Options(monkeypatch, tmpDir):
# Invalid options
with pytest.raises(SystemExit) as ex:
nwGUI = nw.main(
nwGUI = novelwriter.main(
["--testmode", "--invalid", "--config=%s" % tmpDir, "--data=%s" % tmpDir]
)
assert nwGUI.closeMain() == "closeMain"
assert ex.value.code == 2
# Project Path
nwGUI = nw.main(
nwGUI = novelwriter.main(
["--testmode", "--config=%s" % tmpDir, "--data=%s" % tmpDir, "sample/"]
)
assert nw.CONFIG.cmdOpen == "sample/"
assert novelwriter.CONFIG.cmdOpen == "sample/"
assert nwGUI.closeMain() == "closeMain"
# END Test testBaseInit_Options
@@ -154,19 +154,19 @@ def testBaseInit_Options(monkeypatch, tmpDir):
def testBaseInit_Imports(caplog, monkeypatch, tmpDir):
"""Check import error handling.
"""
monkeypatch.setattr("nw.guimain.GuiMain", MockGuiMain)
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.__init__", lambda *args: None)
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.exec_", lambda *args: 0)
monkeypatch.setattr("PyQt5.QtWidgets.QErrorMessage.__init__", lambda *args: None)
monkeypatch.setattr("PyQt5.QtWidgets.QErrorMessage.resize", lambda *args: None)
monkeypatch.setattr("PyQt5.QtWidgets.QErrorMessage.showMessage", lambda *args: None)
monkeypatch.setattr("novelwriter.guimain.GuiMain", MockGuiMain)
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.__init__", lambda *a: None)
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.exec_", lambda *a: 0)
monkeypatch.setattr("PyQt5.QtWidgets.QErrorMessage.__init__", lambda *a: None)
monkeypatch.setattr("PyQt5.QtWidgets.QErrorMessage.resize", lambda *a: None)
monkeypatch.setattr("PyQt5.QtWidgets.QErrorMessage.showMessage", lambda *a: None)
monkeypatch.setitem(sys.modules, "lxml", None)
monkeypatch.setattr("sys.hexversion", 0x0)
monkeypatch.setattr("nw.CONFIG.verQtValue", 50000)
monkeypatch.setattr("nw.CONFIG.verPyQtValue", 50000)
monkeypatch.setattr("novelwriter.CONFIG.verQtValue", 50000)
monkeypatch.setattr("novelwriter.CONFIG.verPyQtValue", 50000)
with pytest.raises(SystemExit) as ex:
_ = nw.main(
_ = novelwriter.main(
["--testmode", "--config=%s" % tmpDir, "--data=%s" % tmpDir]
)
+2 -2
View File
@@ -25,8 +25,8 @@ import pytest
from mock import causeOSError
from tools import readFile
from nw.core import NWProject, NWDoc
from nw.enum import nwItemClass, nwItemLayout
from novelwriter.core import NWProject, NWDoc
from novelwriter.enum import nwItemClass, nwItemLayout
@pytest.mark.core
+3 -3
View File
@@ -28,9 +28,9 @@ from shutil import copyfile
from mock import causeException
from tools import cmpFiles
from nw.core.project import NWProject
from nw.core.index import NWIndex, countWords
from nw.enum import nwItemClass, nwItemLayout
from novelwriter.core.project import NWProject
from novelwriter.core.index import NWIndex, countWords
from novelwriter.enum import nwItemClass, nwItemLayout
@pytest.mark.core
+3 -3
View File
@@ -23,9 +23,9 @@ import pytest
from lxml import etree
from nw.core import NWProject
from nw.core.item import NWItem
from nw.enum import nwItemClass, nwItemType, nwItemLayout
from novelwriter.core import NWProject
from novelwriter.core.item import NWItem
from novelwriter.enum import nwItemClass, nwItemType, nwItemLayout
@pytest.mark.core
+3 -3
View File
@@ -26,9 +26,9 @@ import pytest
from mock import causeOSError
from tools import writeFile
from nw.core import NWProject
from nw.core.options import OptionState
from nw.constants import nwFiles
from novelwriter.core import NWProject
from novelwriter.core.options import OptionState
from novelwriter.constants import nwFiles
@pytest.mark.core
+8 -8
View File
@@ -29,10 +29,10 @@ from lxml import etree
from tools import cmpFiles, writeFile, readFile
from mock import causeOSError
from nw.core.project import NWProject
from nw.enum import nwItemClass, nwItemType, nwItemLayout
from nw.common import formatTimeStamp
from nw.constants import nwFiles
from novelwriter.core.project import NWProject
from novelwriter.enum import nwItemClass, nwItemType, nwItemLayout
from novelwriter.common import formatTimeStamp
from novelwriter.constants import nwFiles
@pytest.mark.core
@@ -234,7 +234,7 @@ def testCoreProject_NewSampleB(monkeypatch, fncDir, tmpConf, mockGUI, tmpDir):
theProject = NWProject(mockGUI)
theProject.projTree.setSeed(42)
# Make sure we do not pick up the nw/assets/sample.zip file
# Make sure we do not pick up the novelwriter/assets/sample.zip file
tmpConf.assetPath = tmpDir
# Set a fake project file name
@@ -531,7 +531,7 @@ def testCoreProject_LockFile(monkeypatch, fncDir, mockGUI):
# Write lock file
with monkeypatch.context() as mp:
mp.setattr("nw.core.project.time", lambda: 123.4)
mp.setattr("novelwriter.core.project.time", lambda: 123.4)
assert theProject._writeLockFile() is True
assert readFile(lockFile) == "TestHost\nTestOS\n1.0\n123\n"
@@ -730,7 +730,7 @@ def testCoreProject_Methods(monkeypatch, nwMinimal, mockGUI, tmpDir):
theProject.editTime = 1234
theProject.projOpened = 1600000000
with monkeypatch.context() as mp:
mp.setattr("nw.core.project.time", lambda: 1600005600)
mp.setattr("novelwriter.core.project.time", lambda: 1600005600)
assert theProject.getCurrentEditTime() == 6834
# Trash folder
@@ -892,7 +892,7 @@ def testCoreProject_Methods(monkeypatch, nwMinimal, mockGUI, tmpDir):
theProject.notesWCount = 100
with monkeypatch.context() as mp:
mp.setattr("nw.core.project.time", lambda: 1600005600)
mp.setattr("novelwriter.core.project.time", lambda: 1600005600)
assert theProject._appendSessionStats(idleTime=99)
assert readFile(statsFile) == (
+3 -1
View File
@@ -26,7 +26,9 @@ import pytest
from mock import causeOSError
from tools import readFile, writeFile
from nw.core.spellcheck import NWSpellCheck, NWSpellEnchant, NWSpellSimple
from novelwriter.core.spellcheck import (
NWSpellCheck, NWSpellEnchant, NWSpellSimple
)
@pytest.mark.core
+1 -1
View File
@@ -23,7 +23,7 @@ import pytest
from lxml import etree
from nw.core.status import NWStatus
from novelwriter.core.status import NWStatus
@pytest.mark.core
+1 -1
View File
@@ -24,7 +24,7 @@ import pytest
from tools import readFile
from nw.core import NWProject, NWIndex, ToHtml
from novelwriter.core import NWProject, NWIndex, ToHtml
@pytest.mark.core
+3 -3
View File
@@ -24,8 +24,8 @@ import pytest
from tools import readFile
from nw.core import NWProject, NWDoc
from nw.core.tokenizer import Tokenizer
from novelwriter.core import NWProject, NWDoc
from novelwriter.core.tokenizer import Tokenizer
@pytest.mark.core
@@ -183,7 +183,7 @@ def testCoreToken_TextOps(monkeypatch, nwMinimal, mockGUI):
assert theToken.theText == docText
with monkeypatch.context() as mp:
mp.setattr("nw.constants.nwConst.MAX_DOCSIZE", 100)
mp.setattr("novelwriter.constants.nwConst.MAX_DOCSIZE", 100)
assert theToken.setText(sHandle, docText) is True
assert theToken.theText == (
"# ERROR\n\n"
+2 -2
View File
@@ -28,8 +28,8 @@ from shutil import copyfile
from tools import cmpFiles
from nw.core import NWProject, NWIndex, ToOdt
from nw.core.toodt import ODTParagraphStyle, ODTTextStyle, XMLParagraph, _mkTag
from novelwriter.core import NWProject, NWIndex, ToOdt
from novelwriter.core.toodt import ODTParagraphStyle, ODTTextStyle, XMLParagraph, _mkTag
XML_NS = [
' xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"',
+4 -4
View File
@@ -27,9 +27,9 @@ from hashlib import sha256
from tools import readFile
from nw.core.project import NWProject, NWItem, NWTree
from nw.enum import nwItemClass, nwItemType, nwItemLayout
from nw.constants import nwFiles
from novelwriter.core.project import NWProject, NWItem, NWTree
from novelwriter.enum import nwItemClass, nwItemType, nwItemLayout
from novelwriter.constants import nwFiles
@pytest.fixture(scope="function")
@@ -283,7 +283,7 @@ def testCoreTree_MakeHandles(monkeypatch, mockGUI):
# Fix the time() function and force a handle collission
theTree.setSeed(None)
theTree._handleCount = 0
monkeypatch.setattr("nw.core.tree.time", lambda: 123.4)
monkeypatch.setattr("novelwriter.core.tree.time", lambda: 123.4)
tHandle = theTree._makeHandle()
theTree._projTree[tHandle] = None
+1 -1
View File
@@ -25,7 +25,7 @@ from tools import getGuiItem
from PyQt5.QtWidgets import QAction, QMessageBox
from nw.dialogs import GuiAbout
from novelwriter.dialogs import GuiAbout
keyDelay = 2
typeDelay = 1
+3 -3
View File
@@ -24,7 +24,7 @@ import pytest
from PyQt5.QtCore import QItemSelectionModel
from PyQt5.QtWidgets import QAction, QListWidgetItem, QDialog, QMessageBox
from nw.dialogs import GuiQuoteSelect, GuiUpdates
from novelwriter.dialogs import GuiQuoteSelect, GuiUpdates
keyDelay = 2
typeDelay = 1
@@ -86,11 +86,11 @@ def testDlgOther_Updates(qtbot, monkeypatch, nwGUI):
return mockPayload()
# Faulty Return
monkeypatch.setattr("nw.dialogs.updates.urlopen", mockUrlopenA)
monkeypatch.setattr("novelwriter.dialogs.updates.urlopen", mockUrlopenA)
nwUpdate.checkLatest()
# Valid Return
monkeypatch.setattr("nw.dialogs.updates.urlopen", mockUrlopenB)
monkeypatch.setattr("novelwriter.dialogs.updates.urlopen", mockUrlopenB)
nwUpdate.checkLatest()
assert nwUpdate.latestValue.text().startswith("novelWriter v1.0")
+3 -3
View File
@@ -27,9 +27,9 @@ from tools import cmpFiles, getGuiItem
from PyQt5.QtWidgets import QAction, QMessageBox
from nw.gui import GuiProjectTree
from nw.enum import nwItemLayout
from nw.dialogs import GuiItemEditor
from novelwriter.gui import GuiProjectTree
from novelwriter.enum import nwItemLayout
from novelwriter.dialogs import GuiItemEditor
keyDelay = 2
typeDelay = 1
+3 -3
View File
@@ -27,9 +27,9 @@ from mock import causeOSError
from PyQt5.QtWidgets import QAction, QMessageBox, QDialog
from nw.dialogs import GuiDocMerge, GuiItemEditor
from nw.enum import nwItemType, nwWidget
from nw.core.tree import NWTree
from novelwriter.dialogs import GuiDocMerge, GuiItemEditor
from novelwriter.enum import nwItemType, nwWidget
from novelwriter.core.tree import NWTree
keyDelay = 2
typeDelay = 1
+10 -10
View File
@@ -19,9 +19,9 @@ 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
import pytest
import novelwriter
from shutil import copyfile
from tools import cmpFiles, getGuiItem
@@ -31,9 +31,9 @@ from PyQt5.QtWidgets import (
QDialogButtonBox, QDialog, QAction, QFileDialog, QFontDialog, QMessageBox
)
from nw.config import Config
from nw.dialogs import GuiPreferences, GuiQuoteSelect
from nw.constants import nwConst
from novelwriter.config import Config
from novelwriter.dialogs import GuiPreferences, GuiQuoteSelect
from novelwriter.constants import nwConst
keyDelay = 2
typeDelay = 1
@@ -50,17 +50,17 @@ def testDlgPreferences_Main(qtbot, monkeypatch, fncDir, outDir, refDir):
monkeypatch.setattr(QMessageBox, "information", lambda *a: 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
# novelwriter.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
origConf = novelwriter.CONFIG
novelwriter.CONFIG = theConf
nwGUI = nw.main(["--testmode", "--config=%s" % fncDir, "--data=%s" % fncDir])
nwGUI = novelwriter.main(["--testmode", "--config=%s" % fncDir, "--data=%s" % fncDir])
qtbot.addWidget(nwGUI)
nwGUI.show()
qtbot.wait(stepDelay)
@@ -253,7 +253,7 @@ def testDlgPreferences_Main(qtbot, monkeypatch, fncDir, outDir, refDir):
assert cmpFiles(testFile, compFile, ignoreLines)
# Clean up
nw.CONFIG = origConf
novelwriter.CONFIG = origConf
nwGUI.closeMain()
# qtbot.stopForInteraction()
+1 -1
View File
@@ -30,7 +30,7 @@ from PyQt5.QtWidgets import (
QMessageBox
)
from nw.dialogs import GuiProjectLoad
from novelwriter.dialogs import GuiProjectLoad
keyDelay = 2
typeDelay = 1
+1 -1
View File
@@ -31,7 +31,7 @@ from PyQt5.QtWidgets import (
QDialog, QAction, QMessageBox, QColorDialog, QTreeWidgetItem
)
from nw.dialogs import GuiProjectSettings
from novelwriter.dialogs import GuiProjectSettings
keyDelay = 2
typeDelay = 1
+4 -4
View File
@@ -27,10 +27,10 @@ from mock import causeOSError
from PyQt5.QtWidgets import QAction, QMessageBox, QDialog
from nw.dialogs import GuiDocSplit, GuiItemEditor
from nw.enum import nwItemType, nwWidget
from nw.core.document import NWDoc
from nw.core.tree import NWTree
from novelwriter.dialogs import GuiDocSplit, GuiItemEditor
from novelwriter.enum import nwItemType, nwWidget
from novelwriter.core.document import NWDoc
from novelwriter.core.tree import NWTree
keyDelay = 2
typeDelay = 1
+2 -2
View File
@@ -28,8 +28,8 @@ from PyQt5.QtWidgets import QDialog, QMessageBox, QAction
from tools import writeFile, readFile, getGuiItem
from mock import causeOSError
from nw.dialogs import GuiWordList
from nw.constants import nwFiles
from novelwriter.dialogs import GuiWordList
from novelwriter.constants import nwFiles
keyDelay = 2
typeDelay = 1
+5 -5
View File
@@ -27,9 +27,9 @@ from PyQt5.QtCore import Qt
from PyQt5.QtGui import QTextBlock, QTextCursor, QTextOption
from PyQt5.QtWidgets import QAction, QMessageBox, qApp
from nw.gui.doceditor import GuiDocEditor
from nw.enum import nwDocAction, nwDocInsert, nwItemClass, nwItemLayout
from nw.constants import nwKeyWords, nwUnicode
from novelwriter.gui.doceditor import GuiDocEditor
from novelwriter.enum import nwDocAction, nwDocInsert, nwItemClass, nwItemLayout
from novelwriter.constants import nwKeyWords, nwUnicode
keyDelay = 2
typeDelay = 1
@@ -110,7 +110,7 @@ def testGuiEditor_LoadText(qtbot, monkeypatch, caplog, nwGUI, nwMinimal, ipsumTe
# Document too big
with monkeypatch.context() as mp:
mp.setattr("nw.constants.nwConst.MAX_DOCSIZE", 100)
mp.setattr("novelwriter.constants.nwConst.MAX_DOCSIZE", 100)
assert nwGUI.docEditor.loadText(sHandle) is False
assert "The document you are trying to open is too big." in caplog.text
@@ -120,7 +120,7 @@ def testGuiEditor_LoadText(qtbot, monkeypatch, caplog, nwGUI, nwMinimal, ipsumTe
# Reload too big text
with monkeypatch.context() as mp:
mp.setattr("nw.constants.nwConst.MAX_DOCSIZE", 100)
mp.setattr("novelwriter.constants.nwConst.MAX_DOCSIZE", 100)
assert nwGUI.docEditor.replaceText(longText) is False
assert "The document you are trying to open is too big." in caplog.text
+1 -1
View File
@@ -25,7 +25,7 @@ from PyQt5.QtCore import Qt, QUrl
from PyQt5.QtGui import QTextCursor
from PyQt5.QtWidgets import qApp, QAction, QMessageBox
from nw.enum import nwDocAction
from novelwriter.enum import nwDocAction
keyDelay = 2
typeDelay = 1
+10 -10
View File
@@ -28,10 +28,10 @@ from tools import cmpFiles
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QMessageBox, QDialog
from nw.dialogs.itemeditor import GuiItemEditor
from nw.gui.doceditor import GuiDocEditor
from nw.gui.projtree import GuiProjectTree
from nw.enum import nwItemType, nwWidget
from novelwriter.dialogs.itemeditor import GuiItemEditor
from novelwriter.gui.doceditor import GuiDocEditor
from novelwriter.gui.projtree import GuiProjectTree
from novelwriter.enum import nwItemType, nwWidget
keyDelay = 2
typeDelay = 1
@@ -43,12 +43,12 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, fncProj, refDir, outDir):
"""Test the document editor.
"""
# Block message box
monkeypatch.setattr(QMessageBox, "question", lambda *args: QMessageBox.Yes)
monkeypatch.setattr(QMessageBox, "information", lambda *args: QMessageBox.Yes)
monkeypatch.setattr(GuiItemEditor, "exec_", lambda *args: None)
monkeypatch.setattr(GuiItemEditor, "result", lambda *args: QDialog.Accepted)
monkeypatch.setattr(GuiProjectTree, "hasFocus", lambda *args: True)
monkeypatch.setattr(GuiDocEditor, "hasFocus", lambda *args: True)
monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes)
monkeypatch.setattr(QMessageBox, "information", lambda *a: QMessageBox.Yes)
monkeypatch.setattr(GuiItemEditor, "exec_", lambda *a: None)
monkeypatch.setattr(GuiItemEditor, "result", lambda *a: QDialog.Accepted)
monkeypatch.setattr(GuiProjectTree, "hasFocus", lambda *a: True)
monkeypatch.setattr(GuiDocEditor, "hasFocus", lambda *a: True)
# Create new, save, close project
nwGUI.theProject.projTree.setSeed(42)
+3 -3
View File
@@ -28,9 +28,9 @@ from PyQt5.QtWidgets import QAction, QFileDialog, QMessageBox
from tools import writeFile
from nw.gui.doceditor import GuiDocEditor
from nw.enum import nwDocAction, nwDocInsert, nwWidget
from nw.constants import nwKeyWords, nwUnicode
from novelwriter.gui.doceditor import GuiDocEditor
from novelwriter.enum import nwDocAction, nwDocInsert, nwWidget
from novelwriter.constants import nwKeyWords, nwUnicode
keyDelay = 2
typeDelay = 1
+1 -1
View File
@@ -24,7 +24,7 @@ import pytest
from PyQt5.QtCore import Qt, QPoint
from PyQt5.QtWidgets import QAction, QTreeWidgetItem, QMessageBox
from nw.enum import nwOutline
from novelwriter.enum import nwOutline
keyDelay = 2
typeDelay = 1
+1 -1
View File
@@ -25,7 +25,7 @@ from tools import getGuiItem
from PyQt5.QtWidgets import QAction, QMessageBox
from nw.gui import GuiProjectDetails
from novelwriter.gui import GuiProjectDetails
keyDelay = 2
typeDelay = 1
+5 -5
View File
@@ -27,9 +27,9 @@ from tools import writeFile
from PyQt5.QtCore import QItemSelectionModel
from PyQt5.QtWidgets import QAction, QMessageBox
from nw.guimain import GuiMain
from nw.gui.projtree import GuiProjectTree
from nw.enum import nwItemType, nwItemClass
from novelwriter.guimain import GuiMain
from novelwriter.gui.projtree import GuiProjectTree
from novelwriter.enum import nwItemType, nwItemClass
@pytest.mark.gui
@@ -86,7 +86,7 @@ def testGuiProjTree_TreeItems(qtbot, caplog, monkeypatch, nwGUI, nwMinimal):
assert nwTree.newTreeItem(nwItemType.ROOT, nwItemClass.CUSTOM) # Valid
# Change max depth and try to add a subfolder that is too deep
monkeypatch.setattr("nw.constants.nwConst.MAX_DEPTH", 2)
monkeypatch.setattr("novelwriter.constants.nwConst.MAX_DEPTH", 2)
chItem = nwTree._getTreeItem("71ee45a3c0db9")
nwTree.setCurrentItem(chItem, QItemSelectionModel.Current)
assert not nwTree.newTreeItem(nwItemType.FOLDER, None)
@@ -228,7 +228,7 @@ def testGuiProjTree_TreeItems(qtbot, caplog, monkeypatch, nwGUI, nwMinimal):
nwTree.clearSelection()
# Add a file with no parent, and fail to find a suitable parent item
monkeypatch.setattr("nw.core.tree.NWTree.findRoot", lambda *a: None)
monkeypatch.setattr("novelwriter.core.tree.NWTree.findRoot", lambda *a: None)
assert not nwTree.newTreeItem(nwItemType.FILE, nwItemClass.NOVEL)
assert not nwTree.newTreeItem(nwItemType.FOLDER, nwItemClass.NOVEL)
+25 -21
View File
@@ -19,8 +19,8 @@ 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 novelwriter
from PyQt5.QtGui import QColor, QPixmap, QIcon
from PyQt5.QtWidgets import QStyle, QMessageBox
@@ -38,40 +38,44 @@ def testGuiTheme_Main(qtbot, monkeypatch, nwMinimal, tmpDir):
monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes)
monkeypatch.setattr(QMessageBox, "warning", lambda *a: QMessageBox.Yes)
nwGUI = nw.main(["--testmode", "--config=%s" % nwMinimal, "--data=%s" % tmpDir, nwMinimal])
nwGUI = novelwriter.main(
["--testmode", "--config=%s" % nwMinimal, "--data=%s" % tmpDir, nwMinimal]
)
qtbot.addWidget(nwGUI)
nwGUI.show()
qtbot.wait(stepDelay)
# Change Settings
assert nw.CONFIG.confPath == nwMinimal
nw.CONFIG.guiTheme = "default_dark"
nw.CONFIG.guiSyntax = "tomorrow_night_eighties"
nw.CONFIG.guiIcons = "typicons_colour_dark"
nw.CONFIG.guiDark = True
nw.CONFIG.guiFont = "Cantarell"
nw.CONFIG.guiFontSize = 11
nw.CONFIG.confChanged = True
assert nw.CONFIG.saveConfig()
assert novelwriter.CONFIG.confPath == nwMinimal
novelwriter.CONFIG.guiTheme = "default_dark"
novelwriter.CONFIG.guiSyntax = "tomorrow_night_eighties"
novelwriter.CONFIG.guiIcons = "typicons_colour_dark"
novelwriter.CONFIG.guiDark = True
novelwriter.CONFIG.guiFont = "Cantarell"
novelwriter.CONFIG.guiFontSize = 11
novelwriter.CONFIG.confChanged = True
assert novelwriter.CONFIG.saveConfig()
nwGUI.closeMain()
nwGUI.close()
del nwGUI
# Re-open
assert nw.CONFIG.confPath == nwMinimal
nwGUI = nw.main(["--testmode", "--config=%s" % nwMinimal, "--data=%s" % tmpDir, nwMinimal])
assert novelwriter.CONFIG.confPath == nwMinimal
nwGUI = novelwriter.main(
["--testmode", "--config=%s" % nwMinimal, "--data=%s" % tmpDir, nwMinimal]
)
assert nwGUI.mainConf.confPath == nwMinimal
qtbot.addWidget(nwGUI)
nwGUI.show()
qtbot.wait(stepDelay)
assert nw.CONFIG.guiTheme == "default_dark"
assert nw.CONFIG.guiSyntax == "tomorrow_night_eighties"
assert nw.CONFIG.guiIcons == "typicons_colour_dark"
assert nw.CONFIG.guiDark is True
assert nw.CONFIG.guiFont == "Cantarell"
assert nw.CONFIG.guiFontSize == 11
assert novelwriter.CONFIG.guiTheme == "default_dark"
assert novelwriter.CONFIG.guiSyntax == "tomorrow_night_eighties"
assert novelwriter.CONFIG.guiIcons == "typicons_colour_dark"
assert novelwriter.CONFIG.guiDark is True
assert novelwriter.CONFIG.guiFont == "Cantarell"
assert novelwriter.CONFIG.guiFontSize == 11
# Check GUI Colours
thePalette = nwGUI.palette()
@@ -114,9 +118,9 @@ def testGuiTheme_Main(qtbot, monkeypatch, nwMinimal, tmpDir):
# Test Icon class
theIcons = nwGUI.theTheme.theIcons
nw.CONFIG.guiIcons = "invalid"
novelwriter.CONFIG.guiIcons = "invalid"
assert not theIcons.updateTheme()
nw.CONFIG.guiIcons = "typicons_colour_dark"
novelwriter.CONFIG.guiIcons = "typicons_colour_dark"
assert theIcons.updateTheme()
# Ask for a non-existent key
+1 -1
View File
@@ -28,7 +28,7 @@ from tools import cmpFiles, getGuiItem
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QAction, QMessageBox, QFileDialog
from nw.tools import GuiBuildNovel
from novelwriter.tools import GuiBuildNovel
keyDelay = 2
typeDelay = 1
+2 -2
View File
@@ -28,8 +28,8 @@ from tools import getGuiItem
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QFileDialog, QWizard, QMessageBox
from nw.enum import nwItemClass
from nw.tools.projwizard import (
from novelwriter.enum import nwItemClass
from novelwriter.tools.projwizard import (
GuiProjectWizard, ProjWizardIntroPage, ProjWizardFolderPage,
ProjWizardPopulatePage, ProjWizardCustomPage, ProjWizardFinalPage
)
+2 -2
View File
@@ -29,8 +29,8 @@ from mock import causeOSError
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QAction, QFileDialog, QMessageBox
from nw.tools import GuiWritingStats
from nw.constants import nwFiles
from novelwriter.tools import GuiWritingStats
from novelwriter.constants import nwFiles
keyDelay = 2
typeDelay = 1