Switch to Path objects nearly everywhere
This commit is contained in:
@@ -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 uuid
|
||||
import pytest
|
||||
|
||||
@@ -35,12 +34,12 @@ from novelwriter.core.coretools import DocMerger, DocSplitter, ProjectBuilder
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreTools_DocMerger(monkeypatch, mockGUI, fncDir, outDir, refDir, mockRnd, ipsumText):
|
||||
def testCoreTools_DocMerger(monkeypatch, mockGUI, fncPath, tstPaths, mockRnd, ipsumText):
|
||||
"""Test the DocMerger utility.
|
||||
"""
|
||||
theProject = NWProject(mockGUI)
|
||||
mockRnd.reset()
|
||||
buildTestProject(theProject, fncDir)
|
||||
buildTestProject(theProject, fncPath)
|
||||
|
||||
# Create Files to Merge
|
||||
# =====================
|
||||
@@ -77,9 +76,9 @@ def testCoreTools_DocMerger(monkeypatch, mockGUI, fncDir, outDir, refDir, mockRn
|
||||
# Merge to New
|
||||
# ============
|
||||
|
||||
saveFile = os.path.join(fncDir, "content", "0000000000014.nwd")
|
||||
testFile = os.path.join(outDir, "coreDocTools_DocMerger_0000000000014.nwd")
|
||||
compFile = os.path.join(refDir, "coreDocTools_DocMerger_0000000000014.nwd")
|
||||
saveFile = fncPath / "content" / "0000000000014.nwd"
|
||||
testFile = tstPaths.outDir / "coreDocTools_DocMerger_0000000000014.nwd"
|
||||
compFile = tstPaths.refDir / "coreDocTools_DocMerger_0000000000014.nwd"
|
||||
|
||||
assert docMerger.newTargetDoc(hChapter1, "All of Chapter 1") == "0000000000014"
|
||||
|
||||
@@ -92,7 +91,7 @@ def testCoreTools_DocMerger(monkeypatch, mockGUI, fncDir, outDir, refDir, mockRn
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr("builtins.open", causeOSError)
|
||||
assert docMerger.writeTargetDoc() is False
|
||||
assert not os.path.isfile(saveFile)
|
||||
assert not saveFile.exists()
|
||||
assert docMerger.getError() != ""
|
||||
|
||||
# Write properly, and compare
|
||||
@@ -103,9 +102,9 @@ def testCoreTools_DocMerger(monkeypatch, mockGUI, fncDir, outDir, refDir, mockRn
|
||||
# Merge into Existing
|
||||
# ===================
|
||||
|
||||
saveFile = os.path.join(fncDir, "content", "0000000000010.nwd")
|
||||
testFile = os.path.join(outDir, "coreDocTools_DocMerger_0000000000010.nwd")
|
||||
compFile = os.path.join(refDir, "coreDocTools_DocMerger_0000000000010.nwd")
|
||||
saveFile = fncPath / "content" / "0000000000010.nwd"
|
||||
testFile = tstPaths.outDir / "coreDocTools_DocMerger_0000000000010.nwd"
|
||||
compFile = tstPaths.refDir / "coreDocTools_DocMerger_0000000000010.nwd"
|
||||
|
||||
docMerger.setTargetDoc(hChapter1)
|
||||
|
||||
@@ -124,12 +123,12 @@ def testCoreTools_DocMerger(monkeypatch, mockGUI, fncDir, outDir, refDir, mockRn
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreTools_DocSplitter(monkeypatch, mockGUI, fncDir, outDir, refDir, mockRnd, ipsumText):
|
||||
def testCoreTools_DocSplitter(monkeypatch, mockGUI, fncPath, mockRnd, ipsumText):
|
||||
"""Test the DocSplitter utility.
|
||||
"""
|
||||
theProject = NWProject(mockGUI)
|
||||
mockRnd.reset()
|
||||
buildTestProject(theProject, fncDir)
|
||||
buildTestProject(theProject, fncPath)
|
||||
|
||||
# Create File to Split
|
||||
# ====================
|
||||
@@ -264,15 +263,15 @@ def testCoreTools_DocSplitter(monkeypatch, mockGUI, fncDir, outDir, refDir, mock
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreTools_NewMinimal(monkeypatch, fncDir, outDir, refDir, mockGUI, mockRnd):
|
||||
def testCoreTools_NewMinimal(monkeypatch, fncPath, tstPaths, mockGUI, mockRnd):
|
||||
"""Create a new project from a project wizard dictionary. With
|
||||
default setting, creating a Minimal project.
|
||||
"""
|
||||
monkeypatch.setattr("uuid.uuid4", lambda *a: uuid.UUID("d0f3fe10-c6e6-4310-8bfd-181eb4224eed"))
|
||||
|
||||
projFile = os.path.join(fncDir, "nwProject.nwx")
|
||||
testFile = os.path.join(outDir, "coreTools_NewMinimal_nwProject.nwx")
|
||||
compFile = os.path.join(refDir, "coreTools_NewMinimal_nwProject.nwx")
|
||||
projFile = fncPath / "nwProject.nwx"
|
||||
testFile = tstPaths.outDir / "coreTools_NewMinimal_nwProject.nwx"
|
||||
compFile = tstPaths.refDir / "coreTools_NewMinimal_nwProject.nwx"
|
||||
|
||||
projBuild = ProjectBuilder(mockGUI)
|
||||
|
||||
@@ -283,10 +282,10 @@ def testCoreTools_NewMinimal(monkeypatch, fncDir, outDir, refDir, mockGUI, mockR
|
||||
assert projBuild.buildProject("stuff") is False
|
||||
|
||||
# Try again with a proper path
|
||||
assert projBuild.buildProject({"projPath": fncDir}) is True
|
||||
assert projBuild.buildProject({"projPath": fncPath}) is True
|
||||
|
||||
# Creating the project once more should fail
|
||||
assert projBuild.buildProject({"projPath": fncDir}) is False
|
||||
assert projBuild.buildProject({"projPath": fncPath}) is False
|
||||
|
||||
# Save and close
|
||||
copyfile(projFile, testFile)
|
||||
@@ -296,21 +295,21 @@ def testCoreTools_NewMinimal(monkeypatch, fncDir, outDir, refDir, mockGUI, mockR
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreTools_NewCustomA(monkeypatch, fncDir, outDir, refDir, mockGUI, mockRnd):
|
||||
def testCoreTools_NewCustomA(monkeypatch, fncPath, tstPaths, mockGUI, mockRnd):
|
||||
"""Create a new project from a project wizard dictionary.
|
||||
Custom type with chapters and scenes.
|
||||
"""
|
||||
monkeypatch.setattr("uuid.uuid4", lambda *a: uuid.UUID("d0f3fe10-c6e6-4310-8bfd-181eb4224eed"))
|
||||
|
||||
projFile = os.path.join(fncDir, "nwProject.nwx")
|
||||
testFile = os.path.join(outDir, "coreTools_NewCustomA_nwProject.nwx")
|
||||
compFile = os.path.join(refDir, "coreTools_NewCustomA_nwProject.nwx")
|
||||
projFile = fncPath / "nwProject.nwx"
|
||||
testFile = tstPaths.outDir / "coreTools_NewCustomA_nwProject.nwx"
|
||||
compFile = tstPaths.refDir / "coreTools_NewCustomA_nwProject.nwx"
|
||||
|
||||
projData = {
|
||||
"projName": "Test Custom",
|
||||
"projTitle": "Test Novel",
|
||||
"projAuthors": "Jane Doe\nJohn Doh\n",
|
||||
"projPath": fncDir,
|
||||
"projPath": fncPath,
|
||||
"popSample": False,
|
||||
"popMinimal": False,
|
||||
"popCustom": True,
|
||||
@@ -334,21 +333,21 @@ def testCoreTools_NewCustomA(monkeypatch, fncDir, outDir, refDir, mockGUI, mockR
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreTools_NewCustomB(monkeypatch, fncDir, outDir, refDir, mockGUI, mockRnd):
|
||||
def testCoreTools_NewCustomB(monkeypatch, fncPath, tstPaths, mockGUI, mockRnd):
|
||||
"""Create a new project from a project wizard dictionary.
|
||||
Custom type without chapters, but with scenes.
|
||||
"""
|
||||
monkeypatch.setattr("uuid.uuid4", lambda *a: uuid.UUID("d0f3fe10-c6e6-4310-8bfd-181eb4224eed"))
|
||||
|
||||
projFile = os.path.join(fncDir, "nwProject.nwx")
|
||||
testFile = os.path.join(outDir, "coreTools_NewCustomB_nwProject.nwx")
|
||||
compFile = os.path.join(refDir, "coreTools_NewCustomB_nwProject.nwx")
|
||||
projFile = fncPath / "nwProject.nwx"
|
||||
testFile = tstPaths.outDir / "coreTools_NewCustomB_nwProject.nwx"
|
||||
compFile = tstPaths.refDir / "coreTools_NewCustomB_nwProject.nwx"
|
||||
|
||||
projData = {
|
||||
"projName": "Test Custom",
|
||||
"projTitle": "Test Novel",
|
||||
"projAuthors": "Jane Doe\nJohn Doh\n",
|
||||
"projPath": fncDir,
|
||||
"projPath": fncPath,
|
||||
"popSample": False,
|
||||
"popMinimal": False,
|
||||
"popCustom": True,
|
||||
@@ -406,16 +405,15 @@ def testCoreTools_NewSample(monkeypatch, fncPath, tmpConf, tmpPath, mockGUI):
|
||||
outFile.write("foo")
|
||||
|
||||
assert projBuild.buildProject(projData) is False
|
||||
os.unlink(dstSample)
|
||||
dstSample.unlink()
|
||||
|
||||
# Create a real zip file, and unpack it
|
||||
with ZipFile(dstSample, "w") as zipObj:
|
||||
zipObj.write(os.path.join(srcSample, "nwProject.nwx"), "nwProject.nwx")
|
||||
for docFile in os.listdir(os.path.join(srcSample, "content")):
|
||||
srcDoc = os.path.join(srcSample, "content", docFile)
|
||||
zipObj.write(srcDoc, "content/"+docFile)
|
||||
zipObj.write(srcSample / "nwProject.nwx", "nwProject.nwx")
|
||||
for docFile in (srcSample / "content").iterdir():
|
||||
zipObj.write(docFile, f"content/{docFile.name}")
|
||||
|
||||
assert projBuild.buildProject(projData) is True
|
||||
os.unlink(dstSample)
|
||||
dstSample.unlink()
|
||||
|
||||
# END Test testCoreTools_NewSample
|
||||
|
||||
@@ -23,7 +23,6 @@ import json
|
||||
import pytest
|
||||
|
||||
from shutil import copyfile
|
||||
from pathlib import Path
|
||||
|
||||
from mock import causeException
|
||||
from tools import C, buildTestProject, cmpFiles, writeFile
|
||||
@@ -35,16 +34,16 @@ from novelwriter.core.project import NWProject
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreIndex_LoadSave(monkeypatch, nwLipsum, mockGUI, tstPaths):
|
||||
def testCoreIndex_LoadSave(monkeypatch, prjLipsum, mockGUI, tstPaths):
|
||||
"""Test core functionality of scaning, saving, loading and checking
|
||||
the index cache file.
|
||||
"""
|
||||
projFile = Path(nwLipsum) / "meta" / nwFiles.INDEX_FILE
|
||||
projFile = prjLipsum / "meta" / nwFiles.INDEX_FILE
|
||||
testFile = tstPaths.outDir / "coreIndex_LoadSave_tagsIndex.json"
|
||||
compFile = tstPaths.refDir / "coreIndex_LoadSave_tagsIndex.json"
|
||||
|
||||
theProject = NWProject(mockGUI)
|
||||
assert theProject.openProject(nwLipsum)
|
||||
assert theProject.openProject(prjLipsum)
|
||||
|
||||
theIndex = NWIndex(theProject)
|
||||
assert repr(theIndex) == "<NWIndex project='Lorem Ipsum'>"
|
||||
@@ -196,12 +195,12 @@ def testCoreIndex_ScanThis(mockGUI):
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreIndex_CheckThese(mockGUI, fncDir, mockRnd):
|
||||
def testCoreIndex_CheckThese(mockGUI, fncPath, mockRnd):
|
||||
"""Test the tag checker function checkThese.
|
||||
"""
|
||||
theProject = NWProject(mockGUI)
|
||||
mockRnd.reset()
|
||||
buildTestProject(theProject, fncDir)
|
||||
buildTestProject(theProject, fncPath)
|
||||
theIndex = theProject.index
|
||||
theIndex.clearIndex()
|
||||
|
||||
@@ -274,12 +273,12 @@ def testCoreIndex_CheckThese(mockGUI, fncDir, mockRnd):
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreIndex_ScanText(mockGUI, fncDir, mockRnd):
|
||||
def testCoreIndex_ScanText(mockGUI, fncPath, mockRnd):
|
||||
"""Check the index text scanner.
|
||||
"""
|
||||
theProject = NWProject(mockGUI)
|
||||
mockRnd.reset()
|
||||
buildTestProject(theProject, fncDir)
|
||||
buildTestProject(theProject, fncPath)
|
||||
theIndex = theProject.index
|
||||
|
||||
# Some items for fail to scan tests
|
||||
@@ -486,12 +485,12 @@ def testCoreIndex_ScanText(mockGUI, fncDir, mockRnd):
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreIndex_ExtractData(mockGUI, fncDir, mockRnd):
|
||||
def testCoreIndex_ExtractData(mockGUI, fncPath, mockRnd):
|
||||
"""Check the index data extraction functions.
|
||||
"""
|
||||
theProject = NWProject(mockGUI)
|
||||
mockRnd.reset()
|
||||
buildTestProject(theProject, fncDir)
|
||||
buildTestProject(theProject, fncPath)
|
||||
|
||||
theIndex = theProject.index
|
||||
theIndex.reIndexHandle(C.hNovelRoot)
|
||||
@@ -940,12 +939,12 @@ def testCoreIndex_TagsIndex():
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreIndex_ItemIndex(mockGUI, fncDir, mockRnd):
|
||||
def testCoreIndex_ItemIndex(mockGUI, fncPath, mockRnd):
|
||||
"""Check the ItemIndex class.
|
||||
"""
|
||||
theProject = NWProject(mockGUI)
|
||||
mockRnd.reset()
|
||||
buildTestProject(theProject, fncDir)
|
||||
buildTestProject(theProject, fncPath)
|
||||
theProject.index.clearIndex()
|
||||
|
||||
nHandle = C.hTitlePage
|
||||
|
||||
@@ -31,12 +31,12 @@ from novelwriter.enum import nwItemClass, nwItemType, nwItemLayout
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreItem_Setters(mockGUI, mockRnd, fncDir):
|
||||
def testCoreItem_Setters(mockGUI, mockRnd, fncPath):
|
||||
"""Test all the simple setters for the NWItem class.
|
||||
"""
|
||||
theProject = NWProject(mockGUI)
|
||||
mockRnd.reset()
|
||||
buildTestProject(theProject, fncDir)
|
||||
buildTestProject(theProject, fncPath)
|
||||
theItem = NWItem(theProject)
|
||||
|
||||
statusKeys = ["s000000", "s000001", "s000002", "s000003"]
|
||||
@@ -192,12 +192,12 @@ def testCoreItem_Setters(mockGUI, mockRnd, fncDir):
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreItem_Methods(mockGUI, mockRnd, fncDir):
|
||||
def testCoreItem_Methods(mockGUI, mockRnd, fncPath):
|
||||
"""Test the simple methods of the NWItem class.
|
||||
"""
|
||||
theProject = NWProject(mockGUI)
|
||||
mockRnd.reset()
|
||||
buildTestProject(theProject, fncDir)
|
||||
buildTestProject(theProject, fncPath)
|
||||
theItem = NWItem(theProject)
|
||||
|
||||
# Describe Me
|
||||
|
||||
@@ -180,6 +180,7 @@ def testCoreProject_Open(monkeypatch, caplog, mockGUI, fncPath, mockRnd):
|
||||
# Fail on lock file
|
||||
assert theProject._storage.writeLockFile()
|
||||
assert theProject.openProject(fncPath) is False
|
||||
assert isinstance(theProject.getLockStatus(), list)
|
||||
|
||||
# Fail to read lockfile (which still opens the project)
|
||||
with monkeypatch.context() as mp:
|
||||
@@ -193,6 +194,7 @@ def testCoreProject_Open(monkeypatch, caplog, mockGUI, fncPath, mockRnd):
|
||||
assert theProject._storage.writeLockFile()
|
||||
assert theProject.openProject(fncPath, overrideLock=True) is True
|
||||
assert theProject.closeProject()
|
||||
assert theProject.getLockStatus() is None
|
||||
|
||||
# Fail getting xml reader
|
||||
with monkeypatch.context() as mp:
|
||||
@@ -625,7 +627,7 @@ def testCoreProject_Methods(monkeypatch, mockGUI, fncPath, mockRnd):
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreProject_OrphanedFiles(mockGUI, nwLipsum):
|
||||
def testCoreProject_OrphanedFiles(mockGUI, prjLipsum):
|
||||
"""Check that files in the content folder that are not tracked in
|
||||
the project XML file are handled correctly by the orphaned files
|
||||
function. It should also restore as much meta data as possible from
|
||||
@@ -633,7 +635,7 @@ def testCoreProject_OrphanedFiles(mockGUI, nwLipsum):
|
||||
"""
|
||||
theProject = NWProject(mockGUI)
|
||||
|
||||
assert theProject.openProject(nwLipsum) is True
|
||||
assert theProject.openProject(prjLipsum) is True
|
||||
assert theProject.tree["636b6aa9b697b"] is None
|
||||
|
||||
# Add a file with non-existent parent
|
||||
@@ -646,7 +648,7 @@ def testCoreProject_OrphanedFiles(mockGUI, nwLipsum):
|
||||
assert theProject.closeProject() is True
|
||||
|
||||
# First Item with Meta Data
|
||||
orphPath = Path(nwLipsum) / "content" / "636b6aa9b697b.nwd"
|
||||
orphPath = prjLipsum / "content" / "636b6aa9b697b.nwd"
|
||||
writeFile(orphPath, (
|
||||
"%%~name:[Recovered] Mars\n"
|
||||
"%%~path:5eaea4e8cdee8/636b6aa9b697b\n"
|
||||
@@ -656,22 +658,22 @@ def testCoreProject_OrphanedFiles(mockGUI, nwLipsum):
|
||||
))
|
||||
|
||||
# Second Item without Meta Data
|
||||
orphPath = Path(nwLipsum) / "content" / "736b6aa9b697b.nwd"
|
||||
orphPath = prjLipsum / "content" / "736b6aa9b697b.nwd"
|
||||
writeFile(orphPath, "\n")
|
||||
|
||||
# Invalid File Name
|
||||
tstPath = Path(nwLipsum) / "content" / "636b6aa9b697b.txt"
|
||||
tstPath = prjLipsum / "content" / "636b6aa9b697b.txt"
|
||||
writeFile(tstPath, "\n")
|
||||
|
||||
# Invalid File Name
|
||||
tstPath = Path(nwLipsum) / "content" / "636b6aa9b697bb.nwd"
|
||||
tstPath = prjLipsum / "content" / "636b6aa9b697bb.nwd"
|
||||
writeFile(tstPath, "\n")
|
||||
|
||||
# Invalid File Name
|
||||
tstPath = Path(nwLipsum) / "content" / "abcdefghijklm.nwd"
|
||||
tstPath = prjLipsum / "content" / "abcdefghijklm.nwd"
|
||||
writeFile(tstPath, "\n")
|
||||
|
||||
assert theProject.openProject(nwLipsum)
|
||||
assert theProject.openProject(prjLipsum)
|
||||
assert theProject.storage.storagePath is not None
|
||||
assert theProject.storage.runtimePath is not None
|
||||
assert theProject.tree["636b6aa9b697bb"] is None
|
||||
@@ -697,7 +699,7 @@ def testCoreProject_OrphanedFiles(mockGUI, nwLipsum):
|
||||
assert oItem.itemType == nwItemType.FILE
|
||||
assert oItem.itemLayout == nwItemLayout.NOTE
|
||||
|
||||
assert theProject.saveProject(nwLipsum)
|
||||
assert theProject.saveProject(prjLipsum)
|
||||
assert theProject.closeProject()
|
||||
|
||||
# Finally, check that the orphaned files function returns
|
||||
@@ -730,17 +732,17 @@ def testCoreProject_Backup(monkeypatch, mockGUI, fncPath, tmpPath):
|
||||
mockGUI.hasProject = True
|
||||
|
||||
# Invalid path
|
||||
theProject.mainConf.backupPath = None
|
||||
theProject.mainConf._backupPath = None
|
||||
assert theProject.backupProject(doNotify=False) is False
|
||||
|
||||
# Missing project name
|
||||
theProject.mainConf.backupPath = str(tmpPath)
|
||||
theProject.mainConf._backupPath = tmpPath
|
||||
theProject.data.setName("")
|
||||
assert theProject.backupProject(doNotify=False) is False
|
||||
|
||||
# Valid Settings
|
||||
# ==============
|
||||
theProject.mainConf.backupPath = str(tmpPath)
|
||||
theProject.mainConf._backupPath = tmpPath
|
||||
theProject.data.setName("Test Minimal")
|
||||
|
||||
# Can't make folder
|
||||
|
||||
@@ -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 pytest
|
||||
|
||||
from tools import readFile
|
||||
@@ -441,7 +440,7 @@ def testCoreToHtml_SpecialCases(mockGUI):
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreToHtml_Complex(mockGUI, fncDir):
|
||||
def testCoreToHtml_Complex(mockGUI, fncPath):
|
||||
"""Test the save method of the ToHtml class.
|
||||
"""
|
||||
theProject = NWProject(mockGUI)
|
||||
@@ -529,7 +528,7 @@ def testCoreToHtml_Complex(mockGUI, fncDir):
|
||||
bodyText="".join(resText).rstrip()
|
||||
)
|
||||
|
||||
saveFile = os.path.join(fncDir, "outFile.htm")
|
||||
saveFile = fncPath / "outFile.htm"
|
||||
theHtml.saveHTML5(saveFile)
|
||||
assert readFile(saveFile) == htmlDoc
|
||||
|
||||
|
||||
@@ -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 pytest
|
||||
|
||||
from tools import C, buildTestProject, readFile
|
||||
@@ -132,12 +131,12 @@ def testCoreToken_Setters(mockGUI):
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreToken_TextOps(monkeypatch, mockGUI, mockRnd, fncDir):
|
||||
def testCoreToken_TextOps(monkeypatch, mockGUI, mockRnd, fncPath):
|
||||
"""Test handling files and text in the Tokenizer class.
|
||||
"""
|
||||
theProject = NWProject(mockGUI)
|
||||
mockRnd.reset()
|
||||
buildTestProject(theProject, fncDir)
|
||||
buildTestProject(theProject, fncPath)
|
||||
|
||||
theProject.data.setLanguage("en")
|
||||
theProject._loadProjectLocalisation()
|
||||
@@ -210,7 +209,7 @@ def testCoreToken_TextOps(monkeypatch, mockGUI, mockRnd, fncDir):
|
||||
assert theToken.theResult == "This is text with escapes: ** ~~ __"
|
||||
|
||||
# Save File
|
||||
savePath = os.path.join(fncDir, "dump.nwd")
|
||||
savePath = fncPath / "dump.nwd"
|
||||
theToken.saveRawMarkdown(savePath)
|
||||
assert readFile(savePath) == (
|
||||
"# Notes: Plot\n\n"
|
||||
|
||||
@@ -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 pytest
|
||||
|
||||
from tools import readFile
|
||||
@@ -208,7 +207,7 @@ def testCoreToMarkdown_ConvertDirect(mockGUI):
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreToMarkdown_Complex(mockGUI, fncDir):
|
||||
def testCoreToMarkdown_Complex(mockGUI, fncPath):
|
||||
"""Test the save method of the ToMarkdown class.
|
||||
"""
|
||||
theProject = NWProject(mockGUI)
|
||||
@@ -253,7 +252,7 @@ def testCoreToMarkdown_Complex(mockGUI, fncDir):
|
||||
# Check File
|
||||
# ==========
|
||||
|
||||
saveFile = os.path.join(fncDir, "outFile.md")
|
||||
saveFile = fncPath / "outFile.md"
|
||||
theMD.saveMarkdown(saveFile)
|
||||
assert readFile(saveFile) == "".join(resText)
|
||||
|
||||
|
||||
@@ -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 pytest
|
||||
import zipfile
|
||||
|
||||
@@ -612,7 +611,7 @@ def testCoreToOdt_ConvertDirect(mockGUI):
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreToOdt_SaveFlat(mockGUI, fncDir, outDir, refDir):
|
||||
def testCoreToOdt_SaveFlat(mockGUI, fncPath, tstPaths):
|
||||
"""Test the document save functions.
|
||||
"""
|
||||
theProject = NWProject(mockGUI)
|
||||
@@ -634,12 +633,12 @@ def testCoreToOdt_SaveFlat(mockGUI, fncDir, outDir, refDir):
|
||||
theDoc.doConvert()
|
||||
theDoc.closeDocument()
|
||||
|
||||
flatFile = os.path.join(fncDir, "document.fodt")
|
||||
testFile = os.path.join(outDir, "coreToOdt_SaveFlat_document.fodt")
|
||||
compFile = os.path.join(refDir, "coreToOdt_SaveFlat_document.fodt")
|
||||
flatFile = fncPath / "document.fodt"
|
||||
testFile = tstPaths.outDir / "coreToOdt_SaveFlat_document.fodt"
|
||||
compFile = tstPaths.refDir / "coreToOdt_SaveFlat_document.fodt"
|
||||
|
||||
theDoc.saveFlatXML(flatFile)
|
||||
assert os.path.isfile(flatFile)
|
||||
assert flatFile.exists()
|
||||
|
||||
copyfile(flatFile, testFile)
|
||||
assert cmpFiles(testFile, compFile, [4, 5])
|
||||
@@ -648,7 +647,7 @@ def testCoreToOdt_SaveFlat(mockGUI, fncDir, outDir, refDir):
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreToOdt_SaveFull(mockGUI, fncDir, outDir, refDir):
|
||||
def testCoreToOdt_SaveFull(mockGUI, fncPath, tstPaths):
|
||||
"""Test the document save functions.
|
||||
"""
|
||||
theProject = NWProject(mockGUI)
|
||||
@@ -667,25 +666,25 @@ def testCoreToOdt_SaveFull(mockGUI, fncDir, outDir, refDir):
|
||||
theDoc.doConvert()
|
||||
theDoc.closeDocument()
|
||||
|
||||
fullFile = os.path.join(fncDir, "document.odt")
|
||||
fullFile = fncPath / "document.odt"
|
||||
|
||||
theDoc.saveOpenDocText(fullFile)
|
||||
assert os.path.isfile(fullFile)
|
||||
assert fullFile.exists()
|
||||
assert zipfile.is_zipfile(fullFile)
|
||||
|
||||
maniFile = os.path.join(outDir, "coreToOdt_SaveFull_manifest.xml")
|
||||
settFile = os.path.join(outDir, "coreToOdt_SaveFull_settings.xml")
|
||||
contFile = os.path.join(outDir, "coreToOdt_SaveFull_content.xml")
|
||||
metaFile = os.path.join(outDir, "coreToOdt_SaveFull_meta.xml")
|
||||
stylFile = os.path.join(outDir, "coreToOdt_SaveFull_styles.xml")
|
||||
maniFile = tstPaths.outDir / "coreToOdt_SaveFull_manifest.xml"
|
||||
settFile = tstPaths.outDir / "coreToOdt_SaveFull_settings.xml"
|
||||
contFile = tstPaths.outDir / "coreToOdt_SaveFull_content.xml"
|
||||
metaFile = tstPaths.outDir / "coreToOdt_SaveFull_meta.xml"
|
||||
stylFile = tstPaths.outDir / "coreToOdt_SaveFull_styles.xml"
|
||||
|
||||
maniComp = os.path.join(refDir, "coreToOdt_SaveFull_manifest.xml")
|
||||
settComp = os.path.join(refDir, "coreToOdt_SaveFull_settings.xml")
|
||||
contComp = os.path.join(refDir, "coreToOdt_SaveFull_content.xml")
|
||||
metaComp = os.path.join(refDir, "coreToOdt_SaveFull_meta.xml")
|
||||
stylComp = os.path.join(refDir, "coreToOdt_SaveFull_styles.xml")
|
||||
maniComp = tstPaths.refDir / "coreToOdt_SaveFull_manifest.xml"
|
||||
settComp = tstPaths.refDir / "coreToOdt_SaveFull_settings.xml"
|
||||
contComp = tstPaths.refDir / "coreToOdt_SaveFull_content.xml"
|
||||
metaComp = tstPaths.refDir / "coreToOdt_SaveFull_meta.xml"
|
||||
stylComp = tstPaths.refDir / "coreToOdt_SaveFull_styles.xml"
|
||||
|
||||
extaxtTo = os.path.join(outDir, "coreToOdt_SaveFull")
|
||||
extaxtTo = tstPaths.outDir / "coreToOdt_SaveFull"
|
||||
|
||||
with zipfile.ZipFile(fullFile, mode="r") as theZip:
|
||||
theZip.extract("META-INF/manifest.xml", extaxtTo)
|
||||
@@ -694,17 +693,17 @@ def testCoreToOdt_SaveFull(mockGUI, fncDir, outDir, refDir):
|
||||
theZip.extract("meta.xml", extaxtTo)
|
||||
theZip.extract("styles.xml", extaxtTo)
|
||||
|
||||
maniOut = os.path.join(outDir, "coreToOdt_SaveFull", "META-INF", "manifest.xml")
|
||||
settOut = os.path.join(outDir, "coreToOdt_SaveFull", "settings.xml")
|
||||
contOut = os.path.join(outDir, "coreToOdt_SaveFull", "content.xml")
|
||||
metaOut = os.path.join(outDir, "coreToOdt_SaveFull", "meta.xml")
|
||||
stylOut = os.path.join(outDir, "coreToOdt_SaveFull", "styles.xml")
|
||||
maniOut = tstPaths.outDir / "coreToOdt_SaveFull" / "META-INF" / "manifest.xml"
|
||||
settOut = tstPaths.outDir / "coreToOdt_SaveFull" / "settings.xml"
|
||||
contOut = tstPaths.outDir / "coreToOdt_SaveFull" / "content.xml"
|
||||
metaOut = tstPaths.outDir / "coreToOdt_SaveFull" / "meta.xml"
|
||||
stylOut = tstPaths.outDir / "coreToOdt_SaveFull" / "styles.xml"
|
||||
|
||||
def prettifyXml(inFile, outFile):
|
||||
with open(outFile, mode="wb") as fileStream:
|
||||
fileStream.write(
|
||||
etree.tostring(
|
||||
etree.parse(inFile),
|
||||
etree.parse(str(inFile)),
|
||||
pretty_print=True,
|
||||
encoding="utf-8",
|
||||
xml_declaration=True
|
||||
|
||||
Reference in New Issue
Block a user