Update tests

This commit is contained in:
Veronica Berglyd Olsen
2024-05-20 17:14:03 +02:00
parent 0b999bd726
commit dce5bdd31d
7 changed files with 21 additions and 44 deletions
+1
View File
@@ -52,6 +52,7 @@ def resetConfigVars():
""" """
CONFIG.setLastPath(_TMP_ROOT) CONFIG.setLastPath(_TMP_ROOT)
CONFIG.setBackupPath(_TMP_ROOT) CONFIG.setBackupPath(_TMP_ROOT)
CONFIG.setGuiFont(None)
CONFIG.setTextFont(None) CONFIG.setTextFont(None)
CONFIG._homePath = _TMP_ROOT CONFIG._homePath = _TMP_ROOT
CONFIG.guiLocale = "en_GB" CONFIG.guiLocale = "en_GB"
+2 -4
View File
@@ -1,11 +1,10 @@
[Meta] [Meta]
timestamp = 2024-05-13 15:59:59 timestamp = 2024-05-20 16:48:20
[Main] [Main]
font =
theme = default theme = default
syntax = default_light syntax = default_light
font =
fontsize = 11
localisation = en_GB localisation = en_GB
hidevscroll = False hidevscroll = False
hidehscroll = False hidehscroll = False
@@ -30,7 +29,6 @@ askbeforebackup = True
[Editor] [Editor]
textfont = textfont =
textsize = 12
width = 700 width = 700
margin = 40 margin = 40
tabwidth = 40 tabwidth = 40
+7 -2
View File
@@ -103,15 +103,19 @@ def testBaseConfig_InitLoadSave(monkeypatch, fncPath, tstPaths):
if confFile.is_file(): if confFile.is_file():
confFile.unlink() confFile.unlink()
# Running init against a new oath should write a new config file # Running init + load against a new path should write a new config file
tstConf.initConfig(confPath=fncPath, dataPath=fncPath) tstConf.initConfig(confPath=fncPath, dataPath=fncPath)
assert tstConf._confPath == fncPath assert tstConf._confPath == fncPath
assert tstConf._dataPath == fncPath assert tstConf._dataPath == fncPath
tstConf.loadConfig()
assert confFile.exists() assert confFile.exists()
# Check that we have a default file # Check that we have a default file
copyfile(confFile, testFile) copyfile(confFile, testFile)
ignore = ("timestamp", "lastnotes", "localisation", "lastpath", "backuppath") ignore = (
"timestamp", "lastnotes", "localisation",
"lastpath", "backuppath", "font", "textfont"
)
assert cmpFiles(testFile, compFile, ignoreStart=ignore) assert cmpFiles(testFile, compFile, ignoreStart=ignore)
tstConf.errorText() # This clears the error cache tstConf.errorText() # This clears the error cache
@@ -136,6 +140,7 @@ def testBaseConfig_InitLoadSave(monkeypatch, fncPath, tstPaths):
newConf = Config() newConf = Config()
newConf.initConfig(confPath=fncPath, dataPath=fncPath) newConf.initConfig(confPath=fncPath, dataPath=fncPath)
newConf.loadConfig()
assert newConf.guiTheme == "foo" assert newConf.guiTheme == "foo"
assert newConf.guiSyntax == "bar" assert newConf.guiSyntax == "bar"
+7 -13
View File
@@ -23,7 +23,7 @@ from __future__ import annotations
import pytest import pytest
from PyQt5.QtCore import QEvent, Qt from PyQt5.QtCore import QEvent, Qt
from PyQt5.QtGui import QFontDatabase, QKeyEvent from PyQt5.QtGui import QFont, QFontDatabase, QKeyEvent
from PyQt5.QtWidgets import QAction, QFileDialog, QFontDialog from PyQt5.QtWidgets import QAction, QFileDialog, QFontDialog
from novelwriter import CONFIG, SHARED from novelwriter import CONFIG, SHARED
@@ -173,32 +173,28 @@ def testDlgPreferences_Settings(qtbot, monkeypatch, nwGUI, tstPaths):
prefs.guiLocale.setCurrentIndex(prefs.guiLocale.findData("en_US")) prefs.guiLocale.setCurrentIndex(prefs.guiLocale.findData("en_US"))
prefs.guiTheme.setCurrentIndex(prefs.guiTheme.findData("default_dark")) prefs.guiTheme.setCurrentIndex(prefs.guiTheme.findData("default_dark"))
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
mp.setattr(QFontDialog, "getFont", lambda *a: (MockFont(), True)) mp.setattr(QFontDialog, "getFont", lambda *a: (QFont(), True))
prefs.guiFontButton.click() prefs.guiFontButton.click()
prefs.guiFontSize.stepDown() # Should change it to 41
prefs.hideVScroll.setChecked(True) prefs.hideVScroll.setChecked(True)
prefs.hideHScroll.setChecked(True) prefs.hideHScroll.setChecked(True)
assert CONFIG.guiLocale != "en_US" assert CONFIG.guiLocale != "en_US"
assert CONFIG.guiTheme != "default_dark" assert CONFIG.guiTheme != "default_dark"
assert CONFIG.guiFont != "TestFont" assert CONFIG.guiFont.family() != ""
assert CONFIG.guiFontSize < 42
assert CONFIG.hideVScroll is False assert CONFIG.hideVScroll is False
assert CONFIG.hideHScroll is False assert CONFIG.hideHScroll is False
# Document Style # Document Style
prefs.guiSyntax.setCurrentIndex(prefs.guiSyntax.findData("default_dark")) prefs.guiSyntax.setCurrentIndex(prefs.guiSyntax.findData("default_dark"))
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
mp.setattr(QFontDialog, "getFont", lambda *a: (MockFont(), True)) mp.setattr(QFontDialog, "getFont", lambda *a: (QFont(), True))
prefs.textFontButton.click() prefs.textFontButton.click()
prefs.textSize.stepDown() # Should change it to 41
prefs.emphLabels.setChecked(False) prefs.emphLabels.setChecked(False)
prefs.showFullPath.setChecked(False) prefs.showFullPath.setChecked(False)
prefs.incNotesWCount.setChecked(False) prefs.incNotesWCount.setChecked(False)
assert CONFIG.guiSyntax != "default_dark" assert CONFIG.guiSyntax != "default_dark"
assert CONFIG.textFont != "testFont" assert CONFIG.textFont.family() != ""
assert CONFIG.textSize < 42
assert CONFIG.emphLabels is True assert CONFIG.emphLabels is True
assert CONFIG.showFullPath is True assert CONFIG.showFullPath is True
assert CONFIG.incNotesWCount is True assert CONFIG.incNotesWCount is True
@@ -341,15 +337,13 @@ def testDlgPreferences_Settings(qtbot, monkeypatch, nwGUI, tstPaths):
# Appearance # Appearance
assert CONFIG.guiLocale == "en_US" assert CONFIG.guiLocale == "en_US"
assert CONFIG.guiTheme == "default_dark" assert CONFIG.guiTheme == "default_dark"
assert CONFIG.guiFont == "TestFont" assert CONFIG.guiFont == QFont()
assert CONFIG.guiFontSize == 41
assert CONFIG.hideVScroll is True assert CONFIG.hideVScroll is True
assert CONFIG.hideHScroll is True assert CONFIG.hideHScroll is True
# Document Style # Document Style
assert CONFIG.guiSyntax == "default_dark" assert CONFIG.guiSyntax == "default_dark"
assert CONFIG.textFont == "TestFont" assert CONFIG.textFont == QFont()
assert CONFIG.textSize == 41
assert CONFIG.emphLabels is False assert CONFIG.emphLabels is False
assert CONFIG.showFullPath is False assert CONFIG.showFullPath is False
assert CONFIG.incNotesWCount is False assert CONFIG.incNotesWCount is False
+3 -3
View File
@@ -23,7 +23,7 @@ from __future__ import annotations
import pytest import pytest
from PyQt5.QtCore import QEvent, Qt, QThreadPool from PyQt5.QtCore import QEvent, Qt, QThreadPool
from PyQt5.QtGui import QClipboard, QMouseEvent, QTextBlock, QTextCursor, QTextOption from PyQt5.QtGui import QClipboard, QFont, QMouseEvent, QTextBlock, QTextCursor, QTextOption
from PyQt5.QtWidgets import QAction, QApplication, QMenu from PyQt5.QtWidgets import QAction, QApplication, QMenu
from novelwriter import CONFIG, SHARED from novelwriter import CONFIG, SHARED
@@ -84,7 +84,7 @@ def testGuiEditor_Init(qtbot, nwGUI, projPath, ipsumText, mockRnd):
assert docEditor.docHeader._docOutline == {0: "### New Scene"} assert docEditor.docHeader._docOutline == {0: "### New Scene"}
# Check that editor handles settings # Check that editor handles settings
CONFIG.textFont = "" CONFIG.textFont = QFont()
CONFIG.doJustify = True CONFIG.doJustify = True
CONFIG.showTabsNSpaces = True CONFIG.showTabsNSpaces = True
CONFIG.showLineEndings = True CONFIG.showLineEndings = True
@@ -96,7 +96,7 @@ def testGuiEditor_Init(qtbot, nwGUI, projPath, ipsumText, mockRnd):
docEditor.initEditor() docEditor.initEditor()
qDoc = docEditor.document() qDoc = docEditor.document()
assert CONFIG.textFont == qDoc.defaultFont().family() assert CONFIG.textFont == qDoc.defaultFont()
assert qDoc.defaultTextOption().alignment() == QtAlignJustify assert qDoc.defaultTextOption().alignment() == QtAlignJustify
assert qDoc.defaultTextOption().flags() & QTextOption.ShowTabsAndSpaces assert qDoc.defaultTextOption().flags() & QTextOption.ShowTabsAndSpaces
assert qDoc.defaultTextOption().flags() & QTextOption.ShowLineAndParagraphSeparators assert qDoc.defaultTextOption().flags() & QTextOption.ShowLineAndParagraphSeparators
-21
View File
@@ -48,27 +48,6 @@ def testGuiTheme_Main(qtbot, nwGUI, tstPaths):
assert mSize > 0 assert mSize > 0
assert mainTheme.getTextWidth("m", mainTheme.guiFont) == mSize assert mainTheme.getTextWidth("m", mainTheme.guiFont) == mSize
# Init Fonts
# ==========
# The defaults should be set
defaultFont = CONFIG.guiFont
defaultSize = CONFIG.guiFontSize
# CHange them to nonsense values
CONFIG.guiFont = "notafont"
CONFIG.guiFontSize = 99
# Let the theme class set them back to default
mainTheme._setGuiFont()
assert CONFIG.guiFont == defaultFont
assert CONFIG.guiFontSize == defaultSize
# A second call should just restore the defaults again
mainTheme._setGuiFont()
assert CONFIG.guiFont == defaultFont
assert CONFIG.guiFontSize == defaultSize
# Scan for Themes # Scan for Themes
# =============== # ===============
+1 -1
View File
@@ -547,7 +547,7 @@ def testBuildSettings_Format(monkeypatch, qtbot, nwGUI):
"""Test the Format Tab of the GuiBuildSettings dialog.""" """Test the Format Tab of the GuiBuildSettings dialog."""
build = BuildSettings() build = BuildSettings()
textFont = str(CONFIG.textFont) textFont = str(CONFIG.textFont.family())
build.setValue("format.buildLang", "en_US") build.setValue("format.buildLang", "en_US")
build.setValue("format.textFont", "") # Will fall back to config value build.setValue("format.textFont", "") # Will fall back to config value