From 7f8ffb228e1f9e8a953f621183a09aad353a2aad Mon Sep 17 00:00:00 2001
From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com>
Date: Tue, 16 May 2023 00:40:56 +0200
Subject: [PATCH] Remove dependency on .mainConf class variable in tests
---
tests/mock.py | 1 -
tests/test_core/test_core_project.py | 7 ++++---
tests/test_core/test_core_storage.py | 7 ++++---
tests/test_dialogs/test_dlg_preferences.py | 3 ++-
tests/test_dialogs/test_dlg_projsettings.py | 9 +++++----
tests/test_gui/test_gui_doceditor.py | 19 ++++++++++---------
tests/test_gui/test_gui_docviewer.py | 8 +++++---
tests/test_gui/test_gui_guimain.py | 17 +++++++++--------
tests/test_gui/test_gui_mainmenu.py | 9 +++++----
tests/test_gui/test_gui_noveltree.py | 9 +++++----
tests/test_gui/test_gui_outline.py | 9 +++++----
tests/test_gui/test_gui_projtree.py | 9 +++++----
tests/test_gui/test_gui_statusbar.py | 9 +++++----
tests/test_tools/test_tools_build.py | 5 +++--
14 files changed, 67 insertions(+), 54 deletions(-)
diff --git a/tests/mock.py b/tests/mock.py
index 96a4c5f8..57381b0a 100644
--- a/tests/mock.py
+++ b/tests/mock.py
@@ -31,7 +31,6 @@ class MockGuiMain(QObject):
def __init__(self):
super().__init__()
- self.mainConf = None
self.hasProject = True
self.theProject = None
self.mainStatus = MockStatusBar()
diff --git a/tests/test_core/test_core_project.py b/tests/test_core/test_core_project.py
index 9d4365a3..6425e4d8 100644
--- a/tests/test_core/test_core_project.py
+++ b/tests/test_core/test_core_project.py
@@ -29,6 +29,7 @@ from zipfile import ZipFile
from mock import causeOSError
from tools import C, cmpFiles, writeFile, buildTestProject, XML_IGNORE
+from novelwriter import CONFIG
from novelwriter.enum import nwItemClass, nwItemType, nwItemLayout
from novelwriter.common import formatTimeStamp
from novelwriter.constants import nwFiles
@@ -721,17 +722,17 @@ def testCoreProject_Backup(monkeypatch, mockGUI, fncPath, tstPaths):
# ================
# Invalid path
- theProject.mainConf._backupPath = None
+ CONFIG._backupPath = None
assert theProject.backupProject(doNotify=False) is False
# Missing project name
- theProject.mainConf._backupPath = tstPaths.tmpDir
+ CONFIG._backupPath = tstPaths.tmpDir
theProject.data.setName("")
assert theProject.backupProject(doNotify=False) is False
# Valid Settings
# ==============
- theProject.mainConf._backupPath = tstPaths.tmpDir
+ CONFIG._backupPath = tstPaths.tmpDir
theProject.data.setName("Test Minimal")
# Can't make folder
diff --git a/tests/test_core/test_core_storage.py b/tests/test_core/test_core_storage.py
index 877629a9..fe1dedc4 100644
--- a/tests/test_core/test_core_storage.py
+++ b/tests/test_core/test_core_storage.py
@@ -25,6 +25,7 @@ import pytest
from mock import causeOSError
from tools import C, buildTestProject, writeFile
+from novelwriter import CONFIG
from novelwriter.constants import nwFiles
from novelwriter.core.project import NWProject
from novelwriter.core.storage import NWStorage
@@ -148,9 +149,9 @@ def testCoreStorage_LockFile(monkeypatch, fncPath):
# Successful read
assert storage.readLockFile() == [
- storage.mainConf.hostName,
- storage.mainConf.osType,
- storage.mainConf.kernelVer,
+ CONFIG.hostName,
+ CONFIG.osType,
+ CONFIG.kernelVer,
"1000",
]
diff --git a/tests/test_dialogs/test_dlg_preferences.py b/tests/test_dialogs/test_dlg_preferences.py
index 6a81090b..d42ba40f 100644
--- a/tests/test_dialogs/test_dlg_preferences.py
+++ b/tests/test_dialogs/test_dlg_preferences.py
@@ -30,6 +30,7 @@ from PyQt5.QtWidgets import (
QDialogButtonBox, QDialog, QAction, QFileDialog, QFontDialog
)
+from novelwriter import CONFIG
from novelwriter.dialogs.quotes import GuiQuoteSelect
from novelwriter.dialogs.preferences import GuiPreferences
@@ -211,7 +212,7 @@ def testDlgPreferences_Main(qtbot, monkeypatch, nwGUI, tstPaths):
qtbot.mouseClick(nwPrefs.buttonBox.button(QDialogButtonBox.Ok), Qt.LeftButton)
nwPrefs._doClose()
- assert nwGUI.mainConf.saveConfig()
+ assert CONFIG.saveConfig()
projFile = tstPaths.cnfDir / "novelwriter.conf"
testFile = tstPaths.outDir / "guiPreferences_novelwriter.conf"
compFile = tstPaths.refDir / "guiPreferences_novelwriter.conf"
diff --git a/tests/test_dialogs/test_dlg_projsettings.py b/tests/test_dialogs/test_dlg_projsettings.py
index c7a6c528..a2c36d2f 100644
--- a/tests/test_dialogs/test_dlg_projsettings.py
+++ b/tests/test_dialogs/test_dlg_projsettings.py
@@ -21,13 +21,14 @@ along with this program. If not, see .
import pytest
-from novelwriter.enum import nwItemType
from tools import C, getGuiItem, buildTestProject
from PyQt5.QtGui import QColor
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QDialog, QAction, QColorDialog
+from novelwriter import CONFIG
+from novelwriter.enum import nwItemType
from novelwriter.dialogs.editlabel import GuiEditLabel
from novelwriter.dialogs.projsettings import GuiProjectSettings
@@ -91,7 +92,7 @@ def testDlgProjSettings_Main(qtbot, monkeypatch, nwGUI, fncPath, projPath, mockR
# Create new project
buildTestProject(nwGUI, projPath)
mockRnd.reset()
- nwGUI.mainConf.setBackupPath(fncPath)
+ CONFIG.setBackupPath(fncPath)
# Set some values
theProject = nwGUI.theProject
@@ -156,7 +157,7 @@ def testDlgProjSettings_StatusImport(qtbot, monkeypatch, nwGUI, fncPath, projPat
# Create new project
mockRnd.reset()
buildTestProject(nwGUI, projPath)
- nwGUI.mainConf.setBackupPath(fncPath)
+ CONFIG.setBackupPath(fncPath)
# Set some values
theProject = nwGUI.theProject
@@ -357,7 +358,7 @@ def testDlgProjSettings_Replace(qtbot, monkeypatch, nwGUI, fncPath, projPath, mo
# Create new project
mockRnd.reset()
buildTestProject(nwGUI, projPath)
- nwGUI.mainConf.setBackupPath(fncPath)
+ CONFIG.setBackupPath(fncPath)
# Set some values
theProject = nwGUI.theProject
diff --git a/tests/test_gui/test_gui_doceditor.py b/tests/test_gui/test_gui_doceditor.py
index 7497f950..cc386515 100644
--- a/tests/test_gui/test_gui_doceditor.py
+++ b/tests/test_gui/test_gui_doceditor.py
@@ -28,6 +28,7 @@ from PyQt5.QtCore import Qt
from PyQt5.QtGui import QTextBlock, QTextCursor, QTextOption
from PyQt5.QtWidgets import QAction, qApp
+from novelwriter import CONFIG
from novelwriter.enum import nwDocAction, nwDocInsert, nwItemLayout
from novelwriter.constants import nwKeyWords, nwUnicode
from novelwriter.core.index import countWords
@@ -55,18 +56,18 @@ def testGuiEditor_Init(qtbot, nwGUI, projPath, ipsumText, mockRnd):
assert nwGUI.docEditor._typPadChar == nwUnicode.U_NBSP
# Check that editor handles settings
- nwGUI.mainConf.textFont = None
- nwGUI.mainConf.doJustify = True
- nwGUI.mainConf.showTabsNSpaces = True
- nwGUI.mainConf.showLineEndings = True
- nwGUI.mainConf.hideVScroll = True
- nwGUI.mainConf.hideHScroll = True
- nwGUI.mainConf.fmtPadThin = True
+ CONFIG.textFont = None
+ CONFIG.doJustify = True
+ CONFIG.showTabsNSpaces = True
+ CONFIG.showLineEndings = True
+ CONFIG.hideVScroll = True
+ CONFIG.hideHScroll = True
+ CONFIG.fmtPadThin = True
assert nwGUI.docEditor.initEditor()
qDoc = nwGUI.docEditor.document()
- assert nwGUI.mainConf.textFont == qDoc.defaultFont().family()
+ assert CONFIG.textFont == qDoc.defaultFont().family()
assert qDoc.defaultTextOption().alignment() == Qt.AlignJustify
assert qDoc.defaultTextOption().flags() & QTextOption.ShowTabsAndSpaces
assert qDoc.defaultTextOption().flags() & QTextOption.ShowLineAndParagraphSeparators
@@ -114,7 +115,7 @@ def testGuiEditor_LoadText(qtbot, monkeypatch, caplog, nwGUI, projPath, ipsumTex
assert "The document you are trying to open is too big." in caplog.text
# Big doc handling
- nwGUI.mainConf.bigDocLimit = 50
+ CONFIG.bigDocLimit = 50
assert nwGUI.docEditor.loadText(C.hSceneDoc) is True
assert nwGUI.docEditor._bigDoc is True
diff --git a/tests/test_gui/test_gui_docviewer.py b/tests/test_gui/test_gui_docviewer.py
index 14cf66d0..2bd7ad7a 100644
--- a/tests/test_gui/test_gui_docviewer.py
+++ b/tests/test_gui/test_gui_docviewer.py
@@ -21,11 +21,13 @@ along with this program. If not, see .
import pytest
+from mock import causeException
+
from PyQt5.QtCore import Qt, QUrl
from PyQt5.QtGui import QTextCursor
from PyQt5.QtWidgets import qApp, QAction
-from mock import causeException
+from novelwriter import CONFIG
from novelwriter.enum import nwDocAction
from novelwriter.core.tohtml import ToHtml
@@ -134,10 +136,10 @@ def testGuiViewer_Main(qtbot, monkeypatch, nwGUI, nwLipsum):
assert nwGUI.docViewer.docHeader.theTitle.text() == "Characters › Test Title"
# Ttile without full path
- nwGUI.mainConf.showFullPath = False
+ CONFIG.showFullPath = False
nwGUI.docViewer.updateDocInfo("4c4f28287af27")
assert nwGUI.docViewer.docHeader.theTitle.text() == "Test Title"
- nwGUI.mainConf.showFullPath = True
+ CONFIG.showFullPath = True
# Document footer show/hide references
viewState = nwGUI.viewMeta.isVisible()
diff --git a/tests/test_gui/test_gui_guimain.py b/tests/test_gui/test_gui_guimain.py
index e6a5256e..f5b9ecc6 100644
--- a/tests/test_gui/test_gui_guimain.py
+++ b/tests/test_gui/test_gui_guimain.py
@@ -30,6 +30,7 @@ from tools import (
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QDialog, QMessageBox, QInputDialog
+from novelwriter import CONFIG
from novelwriter.enum import nwItemType, nwView, nwWidget
from novelwriter.constants import nwFiles
from novelwriter.gui.outline import GuiOutlineView
@@ -75,7 +76,7 @@ def testGuiMain_Launch(qtbot, monkeypatch, nwGUI, prjLipsum):
"""
monkeypatch.setattr(GuiProjectLoad, "exec_", lambda *a: None)
monkeypatch.setattr(GuiProjectLoad, "result", lambda *a: QDialog.Accepted)
- nwGUI.mainConf.lastNotes = "0x0"
+ CONFIG.lastNotes = "0x0"
# Open Lipsum project
nwGUI.postLaunchTasks(prjLipsum)
@@ -244,10 +245,10 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd):
assert nwGUI.mainMenu._toggleSpellCheck()
# Change some settings
- nwGUI.mainConf.hideHScroll = True
- nwGUI.mainConf.hideVScroll = True
- nwGUI.mainConf.autoScrollPos = 80
- nwGUI.mainConf.autoScroll = True
+ CONFIG.hideHScroll = True
+ CONFIG.hideVScroll = True
+ CONFIG.autoScrollPos = 80
+ CONFIG.autoScroll = True
# Add a Character File
nwGUI.switchFocus(nwWidget.TREE)
@@ -589,11 +590,11 @@ def testGuiMain_FocusFullMode(qtbot, nwGUI, projPath, mockRnd):
# Full Screen Mode
# ================
- assert nwGUI.mainConf.isFullScreen is False
+ assert CONFIG.isFullScreen is False
nwGUI.toggleFullScreenMode()
- assert nwGUI.mainConf.isFullScreen is True
+ assert CONFIG.isFullScreen is True
nwGUI.toggleFullScreenMode()
- assert nwGUI.mainConf.isFullScreen is False
+ assert CONFIG.isFullScreen is False
# qtbot.stop()
diff --git a/tests/test_gui/test_gui_mainmenu.py b/tests/test_gui/test_gui_mainmenu.py
index 92a820a0..3c7cc565 100644
--- a/tests/test_gui/test_gui_mainmenu.py
+++ b/tests/test_gui/test_gui_mainmenu.py
@@ -27,6 +27,7 @@ from PyQt5.QtWidgets import QAction, QFileDialog, QMessageBox
from tools import C, writeFile, buildTestProject
+from novelwriter import CONFIG
from novelwriter.enum import nwDocAction, nwDocInsert
from novelwriter.constants import nwKeyWords, nwUnicode
from novelwriter.gui.doceditor import GuiDocEditor
@@ -461,19 +462,19 @@ def testGuiMenu_Insert(qtbot, monkeypatch, nwGUI, fncPath, projPath, mockRnd):
nwGUI.docEditor.clear()
nwGUI.mainMenu.aInsQuoteLS.activate(QAction.Trigger)
- assert nwGUI.docEditor.getText() == nwGUI.mainConf.fmtSQuoteOpen
+ assert nwGUI.docEditor.getText() == CONFIG.fmtSQuoteOpen
nwGUI.docEditor.clear()
nwGUI.mainMenu.aInsQuoteRS.activate(QAction.Trigger)
- assert nwGUI.docEditor.getText() == nwGUI.mainConf.fmtSQuoteClose
+ assert nwGUI.docEditor.getText() == CONFIG.fmtSQuoteClose
nwGUI.docEditor.clear()
nwGUI.mainMenu.aInsQuoteLD.activate(QAction.Trigger)
- assert nwGUI.docEditor.getText() == nwGUI.mainConf.fmtDQuoteOpen
+ assert nwGUI.docEditor.getText() == CONFIG.fmtDQuoteOpen
nwGUI.docEditor.clear()
nwGUI.mainMenu.aInsQuoteRD.activate(QAction.Trigger)
- assert nwGUI.docEditor.getText() == nwGUI.mainConf.fmtDQuoteClose
+ assert nwGUI.docEditor.getText() == CONFIG.fmtDQuoteClose
nwGUI.docEditor.clear()
nwGUI.mainMenu.aInsMSApos.activate(QAction.Trigger)
diff --git a/tests/test_gui/test_gui_noveltree.py b/tests/test_gui/test_gui_noveltree.py
index e74e4ebb..79497f57 100644
--- a/tests/test_gui/test_gui_noveltree.py
+++ b/tests/test_gui/test_gui_noveltree.py
@@ -29,6 +29,7 @@ from PyQt5.QtGui import QFocusEvent
from PyQt5.QtCore import Qt, QEvent
from PyQt5.QtWidgets import QInputDialog, QToolTip
+from novelwriter import CONFIG
from novelwriter.enum import nwWidget, nwItemType
from novelwriter.gui.noveltree import NovelTreeColumn
from novelwriter.dialogs.editlabel import GuiEditLabel
@@ -67,14 +68,14 @@ def testGuiNovelTree_TreeItems(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
# Show/Hide Scrollbars
# ====================
- nwGUI.mainConf.hideVScroll = True
- nwGUI.mainConf.hideHScroll = True
+ CONFIG.hideVScroll = True
+ CONFIG.hideHScroll = True
novelView.initSettings()
assert not novelTree.verticalScrollBar().isVisible()
assert not novelTree.horizontalScrollBar().isVisible()
- nwGUI.mainConf.hideVScroll = False
- nwGUI.mainConf.hideHScroll = False
+ CONFIG.hideVScroll = False
+ CONFIG.hideHScroll = False
novelView.initSettings()
assert novelTree.verticalScrollBar().isEnabled()
assert novelTree.horizontalScrollBar().isEnabled()
diff --git a/tests/test_gui/test_gui_outline.py b/tests/test_gui/test_gui_outline.py
index 7b5bbfc6..533a5c52 100644
--- a/tests/test_gui/test_gui_outline.py
+++ b/tests/test_gui/test_gui_outline.py
@@ -28,6 +28,7 @@ from tools import buildTestProject, writeFile
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QWidget, QAction
+from novelwriter import CONFIG
from novelwriter.enum import nwItemClass, nwOutline, nwView
@@ -47,16 +48,16 @@ def testGuiOutline_Main(qtbot, monkeypatch, nwGUI, projPath):
outlineMenu = outlineView.outlineBar.mColumns
# Toggle scrollbars
- nwGUI.mainConf.hideVScroll = True
- nwGUI.mainConf.hideHScroll = True
+ CONFIG.hideVScroll = True
+ CONFIG.hideHScroll = True
outlineView.initSettings()
assert outlineTree.verticalScrollBarPolicy() == Qt.ScrollBarAlwaysOff
assert outlineTree.horizontalScrollBarPolicy() == Qt.ScrollBarAlwaysOff
assert outlineData.verticalScrollBarPolicy() == Qt.ScrollBarAlwaysOff
assert outlineData.horizontalScrollBarPolicy() == Qt.ScrollBarAlwaysOff
- nwGUI.mainConf.hideVScroll = False
- nwGUI.mainConf.hideHScroll = False
+ CONFIG.hideVScroll = False
+ CONFIG.hideHScroll = False
outlineView.initSettings()
assert outlineTree.verticalScrollBarPolicy() == Qt.ScrollBarAsNeeded
assert outlineTree.horizontalScrollBarPolicy() == Qt.ScrollBarAsNeeded
diff --git a/tests/test_gui/test_gui_projtree.py b/tests/test_gui/test_gui_projtree.py
index cf1a4ab2..dbaeb09f 100644
--- a/tests/test_gui/test_gui_projtree.py
+++ b/tests/test_gui/test_gui_projtree.py
@@ -27,6 +27,7 @@ from tools import C, buildTestProject
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QMessageBox, QMenu, QTreeWidgetItem, QDialog
+from novelwriter import CONFIG
from novelwriter.enum import nwItemLayout, nwItemType, nwItemClass
from novelwriter.gui.projtree import GuiProjectTree
from novelwriter.dialogs.docmerge import GuiDocMerge
@@ -862,14 +863,14 @@ def testGuiProjTree_Other(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
# ====================
# Test that the scrollbar setting works
- nwGUI.mainConf.hideVScroll = True
- nwGUI.mainConf.hideHScroll = True
+ CONFIG.hideVScroll = True
+ CONFIG.hideHScroll = True
projView.initSettings()
assert projTree.verticalScrollBarPolicy() == Qt.ScrollBarAlwaysOff
assert projTree.horizontalScrollBarPolicy() == Qt.ScrollBarAlwaysOff
- nwGUI.mainConf.hideVScroll = False
- nwGUI.mainConf.hideHScroll = False
+ CONFIG.hideVScroll = False
+ CONFIG.hideHScroll = False
projView.initSettings()
assert projTree.verticalScrollBarPolicy() == Qt.ScrollBarAsNeeded
assert projTree.horizontalScrollBarPolicy() == Qt.ScrollBarAsNeeded
diff --git a/tests/test_gui/test_gui_statusbar.py b/tests/test_gui/test_gui_statusbar.py
index f0a3ce9f..b19afa45 100644
--- a/tests/test_gui/test_gui_statusbar.py
+++ b/tests/test_gui/test_gui_statusbar.py
@@ -24,6 +24,7 @@ import pytest
from tools import C, buildTestProject
+from novelwriter import CONFIG
from novelwriter.gui.statusbar import StatusLED
@@ -60,13 +61,13 @@ def testGuiStatusBar_Main(qtbot, nwGUI, projPath, mockRnd):
assert nwGUI.mainStatus.docIcon._theCol == nwGUI.mainStatus.docIcon._colGood
# Idle Status
- nwGUI.mainStatus.mainConf.stopWhenIdle = False
+ CONFIG.stopWhenIdle = False
nwGUI.mainStatus.setUserIdle(True)
nwGUI.mainStatus.updateTime()
assert nwGUI.mainStatus.userIdle is False
assert nwGUI.mainStatus.timeText.text() == "00:00:00"
- nwGUI.mainStatus.mainConf.stopWhenIdle = True
+ CONFIG.stopWhenIdle = True
nwGUI.mainStatus.setUserIdle(True)
nwGUI.mainStatus.updateTime(5)
assert nwGUI.mainStatus.userIdle is True
@@ -84,10 +85,10 @@ def testGuiStatusBar_Main(qtbot, nwGUI, projPath, mockRnd):
assert nwGUI.mainStatus.langText.text() == "American English"
# Project Stats
- nwGUI.mainStatus.mainConf.incNotesWCount = False
+ CONFIG.incNotesWCount = False
nwGUI._updateStatusWordCount()
assert nwGUI.mainStatus.statsText.text() == "Words: 9 (+9)"
- nwGUI.mainStatus.mainConf.incNotesWCount = True
+ CONFIG.incNotesWCount = True
nwGUI._updateStatusWordCount()
assert nwGUI.mainStatus.statsText.text() == "Words: 11 (+11)"
diff --git a/tests/test_tools/test_tools_build.py b/tests/test_tools/test_tools_build.py
index e8dd5dce..5099c168 100644
--- a/tests/test_tools/test_tools_build.py
+++ b/tests/test_tools/test_tools_build.py
@@ -28,6 +28,7 @@ from tools import ODT_IGNORE, cmpFiles, getGuiItem
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QAction, QFileDialog
+from novelwriter import CONFIG
from novelwriter.tools.build import GuiBuildNovel
@@ -67,7 +68,7 @@ def testToolBuild_Main(qtbot, monkeypatch, nwGUI, prjLipsum, tstPaths):
assert not nwBuild._saveDocument(nwBuild.FMT_NWD)
# Default Settings
- nwGUI.mainConf._lastPath = prjLipsum
+ CONFIG._lastPath = prjLipsum
qtbot.mouseClick(nwBuild.buildNovel, Qt.LeftButton)
assert nwBuild._saveDocument(nwBuild.FMT_NWD)
@@ -231,7 +232,7 @@ def testToolBuild_Main(qtbot, monkeypatch, nwGUI, prjLipsum, tstPaths):
assert (prjLipsum / "Lorem Ipsum.odt").is_file()
# Print to PDF
- if not nwGUI.mainConf.osDarwin:
+ if not CONFIG.osDarwin:
assert nwBuild._saveDocument(nwBuild.FMT_PDF)
assert (prjLipsum / "Lorem Ipsum.pdf").is_file()