Cleaned up tests for syntax
This commit is contained in:
+3
-1
@@ -2,7 +2,9 @@
|
|||||||
"""novelWriter Test Config
|
"""novelWriter Test Config
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, pytest, shutil
|
import sys
|
||||||
|
import pytest
|
||||||
|
import shutil
|
||||||
from os import path, mkdir
|
from os import path, mkdir
|
||||||
|
|
||||||
sys.path.insert(1, path.abspath(path.join(path.dirname(__file__), path.pardir)))
|
sys.path.insert(1, path.abspath(path.join(path.dirname(__file__), path.pardir)))
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
"""novelWriter Test Dummy GUI Classes
|
"""novelWriter Test Dummy GUI Classes
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from nw.constants import nwAlert
|
|
||||||
|
|
||||||
class DummyMain():
|
class DummyMain():
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import pstats
|
|||||||
|
|
||||||
from os import path
|
from os import path
|
||||||
|
|
||||||
profDir = path.abspath(path.join(path.dirname(__file__),"..","prof"))
|
profDir = path.abspath(path.join(path.dirname(__file__), path.pardir, "prof"))
|
||||||
|
|
||||||
print("")
|
print("")
|
||||||
print("Profiles directory: %s" % profDir)
|
print("Profiles directory: %s" % profDir)
|
||||||
|
|||||||
+26
-11
@@ -2,8 +2,8 @@
|
|||||||
"""novelWriter Common Class Tester
|
"""novelWriter Common Class Tester
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import nw, pytest
|
import pytest
|
||||||
from nw.common import *
|
from nw.common import checkString, checkBool, checkInt, colRange
|
||||||
from nwtools import cmpList
|
from nwtools import cmpList
|
||||||
|
|
||||||
@pytest.mark.core
|
@pytest.mark.core
|
||||||
@@ -29,11 +29,11 @@ def testCheckInt():
|
|||||||
def testCheckBool():
|
def testCheckBool():
|
||||||
assert checkBool(None, 3, True) is None
|
assert checkBool(None, 3, True) is None
|
||||||
assert checkBool("None", 3, True) is None
|
assert checkBool("None", 3, True) is None
|
||||||
assert checkBool("True", False,False) == True
|
assert checkBool("True", False, False)
|
||||||
assert checkBool("False",True, False) == False
|
assert not checkBool("False", True, False)
|
||||||
assert checkBool("Boo", None, False) is None
|
assert checkBool("Boo", None, False) is None
|
||||||
assert checkBool(0, None, False) == False
|
assert not checkBool(0, None, False)
|
||||||
assert checkBool(1, None, False) == True
|
assert checkBool(1, None, False)
|
||||||
assert checkBool(2, None, False) is None
|
assert checkBool(2, None, False) is None
|
||||||
assert checkBool(0.0, None, False) is None
|
assert checkBool(0.0, None, False) is None
|
||||||
assert checkBool(1.0, None, False) is None
|
assert checkBool(1.0, None, False) is None
|
||||||
@@ -42,8 +42,23 @@ def testCheckBool():
|
|||||||
@pytest.mark.core
|
@pytest.mark.core
|
||||||
def testColRange():
|
def testColRange():
|
||||||
assert colRange([0, 0], [0, 0], 0) is None
|
assert colRange([0, 0], [0, 0], 0) is None
|
||||||
assert cmpList(colRange([200,50,0], [50,200,0], 1), [200,50,0])
|
assert cmpList(
|
||||||
assert cmpList(colRange([200,50,0], [50,200,0], 2), [[200,50,0],[50,200,0]])
|
colRange([200, 50, 0], [50, 200, 0], 1),
|
||||||
assert cmpList(colRange([200,50,0], [50,200,0], 3), [[200,50,0],[125,125,0],[50,200,0]])
|
[200, 50, 0]
|
||||||
assert cmpList(colRange([200,50,0], [50,200,0], 4), [[200,50,0],[150,100,0],[100,150,0],[50,200,0]])
|
)
|
||||||
assert cmpList(colRange([200,50,0], [50,200,0], 5), [[200,50,0],[162,87,0],[124,124,0],[86,161,0],[50,200,0]])
|
assert cmpList(
|
||||||
|
colRange([200, 50, 0], [50, 200, 0], 2),
|
||||||
|
[[200, 50, 0], [50, 200, 0]]
|
||||||
|
)
|
||||||
|
assert cmpList(
|
||||||
|
colRange([200, 50, 0], [50, 200, 0], 3),
|
||||||
|
[[200, 50, 0], [125, 125, 0], [50, 200, 0]]
|
||||||
|
)
|
||||||
|
assert cmpList(
|
||||||
|
colRange([200, 50, 0], [50, 200, 0], 4),
|
||||||
|
[[200, 50, 0], [150, 100, 0], [100, 150, 0], [50, 200, 0]]
|
||||||
|
)
|
||||||
|
assert cmpList(
|
||||||
|
colRange([200, 50, 0], [50, 200, 0], 5),
|
||||||
|
[[200, 50, 0], [162, 87, 0], [124, 124, 0], [86, 161, 0], [50, 200, 0]]
|
||||||
|
)
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
"""novelWriter Config Class Tester
|
"""novelWriter Config Class Tester
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import nw, pytest
|
import pytest
|
||||||
from nwtools import *
|
from nwtools import cmpFiles
|
||||||
from os import path
|
from os import path
|
||||||
from nw.config import Config
|
from nw.config import Config
|
||||||
|
|
||||||
|
|||||||
+36
-20
@@ -2,17 +2,19 @@
|
|||||||
"""novelWriter Main GUI Class Tester
|
"""novelWriter Main GUI Class Tester
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import nw, pytest, sys, json
|
import nw
|
||||||
from nwtools import *
|
import pytest
|
||||||
|
import json
|
||||||
|
from nwtools import cmpFiles
|
||||||
|
|
||||||
from os import path, unlink
|
from os import path
|
||||||
from PyQt5.QtCore import Qt
|
from PyQt5.QtCore import Qt
|
||||||
|
|
||||||
from nw.gui import (
|
from nw.gui import (
|
||||||
GuiProjectSettings, GuiItemEditor, GuiAbout, GuiBuildNovel,
|
GuiProjectSettings, GuiItemEditor, GuiAbout, GuiBuildNovel,
|
||||||
GuiDocMerge, GuiDocSplit, GuiWritingStats, GuiProjectWizard
|
GuiDocMerge, GuiDocSplit, GuiWritingStats, GuiProjectWizard
|
||||||
)
|
)
|
||||||
from nw.constants import *
|
from nw.constants import nwItemType, nwItemLayout, nwItemClass, nwDocAction
|
||||||
|
|
||||||
keyDelay = 2
|
keyDelay = 2
|
||||||
stepDelay = 20
|
stepDelay = 20
|
||||||
@@ -41,7 +43,7 @@ def testMainWindows(qtbot, nwTempGUI, nwRef, nwTemp):
|
|||||||
assert nwGUI.theProject.projName == ""
|
assert nwGUI.theProject.projName == ""
|
||||||
assert nwGUI.theProject.bookTitle == ""
|
assert nwGUI.theProject.bookTitle == ""
|
||||||
assert len(nwGUI.theProject.bookAuthors) == 0
|
assert len(nwGUI.theProject.bookAuthors) == 0
|
||||||
assert nwGUI.theProject.spellCheck == False
|
assert not nwGUI.theProject.spellCheck
|
||||||
|
|
||||||
# Check the files
|
# Check the files
|
||||||
projFile = path.join(nwTempGUI, "nwProject.nwx")
|
projFile = path.join(nwTempGUI, "nwProject.nwx")
|
||||||
@@ -65,7 +67,7 @@ def testMainWindows(qtbot, nwTempGUI, nwRef, nwTemp):
|
|||||||
assert nwGUI.theProject.projName == "New Project"
|
assert nwGUI.theProject.projName == "New Project"
|
||||||
assert nwGUI.theProject.bookTitle == ""
|
assert nwGUI.theProject.bookTitle == ""
|
||||||
assert len(nwGUI.theProject.bookAuthors) == 0
|
assert len(nwGUI.theProject.bookAuthors) == 0
|
||||||
assert nwGUI.theProject.spellCheck == False
|
assert not nwGUI.theProject.spellCheck
|
||||||
|
|
||||||
# Check that tree items have been created
|
# Check that tree items have been created
|
||||||
assert nwGUI.treeView._getTreeItem("73475cb40a568") is not None
|
assert nwGUI.treeView._getTreeItem("73475cb40a568") is not None
|
||||||
@@ -214,7 +216,10 @@ def testMainWindows(qtbot, nwTempGUI, nwRef, nwTemp):
|
|||||||
qtbot.keyClick(nwGUI.docEditor, Qt.Key_Return, delay=keyDelay)
|
qtbot.keyClick(nwGUI.docEditor, Qt.Key_Return, delay=keyDelay)
|
||||||
qtbot.keyClick(nwGUI.docEditor, Qt.Key_Return, delay=keyDelay)
|
qtbot.keyClick(nwGUI.docEditor, Qt.Key_Return, delay=keyDelay)
|
||||||
|
|
||||||
for c in "This is another paragraph of much longer dummy text. It is in fact very very dumb dummy text! ":
|
for c in (
|
||||||
|
"This is another paragraph of much longer dummy text. "
|
||||||
|
"It is in fact very very dumb dummy text! "
|
||||||
|
):
|
||||||
qtbot.keyClick(nwGUI.docEditor, c, delay=keyDelay)
|
qtbot.keyClick(nwGUI.docEditor, c, delay=keyDelay)
|
||||||
for c in "We can also try replacing \"quotes\", even single's quotes are replaced. ":
|
for c in "We can also try replacing \"quotes\", even single's quotes are replaced. ":
|
||||||
qtbot.keyClick(nwGUI.docEditor, c, delay=keyDelay)
|
qtbot.keyClick(nwGUI.docEditor, c, delay=keyDelay)
|
||||||
@@ -859,12 +864,12 @@ def testNewProjectWizard(qtbot, nwTempGUI, nwLipsum, nwRef, nwTemp):
|
|||||||
]
|
]
|
||||||
assert projData["numChapters"] == 5
|
assert projData["numChapters"] == 5
|
||||||
assert projData["numScenes"] == 5
|
assert projData["numScenes"] == 5
|
||||||
assert projData["chFolders"] == True
|
assert projData["chFolders"]
|
||||||
else:
|
else:
|
||||||
assert projData["addRoots"] == []
|
assert projData["addRoots"] == []
|
||||||
assert projData["numChapters"] == 0
|
assert projData["numChapters"] == 0
|
||||||
assert projData["numScenes"] == 0
|
assert projData["numScenes"] == 0
|
||||||
assert projData["chFolders"] == False
|
assert not projData["chFolders"]
|
||||||
|
|
||||||
# qtbot.stopForInteraction()
|
# qtbot.stopForInteraction()
|
||||||
nwGUI.closeMain()
|
nwGUI.closeMain()
|
||||||
@@ -890,7 +895,8 @@ def testDocAction(qtbot, nwTempGUI, nwLipsum, nwRef, nwTemp):
|
|||||||
|
|
||||||
# Bold
|
# Bold
|
||||||
assert nwGUI.passDocumentAction(nwDocAction.STRONG)
|
assert nwGUI.passDocumentAction(nwDocAction.STRONG)
|
||||||
assert nwGUI.docEditor.getText()[27:78] == "**Pellentesque** nec erat ut nulla posuere commodo."
|
fmtStr = "**Pellentesque** nec erat ut nulla posuere commodo."
|
||||||
|
assert nwGUI.docEditor.getText()[27:78] == fmtStr
|
||||||
qtbot.wait(stepDelay)
|
qtbot.wait(stepDelay)
|
||||||
assert nwGUI.passDocumentAction(nwDocAction.STRONG)
|
assert nwGUI.passDocumentAction(nwDocAction.STRONG)
|
||||||
assert nwGUI.docEditor.getText()[27:74] == cleanText
|
assert nwGUI.docEditor.getText()[27:74] == cleanText
|
||||||
@@ -898,7 +904,8 @@ def testDocAction(qtbot, nwTempGUI, nwLipsum, nwRef, nwTemp):
|
|||||||
|
|
||||||
# Italic
|
# Italic
|
||||||
assert nwGUI.passDocumentAction(nwDocAction.EMPH)
|
assert nwGUI.passDocumentAction(nwDocAction.EMPH)
|
||||||
assert nwGUI.docEditor.getText()[27:76] == "_Pellentesque_ nec erat ut nulla posuere commodo."
|
fmtStr = "_Pellentesque_ nec erat ut nulla posuere commodo."
|
||||||
|
assert nwGUI.docEditor.getText()[27:76] == fmtStr
|
||||||
qtbot.wait(stepDelay)
|
qtbot.wait(stepDelay)
|
||||||
assert nwGUI.passDocumentAction(nwDocAction.EMPH)
|
assert nwGUI.passDocumentAction(nwDocAction.EMPH)
|
||||||
assert nwGUI.docEditor.getText()[27:74] == cleanText
|
assert nwGUI.docEditor.getText()[27:74] == cleanText
|
||||||
@@ -906,7 +913,8 @@ def testDocAction(qtbot, nwTempGUI, nwLipsum, nwRef, nwTemp):
|
|||||||
|
|
||||||
# Strikethrough
|
# Strikethrough
|
||||||
assert nwGUI.passDocumentAction(nwDocAction.STRIKE)
|
assert nwGUI.passDocumentAction(nwDocAction.STRIKE)
|
||||||
assert nwGUI.docEditor.getText()[27:78] == "~~Pellentesque~~ nec erat ut nulla posuere commodo."
|
fmtStr = "~~Pellentesque~~ nec erat ut nulla posuere commodo."
|
||||||
|
assert nwGUI.docEditor.getText()[27:78] == fmtStr
|
||||||
qtbot.wait(stepDelay)
|
qtbot.wait(stepDelay)
|
||||||
assert nwGUI.passDocumentAction(nwDocAction.STRIKE)
|
assert nwGUI.passDocumentAction(nwDocAction.STRIKE)
|
||||||
assert nwGUI.docEditor.getText()[27:74] == cleanText
|
assert nwGUI.docEditor.getText()[27:74] == cleanText
|
||||||
@@ -925,7 +933,8 @@ def testDocAction(qtbot, nwTempGUI, nwLipsum, nwRef, nwTemp):
|
|||||||
|
|
||||||
# Double Quotes
|
# Double Quotes
|
||||||
assert nwGUI.passDocumentAction(nwDocAction.D_QUOTE)
|
assert nwGUI.passDocumentAction(nwDocAction.D_QUOTE)
|
||||||
assert nwGUI.docEditor.getText()[27:76] == "“Pellentesque” nec erat ut nulla posuere commodo."
|
fmtStr = "“Pellentesque” nec erat ut nulla posuere commodo."
|
||||||
|
assert nwGUI.docEditor.getText()[27:76] == fmtStr
|
||||||
qtbot.wait(stepDelay)
|
qtbot.wait(stepDelay)
|
||||||
assert nwGUI.passDocumentAction(nwDocAction.UNDO)
|
assert nwGUI.passDocumentAction(nwDocAction.UNDO)
|
||||||
assert nwGUI.docEditor.getText()[27:74] == cleanText
|
assert nwGUI.docEditor.getText()[27:74] == cleanText
|
||||||
@@ -933,7 +942,8 @@ def testDocAction(qtbot, nwTempGUI, nwLipsum, nwRef, nwTemp):
|
|||||||
|
|
||||||
# Single Quotes
|
# Single Quotes
|
||||||
assert nwGUI.passDocumentAction(nwDocAction.S_QUOTE)
|
assert nwGUI.passDocumentAction(nwDocAction.S_QUOTE)
|
||||||
assert nwGUI.docEditor.getText()[27:76] == "‘Pellentesque’ nec erat ut nulla posuere commodo."
|
fmtStr = "‘Pellentesque’ nec erat ut nulla posuere commodo."
|
||||||
|
assert nwGUI.docEditor.getText()[27:76] == fmtStr
|
||||||
qtbot.wait(stepDelay)
|
qtbot.wait(stepDelay)
|
||||||
assert nwGUI.passDocumentAction(nwDocAction.UNDO)
|
assert nwGUI.passDocumentAction(nwDocAction.UNDO)
|
||||||
assert nwGUI.docEditor.getText()[27:74] == cleanText
|
assert nwGUI.docEditor.getText()[27:74] == cleanText
|
||||||
@@ -942,22 +952,27 @@ def testDocAction(qtbot, nwTempGUI, nwLipsum, nwRef, nwTemp):
|
|||||||
# Block Formats
|
# Block Formats
|
||||||
assert nwGUI.docEditor.setCursorPosition(30)
|
assert nwGUI.docEditor.setCursorPosition(30)
|
||||||
assert nwGUI.passDocumentAction(nwDocAction.BLOCK_H1)
|
assert nwGUI.passDocumentAction(nwDocAction.BLOCK_H1)
|
||||||
assert nwGUI.docEditor.getText()[27:76] == "# Pellentesque nec erat ut nulla posuere commodo."
|
fmtStr = "# Pellentesque nec erat ut nulla posuere commodo."
|
||||||
|
assert nwGUI.docEditor.getText()[27:76] == fmtStr
|
||||||
qtbot.wait(stepDelay)
|
qtbot.wait(stepDelay)
|
||||||
assert nwGUI.passDocumentAction(nwDocAction.BLOCK_H2)
|
assert nwGUI.passDocumentAction(nwDocAction.BLOCK_H2)
|
||||||
assert nwGUI.docEditor.getText()[27:77] == "## Pellentesque nec erat ut nulla posuere commodo."
|
fmtStr = "## Pellentesque nec erat ut nulla posuere commodo."
|
||||||
|
assert nwGUI.docEditor.getText()[27:77] == fmtStr
|
||||||
qtbot.wait(stepDelay)
|
qtbot.wait(stepDelay)
|
||||||
assert nwGUI.passDocumentAction(nwDocAction.BLOCK_H3)
|
assert nwGUI.passDocumentAction(nwDocAction.BLOCK_H3)
|
||||||
assert nwGUI.docEditor.getText()[27:78] == "### Pellentesque nec erat ut nulla posuere commodo."
|
fmtStr = "### Pellentesque nec erat ut nulla posuere commodo."
|
||||||
|
assert nwGUI.docEditor.getText()[27:78] == fmtStr
|
||||||
qtbot.wait(stepDelay)
|
qtbot.wait(stepDelay)
|
||||||
assert nwGUI.passDocumentAction(nwDocAction.BLOCK_H4)
|
assert nwGUI.passDocumentAction(nwDocAction.BLOCK_H4)
|
||||||
assert nwGUI.docEditor.getText()[27:79] == "#### Pellentesque nec erat ut nulla posuere commodo."
|
fmtStr = "#### Pellentesque nec erat ut nulla posuere commodo."
|
||||||
|
assert nwGUI.docEditor.getText()[27:79] == fmtStr
|
||||||
qtbot.wait(stepDelay)
|
qtbot.wait(stepDelay)
|
||||||
assert nwGUI.passDocumentAction(nwDocAction.BLOCK_TXT)
|
assert nwGUI.passDocumentAction(nwDocAction.BLOCK_TXT)
|
||||||
assert nwGUI.docEditor.getText()[27:74] == cleanText
|
assert nwGUI.docEditor.getText()[27:74] == cleanText
|
||||||
qtbot.wait(stepDelay)
|
qtbot.wait(stepDelay)
|
||||||
assert nwGUI.passDocumentAction(nwDocAction.BLOCK_COM)
|
assert nwGUI.passDocumentAction(nwDocAction.BLOCK_COM)
|
||||||
assert nwGUI.docEditor.getText()[27:76] == "% Pellentesque nec erat ut nulla posuere commodo."
|
fmtStr = "% Pellentesque nec erat ut nulla posuere commodo."
|
||||||
|
assert nwGUI.docEditor.getText()[27:76] == fmtStr
|
||||||
qtbot.wait(stepDelay)
|
qtbot.wait(stepDelay)
|
||||||
assert nwGUI.passDocumentAction(nwDocAction.BLOCK_TXT)
|
assert nwGUI.passDocumentAction(nwDocAction.BLOCK_TXT)
|
||||||
assert nwGUI.docEditor.getText()[27:74] == cleanText
|
assert nwGUI.docEditor.getText()[27:74] == cleanText
|
||||||
@@ -965,7 +980,8 @@ def testDocAction(qtbot, nwTempGUI, nwLipsum, nwRef, nwTemp):
|
|||||||
|
|
||||||
# Undo/Redo
|
# Undo/Redo
|
||||||
assert nwGUI.passDocumentAction(nwDocAction.UNDO)
|
assert nwGUI.passDocumentAction(nwDocAction.UNDO)
|
||||||
assert nwGUI.docEditor.getText()[27:76] == "% Pellentesque nec erat ut nulla posuere commodo."
|
fmtStr = "% Pellentesque nec erat ut nulla posuere commodo."
|
||||||
|
assert nwGUI.docEditor.getText()[27:76] == fmtStr
|
||||||
qtbot.wait(stepDelay)
|
qtbot.wait(stepDelay)
|
||||||
assert nwGUI.passDocumentAction(nwDocAction.REDO)
|
assert nwGUI.passDocumentAction(nwDocAction.REDO)
|
||||||
assert nwGUI.docEditor.getText()[27:74] == cleanText
|
assert nwGUI.docEditor.getText()[27:74] == cleanText
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
"""novelWriter NWItem Class Tester
|
"""novelWriter NWItem Class Tester
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import nw
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
|||||||
@@ -2,11 +2,10 @@
|
|||||||
"""novelWriter Project Class Tester
|
"""novelWriter Project Class Tester
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import nw
|
|
||||||
import pytest
|
import pytest
|
||||||
from os import path
|
from os import path
|
||||||
|
|
||||||
from nwtools import *
|
from nwtools import cmpFiles
|
||||||
from nwdummy import DummyMain
|
from nwdummy import DummyMain
|
||||||
|
|
||||||
from nw.config import Config
|
from nw.config import Config
|
||||||
@@ -95,7 +94,6 @@ def testIndexScanThis(nwTempProj):
|
|||||||
assert theProject.openProject(projFile)
|
assert theProject.openProject(projFile)
|
||||||
|
|
||||||
theIndex = NWIndex(theProject, theMain)
|
theIndex = NWIndex(theProject, theMain)
|
||||||
tHandle = "31489056e0916"
|
|
||||||
|
|
||||||
isValid, theBits, thePos = theIndex.scanThis("tag: this, and this")
|
isValid, theBits, thePos = theIndex.scanThis("tag: this, and this")
|
||||||
assert not isValid
|
assert not isValid
|
||||||
@@ -176,9 +174,7 @@ def testIndexMeta(nwTempProj):
|
|||||||
|
|
||||||
theIndex = NWIndex(theProject, theMain)
|
theIndex = NWIndex(theProject, theMain)
|
||||||
nHandle = "0e17daca5f3e1"
|
nHandle = "0e17daca5f3e1"
|
||||||
nItem = theProject.projTree[nHandle]
|
|
||||||
cHandle = "02d20bbd7e394"
|
cHandle = "02d20bbd7e394"
|
||||||
cItem = theProject.projTree[cHandle]
|
|
||||||
|
|
||||||
assert theIndex.scanText(cHandle, (
|
assert theIndex.scanText(cHandle, (
|
||||||
"# Jane Smith\n"
|
"# Jane Smith\n"
|
||||||
|
|||||||
Reference in New Issue
Block a user