Make tests not depend on minimal project settings
This commit is contained in:
@@ -20,6 +20,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
import os
|
||||
import time
|
||||
import shutil
|
||||
|
||||
from PyQt5.QtWidgets import qApp
|
||||
@@ -119,3 +120,56 @@ def cleanProject(projPath):
|
||||
os.unlink(tocFile)
|
||||
|
||||
return
|
||||
|
||||
|
||||
def buildTestProject(theObject, projPath):
|
||||
"""Build a standard test project in projPath using theProject
|
||||
object as the parent.
|
||||
"""
|
||||
from novelwriter.enum import nwItemClass
|
||||
from novelwriter.core import NWProject, NWDoc
|
||||
|
||||
if isinstance(theObject, NWProject):
|
||||
theGUI = None
|
||||
theProject = theObject
|
||||
else:
|
||||
theGUI = theObject
|
||||
theProject = theObject.theProject
|
||||
|
||||
theProject.clearProject()
|
||||
theProject.setProjectPath(projPath, newProject=True)
|
||||
theProject.setProjectName("New Project")
|
||||
theProject.setBookTitle("New Novel")
|
||||
theProject.setBookAuthors("Jane Doe")
|
||||
|
||||
# Creating a minimal project with a few root folders and a
|
||||
# single chapter folder with a single file.
|
||||
xHandle = {}
|
||||
xHandle[1] = theProject.newRoot(theProject.tr("Novel"), nwItemClass.NOVEL)
|
||||
xHandle[2] = theProject.newRoot(theProject.tr("Plot"), nwItemClass.PLOT)
|
||||
xHandle[3] = theProject.newRoot(theProject.tr("Characters"), nwItemClass.CHARACTER)
|
||||
xHandle[4] = theProject.newRoot(theProject.tr("World"), nwItemClass.WORLD)
|
||||
xHandle[5] = theProject.newFile(theProject.tr("Title Page"), xHandle[1])
|
||||
xHandle[6] = theProject.newFolder(theProject.tr("New Chapter"), xHandle[1])
|
||||
xHandle[7] = theProject.newFile(theProject.tr("New Chapter"), xHandle[6])
|
||||
xHandle[8] = theProject.newFile(theProject.tr("New Scene"), xHandle[6])
|
||||
|
||||
aDoc = NWDoc(theProject, xHandle[5])
|
||||
aDoc.writeDocument("#! New Novel\n\n>> By Jane DOe <<\n")
|
||||
|
||||
aDoc = NWDoc(theProject, xHandle[7])
|
||||
aDoc.writeDocument("## %s\n\n" % theProject.tr("New Chapter"))
|
||||
|
||||
aDoc = NWDoc(theProject, xHandle[8])
|
||||
aDoc.writeDocument("### %s\n\n" % theProject.tr("New Scene"))
|
||||
|
||||
theProject.projOpened = time.time()
|
||||
theProject.setProjectChanged(True)
|
||||
theProject.saveProject(autoSave=True)
|
||||
|
||||
if theGUI is not None:
|
||||
theGUI.hasProject = True
|
||||
theGUI.rebuildTrees()
|
||||
theGUI.rebuildIndex(beQuiet=True)
|
||||
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user