Switch to Path objects nearly everywhere
This commit is contained in:
@@ -20,10 +20,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
import os
|
||||
|
||||
from shutil import copyfile
|
||||
from pathlib import Path
|
||||
|
||||
from tools import cmpFiles, getGuiItem
|
||||
|
||||
@@ -34,7 +32,7 @@ from novelwriter.tools import GuiBuildNovel
|
||||
|
||||
|
||||
@pytest.mark.gui
|
||||
def testToolBuild_Main(qtbot, monkeypatch, nwGUI, nwLipsum, refDir, outDir):
|
||||
def testToolBuild_Main(qtbot, monkeypatch, nwGUI, prjLipsum, tstPaths):
|
||||
"""Test the build tool.
|
||||
"""
|
||||
# Block message box
|
||||
@@ -45,7 +43,7 @@ def testToolBuild_Main(qtbot, monkeypatch, nwGUI, nwLipsum, refDir, outDir):
|
||||
assert getGuiItem("GuiBuildNovel") is None
|
||||
|
||||
# Open a project
|
||||
assert nwGUI.openProject(nwLipsum)
|
||||
assert nwGUI.openProject(prjLipsum)
|
||||
|
||||
# Open the tool
|
||||
nwGUI.mainMenu.aBuildProject.activate(QAction.Trigger)
|
||||
@@ -69,41 +67,41 @@ def testToolBuild_Main(qtbot, monkeypatch, nwGUI, nwLipsum, refDir, outDir):
|
||||
assert not nwBuild._saveDocument(nwBuild.FMT_NWD)
|
||||
|
||||
# Default Settings
|
||||
nwGUI.mainConf._lastPath = Path(nwLipsum)
|
||||
nwGUI.mainConf._lastPath = prjLipsum
|
||||
qtbot.mouseClick(nwBuild.buildNovel, Qt.LeftButton)
|
||||
|
||||
assert nwBuild._saveDocument(nwBuild.FMT_NWD)
|
||||
projFile = os.path.join(nwLipsum, "Lorem Ipsum.nwd")
|
||||
testFile = os.path.join(outDir, "guiBuild_Tool_Step1_Lorem_Ipsum.nwd")
|
||||
compFile = os.path.join(refDir, "guiBuild_Tool_Step1_Lorem_Ipsum.nwd")
|
||||
projFile = prjLipsum / "Lorem Ipsum.nwd"
|
||||
testFile = tstPaths.outDir / "guiBuild_Tool_Step1_Lorem_Ipsum.nwd"
|
||||
compFile = tstPaths.refDir / "guiBuild_Tool_Step1_Lorem_Ipsum.nwd"
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile)
|
||||
|
||||
assert nwBuild._saveDocument(nwBuild.FMT_HTM)
|
||||
projFile = os.path.join(nwLipsum, "Lorem Ipsum.htm")
|
||||
testFile = os.path.join(outDir, "guiBuild_Tool_Step1_Lorem_Ipsum.htm")
|
||||
compFile = os.path.join(refDir, "guiBuild_Tool_Step1_Lorem_Ipsum.htm")
|
||||
projFile = prjLipsum / "Lorem Ipsum.htm"
|
||||
testFile = tstPaths.outDir / "guiBuild_Tool_Step1_Lorem_Ipsum.htm"
|
||||
compFile = tstPaths.refDir / "guiBuild_Tool_Step1_Lorem_Ipsum.htm"
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile)
|
||||
|
||||
assert nwBuild._saveDocument(nwBuild.FMT_MD)
|
||||
projFile = os.path.join(nwLipsum, "Lorem Ipsum.md")
|
||||
testFile = os.path.join(outDir, "guiBuild_Tool_Step1_Lorem_Ipsum.md")
|
||||
compFile = os.path.join(refDir, "guiBuild_Tool_Step1_Lorem_Ipsum.md")
|
||||
projFile = prjLipsum / "Lorem Ipsum.md"
|
||||
testFile = tstPaths.outDir / "guiBuild_Tool_Step1_Lorem_Ipsum.md"
|
||||
compFile = tstPaths.refDir / "guiBuild_Tool_Step1_Lorem_Ipsum.md"
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile)
|
||||
|
||||
assert nwBuild._saveDocument(nwBuild.FMT_GH)
|
||||
projFile = os.path.join(nwLipsum, "Lorem Ipsum.md")
|
||||
testFile = os.path.join(outDir, "guiBuild_Tool_Step1G_Lorem_Ipsum.md")
|
||||
compFile = os.path.join(refDir, "guiBuild_Tool_Step1G_Lorem_Ipsum.md")
|
||||
projFile = prjLipsum / "Lorem Ipsum.md"
|
||||
testFile = tstPaths.outDir / "guiBuild_Tool_Step1G_Lorem_Ipsum.md"
|
||||
compFile = tstPaths.refDir / "guiBuild_Tool_Step1G_Lorem_Ipsum.md"
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile)
|
||||
|
||||
assert nwBuild._saveDocument(nwBuild.FMT_FODT)
|
||||
projFile = os.path.join(nwLipsum, "Lorem Ipsum.fodt")
|
||||
testFile = os.path.join(outDir, "guiBuild_Tool_Step1_Lorem_Ipsum.fodt")
|
||||
compFile = os.path.join(refDir, "guiBuild_Tool_Step1_Lorem_Ipsum.fodt")
|
||||
projFile = prjLipsum / "Lorem Ipsum.fodt"
|
||||
testFile = tstPaths.outDir / "guiBuild_Tool_Step1_Lorem_Ipsum.fodt"
|
||||
compFile = tstPaths.refDir / "guiBuild_Tool_Step1_Lorem_Ipsum.fodt"
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile, [4, 5])
|
||||
|
||||
@@ -124,30 +122,30 @@ def testToolBuild_Main(qtbot, monkeypatch, nwGUI, nwLipsum, refDir, outDir):
|
||||
qtbot.mouseClick(nwBuild.buildNovel, Qt.LeftButton)
|
||||
|
||||
assert nwBuild._saveDocument(nwBuild.FMT_NWD)
|
||||
projFile = os.path.join(nwLipsum, "Lorem Ipsum.nwd")
|
||||
testFile = os.path.join(outDir, "guiBuild_Tool_Step2_Lorem_Ipsum.nwd")
|
||||
compFile = os.path.join(refDir, "guiBuild_Tool_Step2_Lorem_Ipsum.nwd")
|
||||
projFile = prjLipsum / "Lorem Ipsum.nwd"
|
||||
testFile = tstPaths.outDir / "guiBuild_Tool_Step2_Lorem_Ipsum.nwd"
|
||||
compFile = tstPaths.refDir / "guiBuild_Tool_Step2_Lorem_Ipsum.nwd"
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile)
|
||||
|
||||
assert nwBuild._saveDocument(nwBuild.FMT_HTM)
|
||||
projFile = os.path.join(nwLipsum, "Lorem Ipsum.htm")
|
||||
testFile = os.path.join(outDir, "guiBuild_Tool_Step2_Lorem_Ipsum.htm")
|
||||
compFile = os.path.join(refDir, "guiBuild_Tool_Step2_Lorem_Ipsum.htm")
|
||||
projFile = prjLipsum / "Lorem Ipsum.htm"
|
||||
testFile = tstPaths.outDir / "guiBuild_Tool_Step2_Lorem_Ipsum.htm"
|
||||
compFile = tstPaths.refDir / "guiBuild_Tool_Step2_Lorem_Ipsum.htm"
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile)
|
||||
|
||||
assert nwBuild._saveDocument(nwBuild.FMT_MD)
|
||||
projFile = os.path.join(nwLipsum, "Lorem Ipsum.md")
|
||||
testFile = os.path.join(outDir, "guiBuild_Tool_Step2_Lorem_Ipsum.md")
|
||||
compFile = os.path.join(refDir, "guiBuild_Tool_Step2_Lorem_Ipsum.md")
|
||||
projFile = prjLipsum / "Lorem Ipsum.md"
|
||||
testFile = tstPaths.outDir / "guiBuild_Tool_Step2_Lorem_Ipsum.md"
|
||||
compFile = tstPaths.refDir / "guiBuild_Tool_Step2_Lorem_Ipsum.md"
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile)
|
||||
|
||||
assert nwBuild._saveDocument(nwBuild.FMT_FODT)
|
||||
projFile = os.path.join(nwLipsum, "Lorem Ipsum.fodt")
|
||||
testFile = os.path.join(outDir, "guiBuild_Tool_Step2_Lorem_Ipsum.fodt")
|
||||
compFile = os.path.join(refDir, "guiBuild_Tool_Step2_Lorem_Ipsum.fodt")
|
||||
projFile = prjLipsum / "Lorem Ipsum.fodt"
|
||||
testFile = tstPaths.outDir / "guiBuild_Tool_Step2_Lorem_Ipsum.fodt"
|
||||
compFile = tstPaths.refDir / "guiBuild_Tool_Step2_Lorem_Ipsum.fodt"
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile, [4, 5])
|
||||
|
||||
@@ -158,30 +156,30 @@ def testToolBuild_Main(qtbot, monkeypatch, nwGUI, nwLipsum, refDir, outDir):
|
||||
|
||||
# Save files that can be compared
|
||||
assert nwBuild._saveDocument(nwBuild.FMT_NWD)
|
||||
projFile = os.path.join(nwLipsum, "Lorem Ipsum.nwd")
|
||||
testFile = os.path.join(outDir, "guiBuild_Tool_Step3_Lorem_Ipsum.nwd")
|
||||
compFile = os.path.join(refDir, "guiBuild_Tool_Step3_Lorem_Ipsum.nwd")
|
||||
projFile = prjLipsum / "Lorem Ipsum.nwd"
|
||||
testFile = tstPaths.outDir / "guiBuild_Tool_Step3_Lorem_Ipsum.nwd"
|
||||
compFile = tstPaths.refDir / "guiBuild_Tool_Step3_Lorem_Ipsum.nwd"
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile)
|
||||
|
||||
assert nwBuild._saveDocument(nwBuild.FMT_HTM)
|
||||
projFile = os.path.join(nwLipsum, "Lorem Ipsum.htm")
|
||||
testFile = os.path.join(outDir, "guiBuild_Tool_Step3_Lorem_Ipsum.htm")
|
||||
compFile = os.path.join(refDir, "guiBuild_Tool_Step3_Lorem_Ipsum.htm")
|
||||
projFile = prjLipsum / "Lorem Ipsum.htm"
|
||||
testFile = tstPaths.outDir / "guiBuild_Tool_Step3_Lorem_Ipsum.htm"
|
||||
compFile = tstPaths.refDir / "guiBuild_Tool_Step3_Lorem_Ipsum.htm"
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile)
|
||||
|
||||
assert nwBuild._saveDocument(nwBuild.FMT_MD)
|
||||
projFile = os.path.join(nwLipsum, "Lorem Ipsum.md")
|
||||
testFile = os.path.join(outDir, "guiBuild_Tool_Step3_Lorem_Ipsum.md")
|
||||
compFile = os.path.join(refDir, "guiBuild_Tool_Step3_Lorem_Ipsum.md")
|
||||
projFile = prjLipsum / "Lorem Ipsum.md"
|
||||
testFile = tstPaths.outDir / "guiBuild_Tool_Step3_Lorem_Ipsum.md"
|
||||
compFile = tstPaths.refDir / "guiBuild_Tool_Step3_Lorem_Ipsum.md"
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile)
|
||||
|
||||
assert nwBuild._saveDocument(nwBuild.FMT_FODT)
|
||||
projFile = os.path.join(nwLipsum, "Lorem Ipsum.fodt")
|
||||
testFile = os.path.join(outDir, "guiBuild_Tool_Step3_Lorem_Ipsum.fodt")
|
||||
compFile = os.path.join(refDir, "guiBuild_Tool_Step3_Lorem_Ipsum.fodt")
|
||||
projFile = prjLipsum / "Lorem Ipsum.fodt"
|
||||
testFile = tstPaths.outDir / "guiBuild_Tool_Step3_Lorem_Ipsum.fodt"
|
||||
compFile = tstPaths.refDir / "guiBuild_Tool_Step3_Lorem_Ipsum.fodt"
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile, [4, 5])
|
||||
|
||||
@@ -199,43 +197,43 @@ def testToolBuild_Main(qtbot, monkeypatch, nwGUI, nwLipsum, refDir, outDir):
|
||||
|
||||
# Save files that can be compared
|
||||
assert nwBuild._saveDocument(nwBuild.FMT_NWD)
|
||||
projFile = os.path.join(nwLipsum, "Lorem Ipsum.nwd")
|
||||
testFile = os.path.join(outDir, "guiBuild_Tool_Step4_Lorem_Ipsum.nwd")
|
||||
compFile = os.path.join(refDir, "guiBuild_Tool_Step4_Lorem_Ipsum.nwd")
|
||||
projFile = prjLipsum / "Lorem Ipsum.nwd"
|
||||
testFile = tstPaths.outDir / "guiBuild_Tool_Step4_Lorem_Ipsum.nwd"
|
||||
compFile = tstPaths.refDir / "guiBuild_Tool_Step4_Lorem_Ipsum.nwd"
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile)
|
||||
|
||||
assert nwBuild._saveDocument(nwBuild.FMT_HTM)
|
||||
projFile = os.path.join(nwLipsum, "Lorem Ipsum.htm")
|
||||
testFile = os.path.join(outDir, "guiBuild_Tool_Step4_Lorem_Ipsum.htm")
|
||||
compFile = os.path.join(refDir, "guiBuild_Tool_Step4_Lorem_Ipsum.htm")
|
||||
projFile = prjLipsum / "Lorem Ipsum.htm"
|
||||
testFile = tstPaths.outDir / "guiBuild_Tool_Step4_Lorem_Ipsum.htm"
|
||||
compFile = tstPaths.refDir / "guiBuild_Tool_Step4_Lorem_Ipsum.htm"
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile)
|
||||
|
||||
# Check the JSON files too at this stage
|
||||
assert nwBuild._saveDocument(nwBuild.FMT_JSON_H)
|
||||
projFile = os.path.join(nwLipsum, "Lorem Ipsum.json")
|
||||
testFile = os.path.join(outDir, "guiBuild_Tool_Step4H_Lorem_Ipsum.json")
|
||||
compFile = os.path.join(refDir, "guiBuild_Tool_Step4H_Lorem_Ipsum.json")
|
||||
projFile = prjLipsum / "Lorem Ipsum.json"
|
||||
testFile = tstPaths.outDir / "guiBuild_Tool_Step4H_Lorem_Ipsum.json"
|
||||
compFile = tstPaths.refDir / "guiBuild_Tool_Step4H_Lorem_Ipsum.json"
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile, [8])
|
||||
|
||||
assert nwBuild._saveDocument(nwBuild.FMT_JSON_M)
|
||||
projFile = os.path.join(nwLipsum, "Lorem Ipsum.json")
|
||||
testFile = os.path.join(outDir, "guiBuild_Tool_Step4M_Lorem_Ipsum.json")
|
||||
compFile = os.path.join(refDir, "guiBuild_Tool_Step4M_Lorem_Ipsum.json")
|
||||
projFile = prjLipsum / "Lorem Ipsum.json"
|
||||
testFile = tstPaths.outDir / "guiBuild_Tool_Step4M_Lorem_Ipsum.json"
|
||||
compFile = tstPaths.refDir / "guiBuild_Tool_Step4M_Lorem_Ipsum.json"
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile, [8])
|
||||
|
||||
# Since odt and fodt is built by the same code, we don't check the
|
||||
# output. but just that the different format can be written as well
|
||||
assert nwBuild._saveDocument(nwBuild.FMT_ODT)
|
||||
assert os.path.isfile(os.path.join(nwLipsum, "Lorem Ipsum.odt"))
|
||||
assert (prjLipsum / "Lorem Ipsum.odt").is_file()
|
||||
|
||||
# Print to PDF
|
||||
if not nwGUI.mainConf.osDarwin:
|
||||
assert nwBuild._saveDocument(nwBuild.FMT_PDF)
|
||||
assert os.path.isfile(os.path.join(nwLipsum, "Lorem Ipsum.pdf"))
|
||||
assert (prjLipsum / "Lorem Ipsum.pdf").is_file()
|
||||
|
||||
# Close the build tool
|
||||
htmlText = nwBuild.htmlText
|
||||
|
||||
@@ -29,7 +29,7 @@ from novelwriter.tools import GuiLipsum
|
||||
|
||||
|
||||
@pytest.mark.gui
|
||||
def testToolLipsum_Main(qtbot, nwGUI, fncProj, mockRnd):
|
||||
def testToolLipsum_Main(qtbot, nwGUI, projPath, mockRnd):
|
||||
"""Test the Lorem Ipsum tool.
|
||||
"""
|
||||
# Check that we cannot open when there is no project
|
||||
@@ -37,7 +37,7 @@ def testToolLipsum_Main(qtbot, nwGUI, fncProj, mockRnd):
|
||||
assert getGuiItem("GuiLipsum") is None
|
||||
|
||||
# Create a new project
|
||||
buildTestProject(nwGUI, fncProj)
|
||||
buildTestProject(nwGUI, projPath)
|
||||
assert nwGUI.openDocument(C.hSceneDoc) is True
|
||||
assert len(nwGUI.docEditor.getText()) == 15
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import pytest
|
||||
|
||||
@@ -37,7 +36,7 @@ from novelwriter.tools.projwizard import (
|
||||
|
||||
@pytest.mark.gui
|
||||
@pytest.mark.skipif(sys.platform.startswith("darwin"), reason="Not running on Darwin")
|
||||
def testToolProjectWizard_Handling(qtbot, monkeypatch, nwGUI, fncProj):
|
||||
def testToolProjectWizard_Handling(qtbot, monkeypatch, nwGUI, projPath):
|
||||
"""Test the launch of the project wizard.
|
||||
Disabled for macOS because the test segfaults on QWizard.show()
|
||||
"""
|
||||
@@ -45,7 +44,7 @@ def testToolProjectWizard_Handling(qtbot, monkeypatch, nwGUI, fncProj):
|
||||
# ========================
|
||||
|
||||
# New with a project open should cause an error
|
||||
buildTestProject(nwGUI, fncProj)
|
||||
buildTestProject(nwGUI, projPath)
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr(nwGUI, "closeProject", lambda *a: False)
|
||||
assert nwGUI.newProject() is False
|
||||
@@ -61,7 +60,7 @@ def testToolProjectWizard_Handling(qtbot, monkeypatch, nwGUI, fncProj):
|
||||
assert nwGUI.newProject() is False
|
||||
|
||||
# Now, with a non-empty folder
|
||||
mp.setattr(nwGUI, "showNewProjectDialog", lambda *a: {"projPath": fncProj})
|
||||
mp.setattr(nwGUI, "showNewProjectDialog", lambda *a: {"projPath": projPath})
|
||||
assert nwGUI.newProject() is False
|
||||
|
||||
# Test the Wizard Launching
|
||||
@@ -96,7 +95,7 @@ def testToolProjectWizard_Handling(qtbot, monkeypatch, nwGUI, fncProj):
|
||||
@pytest.mark.gui
|
||||
@pytest.mark.parametrize("prjType", ["minimal", "custom1", "custom2", "sample"])
|
||||
@pytest.mark.skipif(sys.platform.startswith("darwin"), reason="Not running on Darwin")
|
||||
def testToolProjectWizard_Run(qtbot, monkeypatch, nwGUI, fncDir, prjType):
|
||||
def testToolProjectWizard_Run(qtbot, monkeypatch, nwGUI, fncPath, prjType):
|
||||
"""Test the new project wizard with a set of selection scenarios.
|
||||
"""
|
||||
monkeypatch.setattr(GuiProjectWizard, "exec_", lambda *a: None)
|
||||
@@ -130,12 +129,12 @@ def testToolProjectWizard_Run(qtbot, monkeypatch, nwGUI, fncDir, prjType):
|
||||
assert storagePage.errLabel.text() == ""
|
||||
|
||||
# Set an invalid path
|
||||
storagePage.projPath.setText(os.path.join(fncDir, "not", "a", "path"))
|
||||
storagePage.projPath.setText(str(fncPath / "not" / "a" / "path"))
|
||||
assert not nwWiz.button(QWizard.NextButton).isEnabled()
|
||||
assert storagePage.errLabel.text().startswith("Error")
|
||||
|
||||
# Set an existing path
|
||||
storagePage.projPath.setText(fncDir)
|
||||
storagePage.projPath.setText(str(fncPath))
|
||||
assert not nwWiz.button(QWizard.NextButton).isEnabled()
|
||||
assert storagePage.errLabel.text().startswith("Error")
|
||||
|
||||
@@ -146,12 +145,12 @@ def testToolProjectWizard_Run(qtbot, monkeypatch, nwGUI, fncDir, prjType):
|
||||
assert storagePage.errLabel.text() == ""
|
||||
|
||||
# Let the browse feature handle it
|
||||
projPath = os.path.join(fncDir, "Test Wizard")
|
||||
projPath = fncPath / "Test Wizard"
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr(QFileDialog, "getExistingDirectory", lambda *a, **k: fncDir)
|
||||
mp.setattr(QFileDialog, "getExistingDirectory", lambda *a, **k: str(fncPath))
|
||||
qtbot.mouseClick(storagePage.browseButton, Qt.LeftButton, delay=100)
|
||||
|
||||
assert storagePage.projPath.text() == projPath
|
||||
assert storagePage.projPath.text() == str(projPath)
|
||||
assert storagePage.errLabel.text() == ""
|
||||
|
||||
# Setting projPath should activate the button
|
||||
@@ -216,7 +215,7 @@ def testToolProjectWizard_Run(qtbot, monkeypatch, nwGUI, fncDir, prjType):
|
||||
assert projData["projName"] == "Test Wizard"
|
||||
assert projData["projTitle"] == "My Novel"
|
||||
assert projData["projAuthors"] == "Jane Doe"
|
||||
assert projData["projPath"] == projPath
|
||||
assert projData["projPath"] == str(projPath)
|
||||
assert projData["popMinimal"] == prjType.startswith("minimal")
|
||||
assert projData["popCustom"] == prjType.startswith("custom")
|
||||
assert projData["popSample"] == prjType.startswith("sample")
|
||||
|
||||
@@ -19,9 +19,8 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
import json
|
||||
import os
|
||||
import pytest
|
||||
|
||||
from mock import causeOSError
|
||||
from tools import getGuiItem, writeFile, buildTestProject
|
||||
@@ -34,14 +33,14 @@ from novelwriter.constants import nwFiles
|
||||
|
||||
|
||||
@pytest.mark.gui
|
||||
def testToolWritingStats_Main(qtbot, monkeypatch, nwGUI, fncDir, fncProj):
|
||||
def testToolWritingStats_Main(qtbot, monkeypatch, nwGUI, fncPath, projPath):
|
||||
"""Test the full writing stats tool.
|
||||
"""
|
||||
# Create a project to work on
|
||||
buildTestProject(nwGUI, fncProj)
|
||||
buildTestProject(nwGUI, projPath)
|
||||
qtbot.wait(100)
|
||||
assert nwGUI.saveProject()
|
||||
sessFile = os.path.join(fncProj, "meta", nwFiles.SESS_STATS)
|
||||
sessFile = projPath / "meta" / nwFiles.SESS_STATS
|
||||
|
||||
# Open the Writing Stats dialog
|
||||
nwGUI.mainMenu.aWritingStats.activate(QAction.Trigger)
|
||||
@@ -54,7 +53,7 @@ def testToolWritingStats_Main(qtbot, monkeypatch, nwGUI, fncDir, fncProj):
|
||||
# ============
|
||||
|
||||
# No initial logfile
|
||||
assert not os.path.isfile(sessFile)
|
||||
assert not sessFile.is_file()
|
||||
assert not sessLog._loadLogFile()
|
||||
|
||||
# Make a test log file
|
||||
@@ -66,7 +65,7 @@ def testToolWritingStats_Main(qtbot, monkeypatch, nwGUI, fncDir, fncProj):
|
||||
"2020-01-03 21:30:00 2020-01-03 21:30:15 125 5\n"
|
||||
"2020-01-06 21:00:00 2020-01-06 21:00:10 125 5\n"
|
||||
))
|
||||
assert os.path.isfile(sessFile)
|
||||
assert sessFile.is_file()
|
||||
assert sessLog._loadLogFile()
|
||||
assert sessLog.wordOffset == 123
|
||||
assert len(sessLog.logData) == 4
|
||||
@@ -110,9 +109,7 @@ def testToolWritingStats_Main(qtbot, monkeypatch, nwGUI, fncDir, fncProj):
|
||||
assert not sessLog._saveData(None)
|
||||
|
||||
# Make the save succeed
|
||||
monkeypatch.setattr("os.path.expanduser", lambda *a: fncDir)
|
||||
monkeypatch.setattr(QFileDialog, "getSaveFileName", lambda ss, tt, pp, options: (pp, ""))
|
||||
|
||||
sessLog.listBox.sortByColumn(sessLog.C_TIME, 0)
|
||||
|
||||
assert sessLog.novelWords.text() == "{:n}".format(600)
|
||||
@@ -135,7 +132,7 @@ def testToolWritingStats_Main(qtbot, monkeypatch, nwGUI, fncDir, fncProj):
|
||||
qtbot.wait(100)
|
||||
|
||||
# Check the exported files
|
||||
jsonStats = os.path.join(fncDir, "sessionStats.json")
|
||||
jsonStats = fncPath / "sessionStats.json"
|
||||
with open(jsonStats, mode="r", encoding="utf-8") as inFile:
|
||||
jsonData = json.load(inFile)
|
||||
|
||||
@@ -174,7 +171,7 @@ def testToolWritingStats_Main(qtbot, monkeypatch, nwGUI, fncDir, fncProj):
|
||||
qtbot.mouseClick(sessLog.incNovel, Qt.LeftButton)
|
||||
assert sessLog._saveData(sessLog.FMT_JSON)
|
||||
|
||||
jsonStats = os.path.join(fncDir, "sessionStats.json")
|
||||
jsonStats = fncPath / "sessionStats.json"
|
||||
with open(jsonStats, mode="r", encoding="utf-8") as inFile:
|
||||
jsonData = json.loads(inFile.read())
|
||||
|
||||
@@ -220,7 +217,7 @@ def testToolWritingStats_Main(qtbot, monkeypatch, nwGUI, fncDir, fncProj):
|
||||
qtbot.mouseClick(sessLog.incNotes, Qt.LeftButton)
|
||||
assert sessLog._saveData(sessLog.FMT_JSON)
|
||||
|
||||
jsonStats = os.path.join(fncDir, "sessionStats.json")
|
||||
jsonStats = fncPath / "sessionStats.json"
|
||||
with open(jsonStats, mode="r", encoding="utf-8") as inFile:
|
||||
jsonData = json.load(inFile)
|
||||
|
||||
@@ -268,7 +265,7 @@ def testToolWritingStats_Main(qtbot, monkeypatch, nwGUI, fncDir, fncProj):
|
||||
|
||||
# qtbot.stop()
|
||||
|
||||
jsonStats = os.path.join(fncDir, "sessionStats.json")
|
||||
jsonStats = fncPath / "sessionStats.json"
|
||||
with open(jsonStats, mode="r", encoding="utf-8") as inFile:
|
||||
jsonData = json.load(inFile)
|
||||
|
||||
@@ -298,7 +295,7 @@ def testToolWritingStats_Main(qtbot, monkeypatch, nwGUI, fncDir, fncProj):
|
||||
qtbot.mouseClick(sessLog.hideZeros, Qt.LeftButton)
|
||||
assert sessLog._saveData(sessLog.FMT_JSON)
|
||||
|
||||
jsonStats = os.path.join(fncDir, "sessionStats.json")
|
||||
jsonStats = fncPath / "sessionStats.json"
|
||||
with open(jsonStats, mode="r", encoding="utf-8") as inFile:
|
||||
jsonData = json.load(inFile)
|
||||
|
||||
@@ -351,7 +348,7 @@ def testToolWritingStats_Main(qtbot, monkeypatch, nwGUI, fncDir, fncProj):
|
||||
qtbot.mouseClick(sessLog.groupByDay, Qt.LeftButton)
|
||||
assert sessLog._saveData(sessLog.FMT_JSON)
|
||||
|
||||
jsonStats = os.path.join(fncDir, "sessionStats.json")
|
||||
jsonStats = fncPath / "sessionStats.json"
|
||||
with open(jsonStats, mode="r", encoding="utf-8") as inFile:
|
||||
jsonData = json.load(inFile)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user