Remove nw prefix from common test files

This commit is contained in:
Veronica K. B. Olsen
2020-12-03 17:39:42 +01:00
parent fba4d5d04d
commit c13bd18271
9 changed files with 19 additions and 128 deletions
+1 -1
View File
@@ -7,7 +7,7 @@ import pytest
import shutil import shutil
import os import os
from nwdummy import DummyMain from dummy import DummyMain
from PyQt5.QtWidgets import QMessageBox from PyQt5.QtWidgets import QMessageBox
+12
View File
@@ -2,6 +2,10 @@
"""novelWriter Test Dummy GUI Classes """novelWriter Test Dummy GUI Classes
""" """
# =========================================================================== #
# Mock GUI
# =========================================================================== #
class DummyMain(): class DummyMain():
def __init__(self): def __init__(self):
@@ -37,3 +41,11 @@ class StatusBar():
return return
# END Class StatusBar # END Class StatusBar
# =========================================================================== #
# Error Functions
# Dummy functions that will raise errors instead.
# =========================================================================== #
def dummyIO(*args, **kwargs):
raise OSError
+1 -1
View File
@@ -9,7 +9,7 @@ from nw.common import (
checkString, checkBool, checkInt, colRange, formatInt, transferCase, checkString, checkBool, checkInt, colRange, formatInt, transferCase,
fuzzyTime, checkHandle, formatTimeStamp, formatTime fuzzyTime, checkHandle, formatTimeStamp, formatTime
) )
from nwtools import cmpList from tools import cmpList
@pytest.mark.core @pytest.mark.core
def testCheckString(): def testCheckString():
+1 -1
View File
@@ -5,7 +5,7 @@
import pytest import pytest
import os import os
from nwtools import cmpFiles from tools import cmpFiles
@pytest.mark.core @pytest.mark.core
def testConfigCore(tmpConf, tmpDir, refDir): def testConfigCore(tmpConf, tmpDir, refDir):
+1 -1
View File
@@ -8,7 +8,7 @@ import json
from shutil import copyfile from shutil import copyfile
from nwtools import cmpFiles from tools import cmpFiles
from nw.core.project import NWProject from nw.core.project import NWProject
from nw.core.index import NWIndex from nw.core.index import NWIndex
+1 -1
View File
@@ -9,7 +9,7 @@ import os
import sys import sys
from shutil import copyfile from shutil import copyfile
from nwtools import cmpFiles, getGuiItem from tools import cmpFiles, getGuiItem
from PyQt5.QtCore import Qt, QItemSelectionModel from PyQt5.QtCore import Qt, QItemSelectionModel
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
+1 -1
View File
@@ -9,7 +9,7 @@ import os
import sys import sys
from shutil import copyfile from shutil import copyfile
from nwtools import cmpFiles from tools import cmpFiles
from PyQt5.QtCore import Qt, QUrl, QPoint, QItemSelectionModel from PyQt5.QtCore import Qt, QUrl, QPoint, QItemSelectionModel
from PyQt5.QtGui import QTextCursor, QColor, QPixmap, QIcon, QTextBlock from PyQt5.QtGui import QTextCursor, QColor, QPixmap, QIcon, QTextBlock
+1 -122
View File
@@ -8,7 +8,7 @@ import os
from shutil import copyfile from shutil import copyfile
from zipfile import ZipFile from zipfile import ZipFile
from nwtools import cmpFiles from tools import cmpFiles
from nw.core.project import NWProject from nw.core.project import NWProject
from nw.core.spellcheck import NWSpellEnchant, NWSpellSimple 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.setBookAuthors(" Jane Doe \n John Doh \n ")
assert theProject.bookAuthors == ["Jane Doe", "John Doh"] 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 @pytest.mark.project
def testProjectOrphanedFiles(dummyGUI, nwLipsum): def testProjectOrphanedFiles(dummyGUI, nwLipsum):
"""Check that files in the content folder that are not tracked in """Check that files in the content folder that are not tracked in
View File