diff --git a/novelwriter/dialogs/about.py b/novelwriter/dialogs/about.py index d2f7d512..36b8bc99 100644 --- a/novelwriter/dialogs/about.py +++ b/novelwriter/dialogs/about.py @@ -114,7 +114,7 @@ class GuiAbout(QDialog): return - def __del__(self): + def __del__(self): # pragma: no cover logger.debug("Delete: GuiAbout") return diff --git a/novelwriter/dialogs/docmerge.py b/novelwriter/dialogs/docmerge.py index 71111f0a..49e3d5f1 100644 --- a/novelwriter/dialogs/docmerge.py +++ b/novelwriter/dialogs/docmerge.py @@ -113,7 +113,7 @@ class GuiDocMerge(QDialog): return - def __del__(self): + def __del__(self): # pragma: no cover logger.debug("Delete: GuiDocMerge") return diff --git a/novelwriter/dialogs/docsplit.py b/novelwriter/dialogs/docsplit.py index c08c017b..58396879 100644 --- a/novelwriter/dialogs/docsplit.py +++ b/novelwriter/dialogs/docsplit.py @@ -142,7 +142,7 @@ class GuiDocSplit(QDialog): return - def __del__(self): + def __del__(self): # pragma: no cover logger.debug("Delete: GuiDocSplit") return diff --git a/novelwriter/dialogs/preferences.py b/novelwriter/dialogs/preferences.py index 5d89cadc..9878ad51 100644 --- a/novelwriter/dialogs/preferences.py +++ b/novelwriter/dialogs/preferences.py @@ -87,7 +87,7 @@ class GuiPreferences(NPagedDialog): return - def __del__(self): + def __del__(self): # pragma: no cover logger.debug("Delete: GuiPreferences") return diff --git a/novelwriter/dialogs/projdetails.py b/novelwriter/dialogs/projdetails.py index d4cff393..e4960b57 100644 --- a/novelwriter/dialogs/projdetails.py +++ b/novelwriter/dialogs/projdetails.py @@ -82,7 +82,7 @@ class GuiProjectDetails(NPagedDialog): return - def __del__(self): + def __del__(self): # pragma: no cover logger.debug("Delete: GuiProjectDetails") return diff --git a/novelwriter/dialogs/projload.py b/novelwriter/dialogs/projload.py index 8fa3ec7a..04cef031 100644 --- a/novelwriter/dialogs/projload.py +++ b/novelwriter/dialogs/projload.py @@ -151,7 +151,7 @@ class GuiProjectLoad(QDialog): return - def __del__(self): + def __del__(self): # pragma: no cover logger.debug("Delete: GuiProjectLoad") return diff --git a/novelwriter/dialogs/projsettings.py b/novelwriter/dialogs/projsettings.py index aac956cc..f496b5e8 100644 --- a/novelwriter/dialogs/projsettings.py +++ b/novelwriter/dialogs/projsettings.py @@ -97,7 +97,7 @@ class GuiProjectSettings(NPagedDialog): return - def __del__(self): + def __del__(self): # pragma: no cover logger.debug("Delete: GuiProjectSettings") return diff --git a/novelwriter/dialogs/updates.py b/novelwriter/dialogs/updates.py index 15e40f8e..4b8afad1 100644 --- a/novelwriter/dialogs/updates.py +++ b/novelwriter/dialogs/updates.py @@ -117,7 +117,7 @@ class GuiUpdates(QDialog): return - def __del__(self): + def __del__(self): # pragma: no cover logger.debug("Delete: GuiUpdates") return diff --git a/novelwriter/dialogs/wordlist.py b/novelwriter/dialogs/wordlist.py index 118b94a4..55503376 100644 --- a/novelwriter/dialogs/wordlist.py +++ b/novelwriter/dialogs/wordlist.py @@ -114,7 +114,7 @@ class GuiWordList(QDialog): return - def __del__(self): + def __del__(self): # pragma: no cover logger.debug("Delete: GuiWordList") return @@ -122,25 +122,25 @@ class GuiWordList(QDialog): # Slots ## - def _doAdd(self) -> bool: + def _doAdd(self): """Add a new word to the word list.""" word = self.newEntry.text().strip() if word == "": self.mainGui.makeAlert(self.tr( "Cannot add a blank word." ), nwAlert.ERROR) - return False + return if self.listBox.findItems(word, Qt.MatchExactly): self.mainGui.makeAlert(self.tr( "The word '{0}' is already in the word list." ).format(word), nwAlert.ERROR) - return False + return self.listBox.addItem(word) self.newEntry.setText("") - return True + return def _doDelete(self): """Delete the selected item.""" diff --git a/novelwriter/tools/lipsum.py b/novelwriter/tools/lipsum.py index af152397..5c6d41ca 100644 --- a/novelwriter/tools/lipsum.py +++ b/novelwriter/tools/lipsum.py @@ -111,7 +111,7 @@ class GuiLipsum(QDialog): return - def __del__(self): + def __del__(self): # pragma: no cover logger.debug("Delete: GuiLipsum") return diff --git a/novelwriter/tools/manusbuild.py b/novelwriter/tools/manusbuild.py index 5b21cdbf..8ba93af7 100644 --- a/novelwriter/tools/manusbuild.py +++ b/novelwriter/tools/manusbuild.py @@ -235,8 +235,7 @@ class GuiManuscriptBuild(QDialog): return - def __del__(self): - """For debug use only.""" + def __del__(self): # pragma: no cover logger.debug("Delete: GuiManuscriptBuild") return diff --git a/novelwriter/tools/manuscript.py b/novelwriter/tools/manuscript.py index 11729bce..b2344aac 100644 --- a/novelwriter/tools/manuscript.py +++ b/novelwriter/tools/manuscript.py @@ -196,8 +196,7 @@ class GuiManuscript(QDialog): return - def __del__(self): - """For debug use only.""" + def __del__(self): # pragma: no cover logger.debug("Delete: GuiManuscript") return diff --git a/novelwriter/tools/manussettings.py b/novelwriter/tools/manussettings.py index c9fd824c..903284a0 100644 --- a/novelwriter/tools/manussettings.py +++ b/novelwriter/tools/manussettings.py @@ -167,8 +167,7 @@ class GuiBuildSettings(QDialog): return - def __del__(self): - """For debug use only.""" + def __del__(self): # pragma: no cover logger.debug("Delete: GuiBuildSettings") def loadContent(self): diff --git a/novelwriter/tools/projwizard.py b/novelwriter/tools/projwizard.py index 1fe6cdc2..f147dd0f 100644 --- a/novelwriter/tools/projwizard.py +++ b/novelwriter/tools/projwizard.py @@ -80,7 +80,7 @@ class GuiProjectWizard(QWizard): return - def __del__(self): + def __del__(self): # pragma: no cover logger.debug("Delete: GuiProjectWizard") return diff --git a/novelwriter/tools/writingstats.py b/novelwriter/tools/writingstats.py index d4223e60..ce6833bb 100644 --- a/novelwriter/tools/writingstats.py +++ b/novelwriter/tools/writingstats.py @@ -297,7 +297,7 @@ class GuiWritingStats(QDialog): return - def __del__(self): + def __del__(self): # pragma: no cover logger.debug("Delete: GuiWritingStats") return diff --git a/tests/conftest.py b/tests/conftest.py index a12bdecc..acb1ae19 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -61,8 +61,7 @@ def resetConfigVars(): @pytest.fixture(scope="session", autouse=True) def sessionFixture(): - """A session wide fixture to set up the test environment. - """ + """A session wide fixture to set up the test environment.""" if _TMP_ROOT.exists(): shutil.rmtree(_TMP_ROOT) _TMP_ROOT.mkdir() @@ -111,8 +110,7 @@ def tstPaths(): @pytest.fixture(scope="function") def fncPath(): - """A temporary folder for a single test function. - """ + """A temporary folder for a single test function.""" fncPath = _TMP_ROOT / "function" if fncPath.is_dir(): shutil.rmtree(fncPath) @@ -139,16 +137,14 @@ def projPath(fncPath): @pytest.fixture(scope="function") def mockGUI(): - """Create a mock instance of novelWriter's main GUI class. - """ + """Create a mock instance of novelWriter's main GUI class.""" theGui = MockGuiMain() return theGui @pytest.fixture(scope="function") def nwGUI(qtbot, monkeypatch, functionFixture): - """Create an instance of the novelWriter GUI. - """ + """Create an instance of the novelWriter GUI.""" monkeypatch.setattr(QMessageBox, "warning", lambda *a: QMessageBox.Ok) monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Ok) monkeypatch.setattr(QMessageBox, "information", lambda *a: QMessageBox.Ok) diff --git a/tests/test_dialogs/test_dlg_wordlist.py b/tests/test_dialogs/test_dlg_wordlist.py index dfc4280f..8d698851 100644 --- a/tests/test_dialogs/test_dlg_wordlist.py +++ b/tests/test_dialogs/test_dlg_wordlist.py @@ -24,9 +24,9 @@ import pytest from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QDialog, QAction -from tools import buildTestProject, writeFile, readFile, getGuiItem -from mocked import causeOSError +from tools import buildTestProject, getGuiItem +from novelwriter.core.spellcheck import UserDictionary from novelwriter.dialogs.wordlist import GuiWordList @@ -42,7 +42,6 @@ def testDlgWordList_Dialog(qtbot, monkeypatch, nwGUI, projPath): # Open project nwGUI.openProject(projPath) - dictFile = projPath / "meta" / "wordlist.txt" # Load the dialog nwGUI.mainMenu.aEditWordList.activate(QAction.Trigger) @@ -56,15 +55,15 @@ def testDlgWordList_Dialog(qtbot, monkeypatch, nwGUI, projPath): assert wList.listBox.count() == 0 # Add words - writeFile(dictFile, ( - "word_a\n" - "word_c\n" - "word_g\n" - " \n" # Should be ignored - "word_f\n" - "word_b\n" - )) - assert wList._loadWordList() + userDict = UserDictionary(nwGUI.theProject) + userDict.add("word_a") + userDict.add("word_c") + userDict.add("word_g") + userDict.add("word_f") + userDict.add("word_b") + userDict.save() + + wList._loadWordList() # Check that the content was loaded assert wList.listBox.item(0).text() == "word_a" @@ -72,18 +71,22 @@ def testDlgWordList_Dialog(qtbot, monkeypatch, nwGUI, projPath): assert wList.listBox.item(2).text() == "word_c" assert wList.listBox.item(3).text() == "word_f" assert wList.listBox.item(4).text() == "word_g" + assert wList.listBox.count() == 5 - # Add a blank word + # Add a blank word, which is ignored wList.newEntry.setText(" ") - assert not wList._doAdd() + wList._doAdd() + assert wList.listBox.count() == 5 - # Add an existing word + # Add an existing word, which is ignored wList.newEntry.setText("word_c") - assert not wList._doAdd() + wList._doAdd() + assert wList.listBox.count() == 5 # Add a new word wList.newEntry.setText("word_d") - assert wList._doAdd() + wList._doAdd() + assert wList.listBox.count() == 6 # Check that the content now assert wList.listBox.item(0).text() == "word_a" @@ -95,7 +98,7 @@ def testDlgWordList_Dialog(qtbot, monkeypatch, nwGUI, projPath): # Delete a word wList.newEntry.setText("delete_me") - assert wList._doAdd() + wList._doAdd() assert wList.listBox.item(0).text() == "delete_me" delItem = wList.listBox.findItems("delete_me", Qt.MatchExactly)[0] @@ -107,18 +110,14 @@ def testDlgWordList_Dialog(qtbot, monkeypatch, nwGUI, projPath): # Save files assert wList._doSave() - assert readFile(dictFile) == ( - "word_a\n" - "word_b\n" - "word_c\n" - "word_d\n" - "word_f\n" - "word_g\n" - ) - - # Save again and make it fail - monkeypatch.setattr("builtins.open", causeOSError) - assert not wList._doSave() + userDict.load() + assert len(list(userDict)) == 6 + assert "word_a" in userDict + assert "word_b" in userDict + assert "word_c" in userDict + assert "word_d" in userDict + assert "word_f" in userDict + assert "word_g" in userDict # qtbot.stop() wList._doClose()