diff --git a/tests/conftest.py b/tests/conftest.py index 3eeb8344..3a97c58f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -7,7 +7,7 @@ import pytest import shutil import os -from nwdummy import DummyMain +from dummy import DummyMain from PyQt5.QtWidgets import QMessageBox diff --git a/tests/nwdummy.py b/tests/dummy.py similarity index 60% rename from tests/nwdummy.py rename to tests/dummy.py index 4b5302b7..c97be669 100644 --- a/tests/nwdummy.py +++ b/tests/dummy.py @@ -2,6 +2,10 @@ """novelWriter Test Dummy GUI Classes """ +# =========================================================================== # +# Mock GUI +# =========================================================================== # + class DummyMain(): def __init__(self): @@ -37,3 +41,11 @@ class StatusBar(): return # END Class StatusBar + +# =========================================================================== # +# Error Functions +# Dummy functions that will raise errors instead. +# =========================================================================== # + +def dummyIO(*args, **kwargs): + raise OSError diff --git a/tests/test_common.py b/tests/test_common.py index 2a24f31f..135627fc 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -9,7 +9,7 @@ from nw.common import ( checkString, checkBool, checkInt, colRange, formatInt, transferCase, fuzzyTime, checkHandle, formatTimeStamp, formatTime ) -from nwtools import cmpList +from tools import cmpList @pytest.mark.core def testCheckString(): diff --git a/tests/test_config.py b/tests/test_config.py index c23f6bc6..94ff5d1c 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -5,7 +5,7 @@ import pytest import os -from nwtools import cmpFiles +from tools import cmpFiles @pytest.mark.core def testConfigCore(tmpConf, tmpDir, refDir): diff --git a/tests/test_core_index.py b/tests/test_core_index.py index 1d577b70..ad87c7f3 100644 --- a/tests/test_core_index.py +++ b/tests/test_core_index.py @@ -8,7 +8,7 @@ import json from shutil import copyfile -from nwtools import cmpFiles +from tools import cmpFiles from nw.core.project import NWProject from nw.core.index import NWIndex diff --git a/tests/test_dialogs.py b/tests/test_dialogs.py index 7906c8e8..b8e3b276 100644 --- a/tests/test_dialogs.py +++ b/tests/test_dialogs.py @@ -9,7 +9,7 @@ import os import sys from shutil import copyfile -from nwtools import cmpFiles, getGuiItem +from tools import cmpFiles, getGuiItem from PyQt5.QtCore import Qt, QItemSelectionModel from PyQt5.QtWidgets import ( diff --git a/tests/test_gui.py b/tests/test_gui.py index 014d8f34..a6438d0a 100644 --- a/tests/test_gui.py +++ b/tests/test_gui.py @@ -9,7 +9,7 @@ import os import sys from shutil import copyfile -from nwtools import cmpFiles +from tools import cmpFiles from PyQt5.QtCore import Qt, QUrl, QPoint, QItemSelectionModel from PyQt5.QtGui import QTextCursor, QColor, QPixmap, QIcon, QTextBlock diff --git a/tests/test_project.py b/tests/test_project.py index 73c65f13..4167dbd3 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -8,7 +8,7 @@ import os from shutil import copyfile from zipfile import ZipFile -from nwtools import cmpFiles +from tools import cmpFiles from nw.core.project import NWProject from nw.core.spellcheck import NWSpellEnchant, NWSpellSimple @@ -324,127 +324,6 @@ def testProjectMethods(monkeypatch, nwMinimal, dummyGUI): assert theProject.setBookAuthors(" Jane Doe \n John Doh \n ") assert theProject.bookAuthors == ["Jane Doe", "John Doh"] -@pytest.mark.project -def testSpellEnchant(tmpDir, nwConf): - wList = os.path.join(tmpDir, "wordlist.txt") - with open(wList, mode="w") as wFile: - wFile.write("a_word\nb_word\nc_word\n") - - spChk = NWSpellEnchant() - spChk.mainConf = nwConf - spChk.setLanguage("en", wList) - - assert spChk.checkWord("a_word") - assert spChk.checkWord("b_word") - assert spChk.checkWord("c_word") - assert not spChk.checkWord("d_word") - - spChk.addWord("d_word") - assert spChk.checkWord("d_word") - - wSuggest = spChk.suggestWords("wrod") - assert len(wSuggest) > 0 - assert "word" in wSuggest - - dList = spChk.listDictionaries() - assert len(dList) > 0 - - aTag, aName = spChk.describeDict() - assert aTag == "en" - assert aName != "" - -@pytest.mark.project -def testSpellSimple(tmpDir, nwConf): - wList = os.path.join(tmpDir, "wordlist.txt") - with open(wList, mode="w") as wFile: - wFile.write("a_word\nb_word\nc_word\n") - - spChk = NWSpellSimple() - spChk.mainConf = nwConf - spChk.setLanguage("en", wList) - - assert spChk.checkWord("a_word") - assert spChk.checkWord("b_word") - assert spChk.checkWord("c_word") - assert not spChk.checkWord("d_word") - - spChk.addWord("d_word") - assert spChk.checkWord("d_word") - - wSuggest = spChk.suggestWords("wrod") - assert len(wSuggest) > 0 - assert "word" in wSuggest - - dList = spChk.listDictionaries() - assert len(dList) > 0 - - aTag, aName = spChk.describeDict() - assert aTag == "en" - assert aName == nwConst.SP_INTERNAL - -@pytest.mark.project -def testProjectOptions(dummyGUI, nwLipsum): - """Test the class that holds all the GUI state user options that are - tied to the current open project. Non-project related GUI options - are handled by the Config class. - """ - theProject = NWProject(dummyGUI) - assert theProject.projMeta is None - - theOpts = theProject.optState - assert not theOpts.loadSettings() - assert not theOpts.saveSettings() - - # No Settings - assert theProject.openProject(nwLipsum) - assert theOpts.loadSettings() - assert theOpts.saveSettings() - assert str(theOpts.theState) == r"{}" - - # Read Invalid Settings and Filter - stateFile = os.path.join(theProject.projMeta, nwFiles.OPTS_FILE) - with open(stateFile, mode="w", encoding="utf8") as outFile: - outFile.write( - r'{"GuiProjectSettings": {"winWidth": 100, "winHeight": 50}, "NoGroup": {"NoName": 0}}' - ) - assert theOpts.loadSettings() - assert str(theOpts.theState) == r"{'GuiProjectSettings': {'winWidth': 100, 'winHeight': 50}}" - - # Set New Settings - assert not theOpts.setValue("NoGroup", "NoName", None) - assert not theOpts.setValue("GuiProjectSettings", "NoName", None) - assert theOpts.setValue("GuiProjectSettings", "winWidth", 200) - assert theOpts.setValue("GuiProjectSettings", "winHeight", 80) - assert str(theOpts.theState) == r"{'GuiProjectSettings': {'winWidth': 200, 'winHeight': 80}}" - - # Check Read/Write Types - - ## String - assert theOpts.setValue("GuiWritingStats", "winWidth", "123") - assert isinstance(theOpts.getString("GuiWritingStats", "winWidth", "456"), str) - assert theOpts.getString("GuiWritingStats", "NoName", "456") == "456" - - ## Int - assert theOpts.setValue("GuiWritingStats", "winWidth", "123") - assert isinstance(theOpts.getInt("GuiWritingStats", "winWidth", 456), int) - assert theOpts.getInt("GuiWritingStats", "NoName", 456) == 456 - assert theOpts.setValue("GuiWritingStats", "winWidth", "True") - assert theOpts.getInt("GuiWritingStats", "NoName", 456) == 456 - - ## Float - assert theOpts.setValue("GuiWritingStats", "winWidth", "123") - assert isinstance(theOpts.getFloat("GuiWritingStats", "winWidth", 456.0), float) - assert theOpts.getFloat("GuiWritingStats", "NoName", 456.0) == 456.0 - assert theOpts.setValue("GuiWritingStats", "winWidth", "True") - assert theOpts.getFloat("GuiWritingStats", "winWidth", 456.0) == 456.0 - - ## Bool - assert theOpts.setValue("GuiWritingStats", "winWidth", True) - assert isinstance(theOpts.getBool("GuiWritingStats", "winWidth", False), bool) - assert theOpts.getFloat("GuiWritingStats", "NoName", False) is False - assert theOpts.setValue("GuiWritingStats", "winWidth", "True") - assert theOpts.getFloat("GuiWritingStats", "winWidth", False) is False - @pytest.mark.project def testProjectOrphanedFiles(dummyGUI, nwLipsum): """Check that files in the content folder that are not tracked in diff --git a/tests/nwtools.py b/tests/tools.py similarity index 100% rename from tests/nwtools.py rename to tests/tools.py