From dce5bdd31d01f100043d72ebed09bfb2893411aa Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Mon, 20 May 2024 17:14:03 +0200 Subject: [PATCH] Update tests --- tests/conftest.py | 1 + tests/reference/baseConfig_novelwriter.conf | 6 ++---- tests/test_base/test_base_config.py | 9 +++++++-- tests/test_dialogs/test_dlg_preferences.py | 20 +++++++------------ tests/test_gui/test_gui_doceditor.py | 6 +++--- tests/test_gui/test_gui_theme.py | 21 -------------------- tests/test_tools/test_tools_manussettings.py | 2 +- 7 files changed, 21 insertions(+), 44 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 1e463f9c..5ea7cbb2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -52,6 +52,7 @@ def resetConfigVars(): """ CONFIG.setLastPath(_TMP_ROOT) CONFIG.setBackupPath(_TMP_ROOT) + CONFIG.setGuiFont(None) CONFIG.setTextFont(None) CONFIG._homePath = _TMP_ROOT CONFIG.guiLocale = "en_GB" diff --git a/tests/reference/baseConfig_novelwriter.conf b/tests/reference/baseConfig_novelwriter.conf index 818f4280..99559ed8 100644 --- a/tests/reference/baseConfig_novelwriter.conf +++ b/tests/reference/baseConfig_novelwriter.conf @@ -1,11 +1,10 @@ [Meta] -timestamp = 2024-05-13 15:59:59 +timestamp = 2024-05-20 16:48:20 [Main] +font = theme = default syntax = default_light -font = -fontsize = 11 localisation = en_GB hidevscroll = False hidehscroll = False @@ -30,7 +29,6 @@ askbeforebackup = True [Editor] textfont = -textsize = 12 width = 700 margin = 40 tabwidth = 40 diff --git a/tests/test_base/test_base_config.py b/tests/test_base/test_base_config.py index 8af01057..93a09a75 100644 --- a/tests/test_base/test_base_config.py +++ b/tests/test_base/test_base_config.py @@ -103,15 +103,19 @@ def testBaseConfig_InitLoadSave(monkeypatch, fncPath, tstPaths): if confFile.is_file(): 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) assert tstConf._confPath == fncPath assert tstConf._dataPath == fncPath + tstConf.loadConfig() assert confFile.exists() # Check that we have a default file copyfile(confFile, testFile) - ignore = ("timestamp", "lastnotes", "localisation", "lastpath", "backuppath") + ignore = ( + "timestamp", "lastnotes", "localisation", + "lastpath", "backuppath", "font", "textfont" + ) assert cmpFiles(testFile, compFile, ignoreStart=ignore) tstConf.errorText() # This clears the error cache @@ -136,6 +140,7 @@ def testBaseConfig_InitLoadSave(monkeypatch, fncPath, tstPaths): newConf = Config() newConf.initConfig(confPath=fncPath, dataPath=fncPath) + newConf.loadConfig() assert newConf.guiTheme == "foo" assert newConf.guiSyntax == "bar" diff --git a/tests/test_dialogs/test_dlg_preferences.py b/tests/test_dialogs/test_dlg_preferences.py index 360c339f..70e950de 100644 --- a/tests/test_dialogs/test_dlg_preferences.py +++ b/tests/test_dialogs/test_dlg_preferences.py @@ -23,7 +23,7 @@ from __future__ import annotations import pytest 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 novelwriter import CONFIG, SHARED @@ -173,32 +173,28 @@ def testDlgPreferences_Settings(qtbot, monkeypatch, nwGUI, tstPaths): prefs.guiLocale.setCurrentIndex(prefs.guiLocale.findData("en_US")) prefs.guiTheme.setCurrentIndex(prefs.guiTheme.findData("default_dark")) 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.guiFontSize.stepDown() # Should change it to 41 prefs.hideVScroll.setChecked(True) prefs.hideHScroll.setChecked(True) assert CONFIG.guiLocale != "en_US" assert CONFIG.guiTheme != "default_dark" - assert CONFIG.guiFont != "TestFont" - assert CONFIG.guiFontSize < 42 + assert CONFIG.guiFont.family() != "" assert CONFIG.hideVScroll is False assert CONFIG.hideHScroll is False # Document Style prefs.guiSyntax.setCurrentIndex(prefs.guiSyntax.findData("default_dark")) 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.textSize.stepDown() # Should change it to 41 prefs.emphLabels.setChecked(False) prefs.showFullPath.setChecked(False) prefs.incNotesWCount.setChecked(False) assert CONFIG.guiSyntax != "default_dark" - assert CONFIG.textFont != "testFont" - assert CONFIG.textSize < 42 + assert CONFIG.textFont.family() != "" assert CONFIG.emphLabels is True assert CONFIG.showFullPath is True assert CONFIG.incNotesWCount is True @@ -341,15 +337,13 @@ def testDlgPreferences_Settings(qtbot, monkeypatch, nwGUI, tstPaths): # Appearance assert CONFIG.guiLocale == "en_US" assert CONFIG.guiTheme == "default_dark" - assert CONFIG.guiFont == "TestFont" - assert CONFIG.guiFontSize == 41 + assert CONFIG.guiFont == QFont() assert CONFIG.hideVScroll is True assert CONFIG.hideHScroll is True # Document Style assert CONFIG.guiSyntax == "default_dark" - assert CONFIG.textFont == "TestFont" - assert CONFIG.textSize == 41 + assert CONFIG.textFont == QFont() assert CONFIG.emphLabels is False assert CONFIG.showFullPath is False assert CONFIG.incNotesWCount is False diff --git a/tests/test_gui/test_gui_doceditor.py b/tests/test_gui/test_gui_doceditor.py index 30e199d0..6c8ed7a6 100644 --- a/tests/test_gui/test_gui_doceditor.py +++ b/tests/test_gui/test_gui_doceditor.py @@ -23,7 +23,7 @@ from __future__ import annotations import pytest 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 novelwriter import CONFIG, SHARED @@ -84,7 +84,7 @@ def testGuiEditor_Init(qtbot, nwGUI, projPath, ipsumText, mockRnd): assert docEditor.docHeader._docOutline == {0: "### New Scene"} # Check that editor handles settings - CONFIG.textFont = "" + CONFIG.textFont = QFont() CONFIG.doJustify = True CONFIG.showTabsNSpaces = True CONFIG.showLineEndings = True @@ -96,7 +96,7 @@ def testGuiEditor_Init(qtbot, nwGUI, projPath, ipsumText, mockRnd): docEditor.initEditor() qDoc = docEditor.document() - assert CONFIG.textFont == qDoc.defaultFont().family() + assert CONFIG.textFont == qDoc.defaultFont() assert qDoc.defaultTextOption().alignment() == QtAlignJustify assert qDoc.defaultTextOption().flags() & QTextOption.ShowTabsAndSpaces assert qDoc.defaultTextOption().flags() & QTextOption.ShowLineAndParagraphSeparators diff --git a/tests/test_gui/test_gui_theme.py b/tests/test_gui/test_gui_theme.py index e5431b65..18458883 100644 --- a/tests/test_gui/test_gui_theme.py +++ b/tests/test_gui/test_gui_theme.py @@ -48,27 +48,6 @@ def testGuiTheme_Main(qtbot, nwGUI, tstPaths): assert mSize > 0 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 # =============== diff --git a/tests/test_tools/test_tools_manussettings.py b/tests/test_tools/test_tools_manussettings.py index a2d0bc7d..1d1ef591 100644 --- a/tests/test_tools/test_tools_manussettings.py +++ b/tests/test_tools/test_tools_manussettings.py @@ -547,7 +547,7 @@ def testBuildSettings_Format(monkeypatch, qtbot, nwGUI): """Test the Format Tab of the GuiBuildSettings dialog.""" build = BuildSettings() - textFont = str(CONFIG.textFont) + textFont = str(CONFIG.textFont.family()) build.setValue("format.buildLang", "en_US") build.setValue("format.textFont", "") # Will fall back to config value