Fix test coverage of wordlist dialog
This commit is contained in:
@@ -114,7 +114,7 @@ class GuiAbout(QDialog):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self): # pragma: no cover
|
||||||
logger.debug("Delete: GuiAbout")
|
logger.debug("Delete: GuiAbout")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ class GuiDocMerge(QDialog):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self): # pragma: no cover
|
||||||
logger.debug("Delete: GuiDocMerge")
|
logger.debug("Delete: GuiDocMerge")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ class GuiDocSplit(QDialog):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self): # pragma: no cover
|
||||||
logger.debug("Delete: GuiDocSplit")
|
logger.debug("Delete: GuiDocSplit")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ class GuiPreferences(NPagedDialog):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self): # pragma: no cover
|
||||||
logger.debug("Delete: GuiPreferences")
|
logger.debug("Delete: GuiPreferences")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ class GuiProjectDetails(NPagedDialog):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self): # pragma: no cover
|
||||||
logger.debug("Delete: GuiProjectDetails")
|
logger.debug("Delete: GuiProjectDetails")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ class GuiProjectLoad(QDialog):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self): # pragma: no cover
|
||||||
logger.debug("Delete: GuiProjectLoad")
|
logger.debug("Delete: GuiProjectLoad")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ class GuiProjectSettings(NPagedDialog):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self): # pragma: no cover
|
||||||
logger.debug("Delete: GuiProjectSettings")
|
logger.debug("Delete: GuiProjectSettings")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ class GuiUpdates(QDialog):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self): # pragma: no cover
|
||||||
logger.debug("Delete: GuiUpdates")
|
logger.debug("Delete: GuiUpdates")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ class GuiWordList(QDialog):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self): # pragma: no cover
|
||||||
logger.debug("Delete: GuiWordList")
|
logger.debug("Delete: GuiWordList")
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -122,25 +122,25 @@ class GuiWordList(QDialog):
|
|||||||
# Slots
|
# Slots
|
||||||
##
|
##
|
||||||
|
|
||||||
def _doAdd(self) -> bool:
|
def _doAdd(self):
|
||||||
"""Add a new word to the word list."""
|
"""Add a new word to the word list."""
|
||||||
word = self.newEntry.text().strip()
|
word = self.newEntry.text().strip()
|
||||||
if word == "":
|
if word == "":
|
||||||
self.mainGui.makeAlert(self.tr(
|
self.mainGui.makeAlert(self.tr(
|
||||||
"Cannot add a blank word."
|
"Cannot add a blank word."
|
||||||
), nwAlert.ERROR)
|
), nwAlert.ERROR)
|
||||||
return False
|
return
|
||||||
|
|
||||||
if self.listBox.findItems(word, Qt.MatchExactly):
|
if self.listBox.findItems(word, Qt.MatchExactly):
|
||||||
self.mainGui.makeAlert(self.tr(
|
self.mainGui.makeAlert(self.tr(
|
||||||
"The word '{0}' is already in the word list."
|
"The word '{0}' is already in the word list."
|
||||||
).format(word), nwAlert.ERROR)
|
).format(word), nwAlert.ERROR)
|
||||||
return False
|
return
|
||||||
|
|
||||||
self.listBox.addItem(word)
|
self.listBox.addItem(word)
|
||||||
self.newEntry.setText("")
|
self.newEntry.setText("")
|
||||||
|
|
||||||
return True
|
return
|
||||||
|
|
||||||
def _doDelete(self):
|
def _doDelete(self):
|
||||||
"""Delete the selected item."""
|
"""Delete the selected item."""
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ class GuiLipsum(QDialog):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self): # pragma: no cover
|
||||||
logger.debug("Delete: GuiLipsum")
|
logger.debug("Delete: GuiLipsum")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -235,8 +235,7 @@ class GuiManuscriptBuild(QDialog):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self): # pragma: no cover
|
||||||
"""For debug use only."""
|
|
||||||
logger.debug("Delete: GuiManuscriptBuild")
|
logger.debug("Delete: GuiManuscriptBuild")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -196,8 +196,7 @@ class GuiManuscript(QDialog):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self): # pragma: no cover
|
||||||
"""For debug use only."""
|
|
||||||
logger.debug("Delete: GuiManuscript")
|
logger.debug("Delete: GuiManuscript")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -167,8 +167,7 @@ class GuiBuildSettings(QDialog):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self): # pragma: no cover
|
||||||
"""For debug use only."""
|
|
||||||
logger.debug("Delete: GuiBuildSettings")
|
logger.debug("Delete: GuiBuildSettings")
|
||||||
|
|
||||||
def loadContent(self):
|
def loadContent(self):
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ class GuiProjectWizard(QWizard):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self): # pragma: no cover
|
||||||
logger.debug("Delete: GuiProjectWizard")
|
logger.debug("Delete: GuiProjectWizard")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -297,7 +297,7 @@ class GuiWritingStats(QDialog):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self): # pragma: no cover
|
||||||
logger.debug("Delete: GuiWritingStats")
|
logger.debug("Delete: GuiWritingStats")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
+4
-8
@@ -61,8 +61,7 @@ def resetConfigVars():
|
|||||||
|
|
||||||
@pytest.fixture(scope="session", autouse=True)
|
@pytest.fixture(scope="session", autouse=True)
|
||||||
def sessionFixture():
|
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():
|
if _TMP_ROOT.exists():
|
||||||
shutil.rmtree(_TMP_ROOT)
|
shutil.rmtree(_TMP_ROOT)
|
||||||
_TMP_ROOT.mkdir()
|
_TMP_ROOT.mkdir()
|
||||||
@@ -111,8 +110,7 @@ def tstPaths():
|
|||||||
|
|
||||||
@pytest.fixture(scope="function")
|
@pytest.fixture(scope="function")
|
||||||
def fncPath():
|
def fncPath():
|
||||||
"""A temporary folder for a single test function.
|
"""A temporary folder for a single test function."""
|
||||||
"""
|
|
||||||
fncPath = _TMP_ROOT / "function"
|
fncPath = _TMP_ROOT / "function"
|
||||||
if fncPath.is_dir():
|
if fncPath.is_dir():
|
||||||
shutil.rmtree(fncPath)
|
shutil.rmtree(fncPath)
|
||||||
@@ -139,16 +137,14 @@ def projPath(fncPath):
|
|||||||
|
|
||||||
@pytest.fixture(scope="function")
|
@pytest.fixture(scope="function")
|
||||||
def mockGUI():
|
def mockGUI():
|
||||||
"""Create a mock instance of novelWriter's main GUI class.
|
"""Create a mock instance of novelWriter's main GUI class."""
|
||||||
"""
|
|
||||||
theGui = MockGuiMain()
|
theGui = MockGuiMain()
|
||||||
return theGui
|
return theGui
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
@pytest.fixture(scope="function")
|
||||||
def nwGUI(qtbot, monkeypatch, functionFixture):
|
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, "warning", lambda *a: QMessageBox.Ok)
|
||||||
monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Ok)
|
monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Ok)
|
||||||
monkeypatch.setattr(QMessageBox, "information", lambda *a: QMessageBox.Ok)
|
monkeypatch.setattr(QMessageBox, "information", lambda *a: QMessageBox.Ok)
|
||||||
|
|||||||
@@ -24,9 +24,9 @@ import pytest
|
|||||||
from PyQt5.QtCore import Qt
|
from PyQt5.QtCore import Qt
|
||||||
from PyQt5.QtWidgets import QDialog, QAction
|
from PyQt5.QtWidgets import QDialog, QAction
|
||||||
|
|
||||||
from tools import buildTestProject, writeFile, readFile, getGuiItem
|
from tools import buildTestProject, getGuiItem
|
||||||
from mocked import causeOSError
|
|
||||||
|
|
||||||
|
from novelwriter.core.spellcheck import UserDictionary
|
||||||
from novelwriter.dialogs.wordlist import GuiWordList
|
from novelwriter.dialogs.wordlist import GuiWordList
|
||||||
|
|
||||||
|
|
||||||
@@ -42,7 +42,6 @@ def testDlgWordList_Dialog(qtbot, monkeypatch, nwGUI, projPath):
|
|||||||
|
|
||||||
# Open project
|
# Open project
|
||||||
nwGUI.openProject(projPath)
|
nwGUI.openProject(projPath)
|
||||||
dictFile = projPath / "meta" / "wordlist.txt"
|
|
||||||
|
|
||||||
# Load the dialog
|
# Load the dialog
|
||||||
nwGUI.mainMenu.aEditWordList.activate(QAction.Trigger)
|
nwGUI.mainMenu.aEditWordList.activate(QAction.Trigger)
|
||||||
@@ -56,15 +55,15 @@ def testDlgWordList_Dialog(qtbot, monkeypatch, nwGUI, projPath):
|
|||||||
assert wList.listBox.count() == 0
|
assert wList.listBox.count() == 0
|
||||||
|
|
||||||
# Add words
|
# Add words
|
||||||
writeFile(dictFile, (
|
userDict = UserDictionary(nwGUI.theProject)
|
||||||
"word_a\n"
|
userDict.add("word_a")
|
||||||
"word_c\n"
|
userDict.add("word_c")
|
||||||
"word_g\n"
|
userDict.add("word_g")
|
||||||
" \n" # Should be ignored
|
userDict.add("word_f")
|
||||||
"word_f\n"
|
userDict.add("word_b")
|
||||||
"word_b\n"
|
userDict.save()
|
||||||
))
|
|
||||||
assert wList._loadWordList()
|
wList._loadWordList()
|
||||||
|
|
||||||
# Check that the content was loaded
|
# Check that the content was loaded
|
||||||
assert wList.listBox.item(0).text() == "word_a"
|
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(2).text() == "word_c"
|
||||||
assert wList.listBox.item(3).text() == "word_f"
|
assert wList.listBox.item(3).text() == "word_f"
|
||||||
assert wList.listBox.item(4).text() == "word_g"
|
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(" ")
|
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")
|
wList.newEntry.setText("word_c")
|
||||||
assert not wList._doAdd()
|
wList._doAdd()
|
||||||
|
assert wList.listBox.count() == 5
|
||||||
|
|
||||||
# Add a new word
|
# Add a new word
|
||||||
wList.newEntry.setText("word_d")
|
wList.newEntry.setText("word_d")
|
||||||
assert wList._doAdd()
|
wList._doAdd()
|
||||||
|
assert wList.listBox.count() == 6
|
||||||
|
|
||||||
# Check that the content now
|
# Check that the content now
|
||||||
assert wList.listBox.item(0).text() == "word_a"
|
assert wList.listBox.item(0).text() == "word_a"
|
||||||
@@ -95,7 +98,7 @@ def testDlgWordList_Dialog(qtbot, monkeypatch, nwGUI, projPath):
|
|||||||
|
|
||||||
# Delete a word
|
# Delete a word
|
||||||
wList.newEntry.setText("delete_me")
|
wList.newEntry.setText("delete_me")
|
||||||
assert wList._doAdd()
|
wList._doAdd()
|
||||||
assert wList.listBox.item(0).text() == "delete_me"
|
assert wList.listBox.item(0).text() == "delete_me"
|
||||||
|
|
||||||
delItem = wList.listBox.findItems("delete_me", Qt.MatchExactly)[0]
|
delItem = wList.listBox.findItems("delete_me", Qt.MatchExactly)[0]
|
||||||
@@ -107,18 +110,14 @@ def testDlgWordList_Dialog(qtbot, monkeypatch, nwGUI, projPath):
|
|||||||
|
|
||||||
# Save files
|
# Save files
|
||||||
assert wList._doSave()
|
assert wList._doSave()
|
||||||
assert readFile(dictFile) == (
|
userDict.load()
|
||||||
"word_a\n"
|
assert len(list(userDict)) == 6
|
||||||
"word_b\n"
|
assert "word_a" in userDict
|
||||||
"word_c\n"
|
assert "word_b" in userDict
|
||||||
"word_d\n"
|
assert "word_c" in userDict
|
||||||
"word_f\n"
|
assert "word_d" in userDict
|
||||||
"word_g\n"
|
assert "word_f" in userDict
|
||||||
)
|
assert "word_g" in userDict
|
||||||
|
|
||||||
# Save again and make it fail
|
|
||||||
monkeypatch.setattr("builtins.open", causeOSError)
|
|
||||||
assert not wList._doSave()
|
|
||||||
|
|
||||||
# qtbot.stop()
|
# qtbot.stop()
|
||||||
wList._doClose()
|
wList._doClose()
|
||||||
|
|||||||
Reference in New Issue
Block a user