Completed coverage of setProjectPath and made all os imports explicit
This commit is contained in:
+31
-31
@@ -5,11 +5,11 @@
|
||||
import nw
|
||||
import pytest
|
||||
import logging
|
||||
import os
|
||||
|
||||
from shutil import copyfile
|
||||
from nwtools import cmpFiles
|
||||
|
||||
from os import path
|
||||
from PyQt5.QtCore import Qt, QUrl, QPoint, QItemSelectionModel
|
||||
from PyQt5.QtGui import QTextCursor, QColor, QPixmap, QIcon
|
||||
from PyQt5.QtWidgets import (
|
||||
@@ -57,19 +57,19 @@ def testLaunch(qtbot, nwFuncTemp, nwTemp):
|
||||
nwGUI.close()
|
||||
|
||||
# Log file
|
||||
logFile = path.join(nwTemp, "logFile.log")
|
||||
bakFile = path.join(nwTemp, "logFile.log.bak")
|
||||
logFile = os.path.join(nwTemp, "logFile.log")
|
||||
bakFile = os.path.join(nwTemp, "logFile.log.bak")
|
||||
|
||||
nwGUI = nw.main(
|
||||
["--testmode", "--logfile=%s" % logFile, "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp]
|
||||
)
|
||||
assert path.isfile(logFile)
|
||||
assert os.path.isfile(logFile)
|
||||
|
||||
nwGUI = nw.main(
|
||||
["--testmode", "--logfile=%s" % logFile, "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp]
|
||||
)
|
||||
assert path.isfile(bakFile)
|
||||
assert path.isfile(logFile)
|
||||
assert os.path.isfile(bakFile)
|
||||
assert os.path.isfile(logFile)
|
||||
nwGUI.closeMain()
|
||||
nwGUI.close()
|
||||
|
||||
@@ -116,9 +116,9 @@ def testDocEditor(qtbot, yesToAll, nwFuncTemp, nwTempGUI, nwRef, nwTemp):
|
||||
assert not nwGUI.theProject.spellCheck
|
||||
|
||||
# Check the files
|
||||
projFile = path.join(nwFuncTemp, "nwProject.nwx")
|
||||
testFile = path.join(nwTempGUI, "0_nwProject.nwx")
|
||||
refFile = path.join(nwRef, "gui", "0_nwProject.nwx")
|
||||
projFile = os.path.join(nwFuncTemp, "nwProject.nwx")
|
||||
testFile = os.path.join(nwTempGUI, "0_nwProject.nwx")
|
||||
refFile = os.path.join(nwRef, "gui", "0_nwProject.nwx")
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, refFile, [2, 6, 7, 8])
|
||||
qtbot.wait(stepDelay)
|
||||
@@ -135,7 +135,7 @@ def testDocEditor(qtbot, yesToAll, nwFuncTemp, nwTempGUI, nwRef, nwTemp):
|
||||
assert len(nwGUI.theProject.projTree._treeRoots) == 4
|
||||
assert nwGUI.theProject.projTree.trashRoot() is None
|
||||
assert nwGUI.theProject.projPath == nwFuncTemp
|
||||
assert nwGUI.theProject.projMeta == path.join(nwFuncTemp, "meta")
|
||||
assert nwGUI.theProject.projMeta == os.path.join(nwFuncTemp, "meta")
|
||||
assert nwGUI.theProject.projFile == "nwProject.nwx"
|
||||
assert nwGUI.theProject.projName == "New Project"
|
||||
assert nwGUI.theProject.bookTitle == ""
|
||||
@@ -358,33 +358,33 @@ def testDocEditor(qtbot, yesToAll, nwFuncTemp, nwTempGUI, nwRef, nwTemp):
|
||||
assert nwGUI.saveProject()
|
||||
|
||||
# Check the files
|
||||
projFile = path.join(nwFuncTemp, "nwProject.nwx")
|
||||
testFile = path.join(nwTempGUI, "1_nwProject.nwx")
|
||||
refFile = path.join(nwRef, "gui", "1_nwProject.nwx")
|
||||
projFile = os.path.join(nwFuncTemp, "nwProject.nwx")
|
||||
testFile = os.path.join(nwTempGUI, "1_nwProject.nwx")
|
||||
refFile = os.path.join(nwRef, "gui", "1_nwProject.nwx")
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, refFile, [2, 6, 7, 8])
|
||||
|
||||
projFile = path.join(nwFuncTemp, "content", "031b4af5197ec.nwd")
|
||||
testFile = path.join(nwTempGUI, "1_031b4af5197ec.nwd")
|
||||
refFile = path.join(nwRef, "gui", "1_031b4af5197ec.nwd")
|
||||
projFile = os.path.join(nwFuncTemp, "content", "031b4af5197ec.nwd")
|
||||
testFile = os.path.join(nwTempGUI, "1_031b4af5197ec.nwd")
|
||||
refFile = os.path.join(nwRef, "gui", "1_031b4af5197ec.nwd")
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, refFile)
|
||||
|
||||
projFile = path.join(nwFuncTemp, "content", "1a6562590ef19.nwd")
|
||||
testFile = path.join(nwTempGUI, "1_1a6562590ef19.nwd")
|
||||
refFile = path.join(nwRef, "gui", "1_1a6562590ef19.nwd")
|
||||
projFile = os.path.join(nwFuncTemp, "content", "1a6562590ef19.nwd")
|
||||
testFile = os.path.join(nwTempGUI, "1_1a6562590ef19.nwd")
|
||||
refFile = os.path.join(nwRef, "gui", "1_1a6562590ef19.nwd")
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, refFile)
|
||||
|
||||
projFile = path.join(nwFuncTemp, "content", "0e17daca5f3e1.nwd")
|
||||
testFile = path.join(nwTempGUI, "1_0e17daca5f3e1.nwd")
|
||||
refFile = path.join(nwRef, "gui", "1_0e17daca5f3e1.nwd")
|
||||
projFile = os.path.join(nwFuncTemp, "content", "0e17daca5f3e1.nwd")
|
||||
testFile = os.path.join(nwTempGUI, "1_0e17daca5f3e1.nwd")
|
||||
refFile = os.path.join(nwRef, "gui", "1_0e17daca5f3e1.nwd")
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, refFile)
|
||||
|
||||
projFile = path.join(nwFuncTemp, "content", "41cfc0d1f2d12.nwd")
|
||||
testFile = path.join(nwTempGUI, "1_41cfc0d1f2d12.nwd")
|
||||
refFile = path.join(nwRef, "gui", "1_41cfc0d1f2d12.nwd")
|
||||
projFile = os.path.join(nwFuncTemp, "content", "41cfc0d1f2d12.nwd")
|
||||
testFile = os.path.join(nwTempGUI, "1_41cfc0d1f2d12.nwd")
|
||||
refFile = os.path.join(nwRef, "gui", "1_41cfc0d1f2d12.nwd")
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, refFile)
|
||||
|
||||
@@ -625,7 +625,7 @@ def testProjectTree(qtbot, yesToAll, nwMinimal, nwTemp):
|
||||
nwGUI.openDocument("73475cb40a568")
|
||||
nwGUI.docEditor.setText("# Hello World\n")
|
||||
nwGUI.saveDocument()
|
||||
assert path.isfile(path.join(nwMinimal, "content", "73475cb40a568.nwd"))
|
||||
assert os.path.isfile(os.path.join(nwMinimal, "content", "73475cb40a568.nwd"))
|
||||
|
||||
# Delete the items we added earlier
|
||||
nwTree.clearSelection()
|
||||
@@ -640,17 +640,17 @@ def testProjectTree(qtbot, yesToAll, nwMinimal, nwTemp):
|
||||
assert "71ee45a3c0db9" not in nwGUI.theProject.projTree._treeOrder
|
||||
|
||||
# The file is in trash, empty it
|
||||
assert path.isfile(path.join(nwMinimal, "content", "73475cb40a568.nwd"))
|
||||
assert os.path.isfile(os.path.join(nwMinimal, "content", "73475cb40a568.nwd"))
|
||||
assert nwTree.emptyTrash()
|
||||
assert not nwTree.emptyTrash() # Already empty
|
||||
assert not path.isfile(path.join(nwMinimal, "content", "73475cb40a568.nwd"))
|
||||
assert not os.path.isfile(os.path.join(nwMinimal, "content", "73475cb40a568.nwd"))
|
||||
assert "73475cb40a568" not in nwGUI.theProject.projTree._treeOrder
|
||||
|
||||
# Close the project
|
||||
nwGUI.closeProject()
|
||||
|
||||
# Add an orphaned file
|
||||
orphFile = path.join(nwMinimal, "content", "1234567890abc.nwd")
|
||||
orphFile = os.path.join(nwMinimal, "content", "1234567890abc.nwd")
|
||||
with open(orphFile, mode="w+", encoding="utf8") as outFile:
|
||||
outFile.write("# Hello World\n")
|
||||
|
||||
@@ -1102,7 +1102,7 @@ def testInsertMenu(qtbot, monkeypatch, nwFuncTemp, nwTemp):
|
||||
assert not nwGUI.importDocument()
|
||||
|
||||
# Then a valid path, but bot a file that exists
|
||||
theFile = path.join(nwTemp, "import.txt")
|
||||
theFile = os.path.join(nwTemp, "import.txt")
|
||||
monkeypatch.setattr(QFileDialog, "getOpenFileName", lambda *args, **kwards: [theFile])
|
||||
assert not nwGUI.importDocument()
|
||||
|
||||
@@ -1145,7 +1145,7 @@ def testInsertMenu(qtbot, monkeypatch, nwFuncTemp, nwTemp):
|
||||
assert len(theBits) == 3
|
||||
assert theBits[0] == "File details for the currently open file"
|
||||
assert theBits[1] == "Handle: 0e17daca5f3e1"
|
||||
assert theBits[2] == "Location: %s" % path.join(nwFuncTemp, "content", "0e17daca5f3e1.nwd")
|
||||
assert theBits[2] == "Location: %s" % os.path.join(nwFuncTemp, "content", "0e17daca5f3e1.nwd")
|
||||
|
||||
# qtbot.stopForInteraction()
|
||||
nwGUI.closeMain()
|
||||
|
||||
Reference in New Issue
Block a user