Clean up variables and formatting
This commit is contained in:
@@ -365,7 +365,7 @@ def testGuiEditor_Actions(qtbot, nwGUI, projPath, ipsumText, mockRnd):
|
||||
|
||||
text = "### A Scene\n\n%s" % "\n\n".join(ipsumText)
|
||||
nwGUI.docEditor.replaceText(text)
|
||||
theDoc = nwGUI.docEditor.document()
|
||||
doc = nwGUI.docEditor.document()
|
||||
|
||||
# Select/Cut/Copy/Paste/Undo/Redo
|
||||
# ===============================
|
||||
@@ -374,17 +374,17 @@ def testGuiEditor_Actions(qtbot, nwGUI, projPath, ipsumText, mockRnd):
|
||||
|
||||
# Select All
|
||||
assert nwGUI.docEditor.docAction(nwDocAction.SEL_ALL) is True
|
||||
theCursor = nwGUI.docEditor.textCursor()
|
||||
assert theCursor.hasSelection() is True
|
||||
assert theCursor.selectedText() == text.replace("\n", "\u2029")
|
||||
theCursor.clearSelection()
|
||||
cursor = nwGUI.docEditor.textCursor()
|
||||
assert cursor.hasSelection() is True
|
||||
assert cursor.selectedText() == text.replace("\n", "\u2029")
|
||||
cursor.clearSelection()
|
||||
|
||||
# Select Paragraph
|
||||
nwGUI.docEditor.setCursorPosition(1000)
|
||||
assert nwGUI.docEditor.getCursorPosition() == 1000
|
||||
assert nwGUI.docEditor.docAction(nwDocAction.SEL_PARA) is True
|
||||
theCursor = nwGUI.docEditor.textCursor()
|
||||
assert theCursor.selectedText() == ipsumText[1]
|
||||
cursor = nwGUI.docEditor.textCursor()
|
||||
assert cursor.selectedText() == ipsumText[1]
|
||||
|
||||
# Cut Selected Text
|
||||
nwGUI.docEditor.replaceText(text)
|
||||
@@ -411,10 +411,10 @@ def testGuiEditor_Actions(qtbot, nwGUI, projPath, ipsumText, mockRnd):
|
||||
assert nwGUI.docEditor.docAction(nwDocAction.COPY) is True
|
||||
|
||||
# Paste at End
|
||||
nwGUI.docEditor.setCursorPosition(theDoc.characterCount())
|
||||
theCursor = nwGUI.docEditor.textCursor()
|
||||
theCursor.insertBlock()
|
||||
theCursor.insertBlock()
|
||||
nwGUI.docEditor.setCursorPosition(doc.characterCount())
|
||||
cursor = nwGUI.docEditor.textCursor()
|
||||
cursor.insertBlock()
|
||||
cursor.insertBlock()
|
||||
|
||||
assert nwGUI.docEditor.docAction(nwDocAction.PASTE) is True
|
||||
newText = nwGUI.docEditor.getText()
|
||||
@@ -1017,8 +1017,8 @@ def testGuiEditor_BlockFormatting(qtbot, monkeypatch, nwGUI, projPath, ipsumText
|
||||
# Invalid and Generic
|
||||
# ===================
|
||||
|
||||
theText = "### A Scene\n\n%s" % ipsumText[0]
|
||||
nwGUI.docEditor.replaceText(theText)
|
||||
text = "### A Scene\n\n%s" % ipsumText[0]
|
||||
nwGUI.docEditor.replaceText(text)
|
||||
|
||||
# Invalid Block
|
||||
nwGUI.docEditor.setCursorPosition(0)
|
||||
@@ -1561,9 +1561,9 @@ def testGuiEditor_WordCounters(qtbot, monkeypatch, nwGUI, projPath, ipsumText, m
|
||||
SHARED.project.tree[C.hSceneDoc]._wordCount = 0 # type: ignore
|
||||
assert nwGUI.openDocument(C.hSceneDoc) is True
|
||||
|
||||
theText = "\n\n".join(ipsumText)
|
||||
cC, wC, pC = countWords(theText)
|
||||
nwGUI.docEditor.replaceText(theText)
|
||||
text = "\n\n".join(ipsumText)
|
||||
cC, wC, pC = countWords(text)
|
||||
nwGUI.docEditor.replaceText(text)
|
||||
|
||||
# Check that a busy counter is blocked
|
||||
with monkeypatch.context() as mp:
|
||||
@@ -1617,8 +1617,8 @@ def testGuiEditor_Search(qtbot, monkeypatch, nwGUI, prjLipsum):
|
||||
# Select the Word "est"
|
||||
nwGUI.docEditor.setCursorPosition(630)
|
||||
nwGUI.docEditor._makeSelection(QTextCursor.WordUnderCursor)
|
||||
theCursor = nwGUI.docEditor.textCursor()
|
||||
assert theCursor.selectedText() == "est"
|
||||
cursor = nwGUI.docEditor.textCursor()
|
||||
assert cursor.selectedText() == "est"
|
||||
|
||||
# Activate search
|
||||
nwGUI.mainMenu.aFind.activate(QAction.Trigger)
|
||||
@@ -1747,8 +1747,8 @@ def testGuiEditor_Search(qtbot, monkeypatch, nwGUI, prjLipsum):
|
||||
nwGUI.docEditor.docSearch.cancelSearch.activate(QAction.Trigger)
|
||||
nwGUI.docEditor.setCursorPosition(630)
|
||||
nwGUI.docEditor._makeSelection(QTextCursor.WordUnderCursor)
|
||||
theCursor = nwGUI.docEditor.textCursor()
|
||||
assert theCursor.selectedText() == "est"
|
||||
cursor = nwGUI.docEditor.textCursor()
|
||||
assert cursor.selectedText() == "est"
|
||||
|
||||
# Activate search again
|
||||
nwGUI.mainMenu.aFind.activate(QAction.Trigger)
|
||||
|
||||
@@ -187,8 +187,8 @@ def testGuiMenu_EditFormat(qtbot, monkeypatch, nwGUI, prjLipsum):
|
||||
# Select Paragraph/All
|
||||
nwGUI.docEditor.setCursorPosition(42)
|
||||
nwGUI.mainMenu.aSelectPar.activate(QAction.Trigger)
|
||||
theCursor = nwGUI.docEditor.textCursor()
|
||||
assert theCursor.selectedText() == (
|
||||
cursor = nwGUI.docEditor.textCursor()
|
||||
assert cursor.selectedText() == (
|
||||
"Pellentesque nec erat ut nulla posuere commodo. Curabitur nisi augue, imperdiet et porta "
|
||||
"imperdiet, efficitur id leo. Cras finibus arcu at nibh commodo congue. Proin suscipit "
|
||||
"placerat condimentum. Aenean ante enim, cursus id lorem a, blandit venenatis nibh. "
|
||||
@@ -200,8 +200,8 @@ def testGuiMenu_EditFormat(qtbot, monkeypatch, nwGUI, prjLipsum):
|
||||
|
||||
nwGUI.docEditor.setCursorPosition(42)
|
||||
nwGUI.mainMenu.aSelectAll.activate(QAction.Trigger)
|
||||
theCursor = nwGUI.docEditor.textCursor()
|
||||
assert len(theCursor.selectedText()) == 1895
|
||||
cursor = nwGUI.docEditor.textCursor()
|
||||
assert len(cursor.selectedText()) == 1895
|
||||
|
||||
# Clear the Text
|
||||
nwGUI.docEditor.clear()
|
||||
@@ -295,10 +295,10 @@ def testGuiMenu_EditFormat(qtbot, monkeypatch, nwGUI, prjLipsum):
|
||||
"Here is some text\non multiple\nlines.\n\n"
|
||||
"With another paragraph\nhere."
|
||||
))
|
||||
theCursor = nwGUI.docEditor.textCursor()
|
||||
theCursor.setPosition(74)
|
||||
theCursor.movePosition(QTextCursor.Right, QTextCursor.KeepAnchor, 29)
|
||||
nwGUI.docEditor.setTextCursor(theCursor)
|
||||
cursor = nwGUI.docEditor.textCursor()
|
||||
cursor.setPosition(74)
|
||||
cursor.movePosition(QTextCursor.Right, QTextCursor.KeepAnchor, 29)
|
||||
nwGUI.docEditor.setTextCursor(cursor)
|
||||
nwGUI.mainMenu.aFmtRmBreaks.activate(QAction.Trigger)
|
||||
assert nwGUI.docEditor.getText() == (
|
||||
"### New Text\n\n"
|
||||
@@ -348,21 +348,21 @@ def testGuiMenu_ContextMenus(qtbot, nwGUI, prjLipsum):
|
||||
assert nwGUI.openDocument("4c4f28287af27")
|
||||
|
||||
# Editor Context Menu
|
||||
theCursor = nwGUI.docEditor.textCursor()
|
||||
theCursor.setPosition(112)
|
||||
nwGUI.docEditor.setTextCursor(theCursor)
|
||||
theRect = nwGUI.docEditor.cursorRect()
|
||||
cursor = nwGUI.docEditor.textCursor()
|
||||
cursor.setPosition(112)
|
||||
nwGUI.docEditor.setTextCursor(cursor)
|
||||
rect = nwGUI.docEditor.cursorRect()
|
||||
|
||||
nwGUI.docEditor._openContextMenu(theRect.bottomRight())
|
||||
qtbot.mouseClick(nwGUI.docEditor, Qt.LeftButton, pos=theRect.topLeft())
|
||||
nwGUI.docEditor._openContextMenu(rect.bottomRight())
|
||||
qtbot.mouseClick(nwGUI.docEditor, Qt.LeftButton, pos=rect.topLeft())
|
||||
|
||||
nwGUI.docEditor._makePosSelection(QTextCursor.WordUnderCursor, theRect.center())
|
||||
theCursor = nwGUI.docEditor.textCursor()
|
||||
assert theCursor.selectedText() == "imperdiet"
|
||||
nwGUI.docEditor._makePosSelection(QTextCursor.WordUnderCursor, rect.center())
|
||||
cursor = nwGUI.docEditor.textCursor()
|
||||
assert cursor.selectedText() == "imperdiet"
|
||||
|
||||
nwGUI.docEditor._makePosSelection(QTextCursor.BlockUnderCursor, theRect.center())
|
||||
theCursor = nwGUI.docEditor.textCursor()
|
||||
assert theCursor.selectedText() == (
|
||||
nwGUI.docEditor._makePosSelection(QTextCursor.BlockUnderCursor, rect.center())
|
||||
cursor = nwGUI.docEditor.textCursor()
|
||||
assert cursor.selectedText() == (
|
||||
"Pellentesque nec erat ut nulla posuere commodo. Curabitur nisi augue, imperdiet et porta "
|
||||
"imperdiet, efficitur id leo. Cras finibus arcu at nibh commodo congue. Proin suscipit "
|
||||
"placerat condimentum. Aenean ante enim, cursus id lorem a, blandit venenatis nibh. "
|
||||
@@ -375,21 +375,21 @@ def testGuiMenu_ContextMenus(qtbot, nwGUI, prjLipsum):
|
||||
# Viewer Context Menu
|
||||
assert nwGUI.viewDocument("4c4f28287af27")
|
||||
|
||||
theCursor = nwGUI.docViewer.textCursor()
|
||||
theCursor.setPosition(112)
|
||||
nwGUI.docViewer.setTextCursor(theCursor)
|
||||
theRect = nwGUI.docViewer.cursorRect()
|
||||
cursor = nwGUI.docViewer.textCursor()
|
||||
cursor.setPosition(112)
|
||||
nwGUI.docViewer.setTextCursor(cursor)
|
||||
rect = nwGUI.docViewer.cursorRect()
|
||||
|
||||
nwGUI.docViewer._openContextMenu(theRect.bottomRight())
|
||||
qtbot.mouseClick(nwGUI.docViewer, Qt.LeftButton, pos=theRect.topLeft())
|
||||
nwGUI.docViewer._openContextMenu(rect.bottomRight())
|
||||
qtbot.mouseClick(nwGUI.docViewer, Qt.LeftButton, pos=rect.topLeft())
|
||||
|
||||
nwGUI.docViewer._makePosSelection(QTextCursor.WordUnderCursor, theRect.center())
|
||||
theCursor = nwGUI.docViewer.textCursor()
|
||||
assert theCursor.selectedText() == "imperdiet"
|
||||
nwGUI.docViewer._makePosSelection(QTextCursor.WordUnderCursor, rect.center())
|
||||
cursor = nwGUI.docViewer.textCursor()
|
||||
assert cursor.selectedText() == "imperdiet"
|
||||
|
||||
nwGUI.docEditor._makePosSelection(QTextCursor.BlockUnderCursor, theRect.center())
|
||||
theCursor = nwGUI.docEditor.textCursor()
|
||||
assert theCursor.selectedText() == (
|
||||
nwGUI.docEditor._makePosSelection(QTextCursor.BlockUnderCursor, rect.center())
|
||||
cursor = nwGUI.docEditor.textCursor()
|
||||
assert cursor.selectedText() == (
|
||||
"Pellentesque nec erat ut nulla posuere commodo. Curabitur nisi augue, imperdiet et porta "
|
||||
"imperdiet, efficitur id leo. Cras finibus arcu at nibh commodo congue. Proin suscipit "
|
||||
"placerat condimentum. Aenean ante enim, cursus id lorem a, blandit venenatis nibh. "
|
||||
@@ -629,12 +629,12 @@ def testGuiMenu_Insert(qtbot, monkeypatch, nwGUI, fncPath, projPath, mockRnd):
|
||||
assert not nwGUI.importDocument()
|
||||
|
||||
# Then a valid path, but bot a file that exists
|
||||
theFile = fncPath / "import.txt"
|
||||
monkeypatch.setattr(QFileDialog, "getOpenFileName", lambda *a, **k: (str(theFile), ""))
|
||||
iFile = fncPath / "import.txt"
|
||||
monkeypatch.setattr(QFileDialog, "getOpenFileName", lambda *a, **k: (str(iFile), ""))
|
||||
assert not nwGUI.importDocument()
|
||||
|
||||
# Create the file and try again, but with no target document open
|
||||
writeFile(theFile, "Foo")
|
||||
writeFile(iFile, "Foo")
|
||||
assert not nwGUI.importDocument()
|
||||
|
||||
# Open the document from before, and add some text to it
|
||||
|
||||
@@ -370,7 +370,7 @@ def testGuiProjTree_MoveItemToTrash(qtbot, caplog, monkeypatch, nwGUI, projPath,
|
||||
"""Test moving items to Trash."""
|
||||
monkeypatch.setattr(GuiEditLabel, "getLabel", lambda *a, text: (text, True))
|
||||
|
||||
theProject = SHARED.project
|
||||
project = SHARED.project
|
||||
projTree = nwGUI.projView.projTree
|
||||
|
||||
# Create a project
|
||||
@@ -392,7 +392,7 @@ def testGuiProjTree_MoveItemToTrash(qtbot, caplog, monkeypatch, nwGUI, projPath,
|
||||
|
||||
caplog.clear()
|
||||
assert projTree.moveItemToTrash(C.hTitlePage) is False
|
||||
assert theProject.tree.isTrash(C.hTitlePage) is False
|
||||
assert project.tree.isTrash(C.hTitlePage) is False
|
||||
assert "Could not delete item" in caplog.text
|
||||
|
||||
projTree._addTrashRoot = funcPointer
|
||||
@@ -401,11 +401,11 @@ def testGuiProjTree_MoveItemToTrash(qtbot, caplog, monkeypatch, nwGUI, projPath,
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr(QMessageBox, "result", lambda *a: QMessageBox.No)
|
||||
assert projTree.moveItemToTrash(C.hTitlePage) is False
|
||||
assert theProject.tree.isTrash(C.hTitlePage) is False
|
||||
assert project.tree.isTrash(C.hTitlePage) is False
|
||||
|
||||
# Move a document to Trash
|
||||
assert projTree.moveItemToTrash(C.hTitlePage) is True
|
||||
assert theProject.tree.isTrash(C.hTitlePage) is True
|
||||
assert project.tree.isTrash(C.hTitlePage) is True
|
||||
|
||||
# Cannot be moved again
|
||||
caplog.clear()
|
||||
@@ -422,7 +422,7 @@ def testGuiProjTree_PermanentlyDeleteItem(qtbot, caplog, monkeypatch, nwGUI, pro
|
||||
"""Test permanently deleting items."""
|
||||
monkeypatch.setattr(GuiEditLabel, "getLabel", lambda *a, text: (text, True))
|
||||
|
||||
theProject = SHARED.project
|
||||
project = SHARED.project
|
||||
projTree = nwGUI.projView.projTree
|
||||
|
||||
# Create a project
|
||||
@@ -437,31 +437,31 @@ def testGuiProjTree_PermanentlyDeleteItem(qtbot, caplog, monkeypatch, nwGUI, pro
|
||||
caplog.clear()
|
||||
assert projTree.permDeleteItem(C.hNovelRoot) is False
|
||||
assert "Root folders can only be deleted when they are empty" in caplog.text
|
||||
assert C.hNovelRoot in theProject.tree
|
||||
assert C.hNovelRoot in project.tree
|
||||
|
||||
# Deleting unused root item is allowed
|
||||
caplog.clear()
|
||||
assert projTree.permDeleteItem(C.hPlotRoot) is True
|
||||
assert C.hPlotRoot not in theProject.tree
|
||||
assert C.hPlotRoot not in project.tree
|
||||
|
||||
# User cancels action
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr(QMessageBox, "result", lambda *a: QMessageBox.No)
|
||||
assert projTree.permDeleteItem(C.hTitlePage) is False
|
||||
assert C.hTitlePage in theProject.tree
|
||||
assert C.hTitlePage in project.tree
|
||||
|
||||
# Deleting file is OK, and if it is open, it should close
|
||||
assert nwGUI.openDocument(C.hTitlePage) is True
|
||||
assert nwGUI.docEditor.docHandle == C.hTitlePage
|
||||
assert projTree.permDeleteItem(C.hTitlePage) is True
|
||||
assert C.hTitlePage not in theProject.tree
|
||||
assert C.hTitlePage not in project.tree
|
||||
assert nwGUI.docEditor.docHandle is None
|
||||
|
||||
# Deleting folder + files recursively is ok
|
||||
assert projTree.permDeleteItem(C.hChapterDir) is True
|
||||
assert C.hChapterDir not in theProject.tree
|
||||
assert C.hChapterDoc not in theProject.tree
|
||||
assert C.hSceneDoc not in theProject.tree
|
||||
assert C.hChapterDir not in project.tree
|
||||
assert C.hChapterDoc not in project.tree
|
||||
assert C.hSceneDoc not in project.tree
|
||||
|
||||
nwGUI.closeProject()
|
||||
|
||||
@@ -473,7 +473,7 @@ def testGuiProjTree_EmptyTrash(qtbot, caplog, monkeypatch, nwGUI, projPath, mock
|
||||
"""Test emptying Trash."""
|
||||
monkeypatch.setattr(GuiEditLabel, "getLabel", lambda *a, text: (text, True))
|
||||
|
||||
theProject = SHARED.project
|
||||
project = SHARED.project
|
||||
projTree = nwGUI.projView.projTree
|
||||
|
||||
# No project open
|
||||
@@ -491,26 +491,26 @@ def testGuiProjTree_EmptyTrash(qtbot, caplog, monkeypatch, nwGUI, projPath, mock
|
||||
assert projTree.moveItemToTrash(C.hTitlePage) is True
|
||||
assert projTree.moveItemToTrash(C.hChapterDir) is True
|
||||
|
||||
assert theProject.tree.isTrash(C.hTitlePage) is True
|
||||
assert theProject.tree.isTrash(C.hChapterDir) is True
|
||||
assert theProject.tree.isTrash(C.hChapterDoc) is True
|
||||
assert theProject.tree.isTrash(C.hSceneDoc) is True
|
||||
assert project.tree.isTrash(C.hTitlePage) is True
|
||||
assert project.tree.isTrash(C.hChapterDir) is True
|
||||
assert project.tree.isTrash(C.hChapterDoc) is True
|
||||
assert project.tree.isTrash(C.hSceneDoc) is True
|
||||
|
||||
# User cancels
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr(QMessageBox, "result", lambda *a: QMessageBox.No)
|
||||
assert projTree.emptyTrash() is False
|
||||
assert C.hTitlePage in theProject.tree
|
||||
assert C.hChapterDir in theProject.tree
|
||||
assert C.hChapterDoc in theProject.tree
|
||||
assert C.hSceneDoc in theProject.tree
|
||||
assert C.hTitlePage in project.tree
|
||||
assert C.hChapterDir in project.tree
|
||||
assert C.hChapterDoc in project.tree
|
||||
assert C.hSceneDoc in project.tree
|
||||
|
||||
# Run again to empty all items
|
||||
assert projTree.emptyTrash() is True
|
||||
assert C.hTitlePage not in theProject.tree
|
||||
assert C.hChapterDir not in theProject.tree
|
||||
assert C.hChapterDoc not in theProject.tree
|
||||
assert C.hSceneDoc not in theProject.tree
|
||||
assert C.hTitlePage not in project.tree
|
||||
assert C.hChapterDir not in project.tree
|
||||
assert C.hChapterDoc not in project.tree
|
||||
assert C.hSceneDoc not in project.tree
|
||||
|
||||
# Running Empty Trash again is cancelled due to empty folder
|
||||
assert projTree.emptyTrash() is False
|
||||
@@ -634,7 +634,7 @@ def testGuiProjTree_SplitDocument(qtbot, monkeypatch, nwGUI, projPath, mockRnd,
|
||||
# Create a project
|
||||
buildTestProject(nwGUI, projPath)
|
||||
|
||||
theProject = SHARED.project
|
||||
project = SHARED.project
|
||||
projTree = nwGUI.projView.projTree
|
||||
|
||||
docText = (
|
||||
@@ -652,8 +652,8 @@ def testGuiProjTree_SplitDocument(qtbot, monkeypatch, nwGUI, projPath, mockRnd,
|
||||
"#### New Section\n\nText\n\n"
|
||||
)
|
||||
|
||||
hSplitDoc = theProject.newFile("Split Doc", C.hNovelRoot)
|
||||
theProject.writeNewFile(hSplitDoc, 1, True, docText) # type: ignore
|
||||
hSplitDoc = project.newFile("Split Doc", C.hNovelRoot)
|
||||
project.writeNewFile(hSplitDoc, 1, True, docText) # type: ignore
|
||||
projTree.revealNewTreeItem(hSplitDoc, nHandle=C.hNovelRoot, wordCount=True)
|
||||
|
||||
docText = f"# Split Doc\n\n{docText}"
|
||||
@@ -700,25 +700,25 @@ def testGuiProjTree_SplitDocument(qtbot, monkeypatch, nwGUI, projPath, mockRnd,
|
||||
mp.setattr("builtins.open", causeOSError)
|
||||
assert projTree._splitDocument(hSplitDoc) is True
|
||||
for tHandle in fstSet:
|
||||
assert tHandle in theProject.tree
|
||||
assert tHandle in project.tree
|
||||
assert not (projPath / "content" / f"{tHandle}.nwd").is_file()
|
||||
|
||||
# Writing succeeds
|
||||
assert projTree._splitDocument(hSplitDoc) is True
|
||||
for tHandle in sndSet:
|
||||
assert tHandle in theProject.tree
|
||||
assert tHandle in project.tree
|
||||
assert (projPath / "content" / f"{tHandle}.nwd").is_file()
|
||||
|
||||
# Add to a folder and move source to trash
|
||||
splitData["intoFolder"] = True
|
||||
splitData["moveToTrash"] = True
|
||||
assert projTree._splitDocument(hSplitDoc) is True
|
||||
assert "0000000000029" in theProject.tree # The folder
|
||||
assert "0000000000029" in project.tree # The folder
|
||||
for tHandle in trdSet:
|
||||
assert tHandle in theProject.tree
|
||||
assert tHandle in project.tree
|
||||
assert (projPath / "content" / f"{tHandle}.nwd").is_file()
|
||||
|
||||
assert theProject.tree.isTrash(hSplitDoc) is True # type: ignore
|
||||
assert project.tree.isTrash(hSplitDoc) is True # type: ignore
|
||||
|
||||
# Cancelled by user
|
||||
with monkeypatch.context() as mp:
|
||||
|
||||
Reference in New Issue
Block a user