Move zipping of project to storage class
This commit is contained in:
@@ -29,6 +29,7 @@ from mock import causeException
|
||||
from tools import C, buildTestProject, cmpFiles, writeFile
|
||||
|
||||
from novelwriter.enum import nwItemClass, nwItemLayout
|
||||
from novelwriter.constants import nwFiles
|
||||
from novelwriter.core.index import NWIndex, countWords, TagsIndex
|
||||
from novelwriter.core.project import NWProject
|
||||
|
||||
@@ -38,7 +39,7 @@ def testCoreIndex_LoadSave(monkeypatch, nwLipsum, mockGUI, outDir, refDir):
|
||||
"""Test core functionality of scaning, saving, loading and checking
|
||||
the index cache file.
|
||||
"""
|
||||
projFile = os.path.join(nwLipsum, "meta", "tagsIndex.json")
|
||||
projFile = os.path.join(nwLipsum, "meta", nwFiles.INDEX_FILE)
|
||||
testFile = os.path.join(outDir, "coreIndex_LoadSave_tagsIndex.json")
|
||||
compFile = os.path.join(refDir, "coreIndex_LoadSave_tagsIndex.json")
|
||||
|
||||
|
||||
@@ -235,7 +235,7 @@ def testCoreProject_Open(monkeypatch, caplog, mockGUI, fncDir, mockRnd):
|
||||
|
||||
# Won't convert legacy file
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr(ProjectXMLReader, "hexVersion", property(lambda *a: "0x99999999"))
|
||||
mp.setattr(ProjectXMLReader, "hexVersion", property(lambda *a: 0x99999999))
|
||||
mockGUI.askResponse = False
|
||||
assert theProject.openProject(fncDir) is False
|
||||
assert "This project was saved by a newer version" in mockGUI.lastQuestion[1]
|
||||
@@ -699,46 +699,42 @@ def testCoreProject_Backup(monkeypatch, mockGUI, fncDir, tmpDir):
|
||||
|
||||
# No project
|
||||
mockGUI.hasProject = False
|
||||
assert theProject.zipIt(doNotify=False) is False
|
||||
assert theProject.backupProject(doNotify=False) is False
|
||||
mockGUI.hasProject = True
|
||||
|
||||
# Invalid path
|
||||
theProject.mainConf.backupPath = None
|
||||
assert theProject.zipIt(doNotify=False) is False
|
||||
assert theProject.backupProject(doNotify=False) is False
|
||||
|
||||
# Missing project name
|
||||
theProject.mainConf.backupPath = tmpDir
|
||||
theProject.data.setName("")
|
||||
assert theProject.zipIt(doNotify=False) is False
|
||||
assert theProject.backupProject(doNotify=False) is False
|
||||
|
||||
# Non-existent folder
|
||||
theProject.mainConf.backupPath = os.path.join(tmpDir, "nonexistent")
|
||||
theProject.data.setName("Test Minimal")
|
||||
assert theProject.zipIt(doNotify=False) is False
|
||||
|
||||
# Same folder as project (causes infinite loop in zipping)
|
||||
theProject.mainConf.backupPath = fncDir
|
||||
assert theProject.zipIt(doNotify=False) is False
|
||||
assert theProject.backupProject(doNotify=False) is False
|
||||
|
||||
# Subfolder of project (causes infinite loop in zipping)
|
||||
theProject.mainConf.backupPath = os.path.join(fncDir, "subdir")
|
||||
assert theProject.zipIt(doNotify=False) is False
|
||||
assert theProject.backupProject(doNotify=False) is False
|
||||
|
||||
# Set a valid folder
|
||||
theProject.mainConf.backupPath = tmpDir
|
||||
|
||||
# Can't make folder
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr("os.mkdir", causeOSError)
|
||||
assert theProject.zipIt(doNotify=False) is False
|
||||
mp.setattr("pathlib.Path.mkdir", causeOSError)
|
||||
assert theProject.backupProject(doNotify=False) is False
|
||||
|
||||
# Can't write archive
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr("shutil.make_archive", causeOSError)
|
||||
assert theProject.zipIt(doNotify=False) is False
|
||||
mp.setattr("zipfile.ZipFile.write", causeOSError)
|
||||
assert theProject.backupProject(doNotify=False) is False
|
||||
|
||||
# Test correct settings
|
||||
assert theProject.zipIt(doNotify=True) is True
|
||||
assert theProject.backupProject(doNotify=True) is True
|
||||
|
||||
theFiles = os.listdir(os.path.join(tmpDir, "Test Minimal"))
|
||||
assert len(theFiles) == 1
|
||||
|
||||
@@ -131,7 +131,7 @@ def testCoreProjectXML_ReadCurrent(monkeypatch, tstPaths, fncPath):
|
||||
assert xmlReader.xmlRoot == "novelWriterXML"
|
||||
assert xmlReader.xmlVersion == 0x0105
|
||||
assert xmlReader.appVersion == "2.0-rc1"
|
||||
assert xmlReader.hexVersion == "0x020000c1"
|
||||
assert xmlReader.hexVersion == 0x020000c1
|
||||
|
||||
# Check loaded data
|
||||
assert data.name == "Sample Project"
|
||||
@@ -257,7 +257,7 @@ def testCoreProjectXML_ReadLegacy10(tstPaths, fncPath, mockRnd):
|
||||
assert xmlReader.xmlRoot == "novelWriterXML"
|
||||
assert xmlReader.xmlVersion == 0x0100
|
||||
assert xmlReader.appVersion == "0.6.1"
|
||||
assert xmlReader.hexVersion == "0x000601f0"
|
||||
assert xmlReader.hexVersion == 0x000601f0
|
||||
|
||||
# Check loaded data
|
||||
assert data.name == "Sample Project"
|
||||
@@ -399,7 +399,7 @@ def testCoreProjectXML_ReadLegacy11(tstPaths, fncPath, mockRnd):
|
||||
assert xmlReader.xmlRoot == "novelWriterXML"
|
||||
assert xmlReader.xmlVersion == 0x0101
|
||||
assert xmlReader.appVersion == "0.9.2"
|
||||
assert xmlReader.hexVersion == "0x000902f0"
|
||||
assert xmlReader.hexVersion == 0x000902f0
|
||||
|
||||
# Check loaded data
|
||||
assert data.name == "Sample Project"
|
||||
@@ -541,7 +541,7 @@ def testCoreProjectXML_ReadLegacy12(tstPaths, fncPath, mockRnd):
|
||||
assert xmlReader.xmlRoot == "novelWriterXML"
|
||||
assert xmlReader.xmlVersion == 0x0102
|
||||
assert xmlReader.appVersion == "1.4.2"
|
||||
assert xmlReader.hexVersion == "0x010402f0"
|
||||
assert xmlReader.hexVersion == 0x010402f0
|
||||
|
||||
# Check loaded data
|
||||
assert data.name == "Sample Project"
|
||||
@@ -686,7 +686,7 @@ def testCoreProjectXML_ReadLegacy13(tstPaths, fncPath, mockRnd):
|
||||
assert xmlReader.xmlRoot == "novelWriterXML"
|
||||
assert xmlReader.xmlVersion == 0x0103
|
||||
assert xmlReader.appVersion == "1.6.6"
|
||||
assert xmlReader.hexVersion == "0x010606f0"
|
||||
assert xmlReader.hexVersion == 0x010606f0
|
||||
|
||||
# Check loaded data
|
||||
assert data.name == "Sample Project"
|
||||
@@ -831,7 +831,7 @@ def testCoreProjectXML_ReadLegacy14(tstPaths, fncPath, mockRnd):
|
||||
assert xmlReader.xmlRoot == "novelWriterXML"
|
||||
assert xmlReader.xmlVersion == 0x0104
|
||||
assert xmlReader.appVersion == "2.0-rc1"
|
||||
assert xmlReader.hexVersion == "0x020000c1"
|
||||
assert xmlReader.hexVersion == 0x020000c1
|
||||
|
||||
# Check loaded data
|
||||
assert data.name == "Sample Project"
|
||||
|
||||
Reference in New Issue
Block a user