A good start on project tests. needed some tewaking of the project class.
This commit is contained in:
+11
-1
@@ -1,2 +1,12 @@
|
||||
# Python Temp
|
||||
__pycache__
|
||||
*.bak
|
||||
|
||||
# Sample Project
|
||||
sample/**/cache
|
||||
sample/**/wordlist.txt
|
||||
sample/**/*.bak
|
||||
|
||||
# PyTest
|
||||
tests/temp
|
||||
.pytest_cache
|
||||
pytestdebug.log
|
||||
|
||||
+12
-1
@@ -33,6 +33,9 @@ class NWProject():
|
||||
self.mainConf = self.theParent.mainConf
|
||||
self.projChanged = None
|
||||
|
||||
# Debug
|
||||
self.handleSeed = None
|
||||
|
||||
# Project Settings
|
||||
self.projTree = None
|
||||
self.treeOrder = None
|
||||
@@ -56,6 +59,9 @@ class NWProject():
|
||||
##
|
||||
|
||||
def newRoot(self, rootName, rootClass):
|
||||
if not self.checkRootUnique(rootClass):
|
||||
self.theParent.makeAlert("Duplicate root item detected!",2)
|
||||
return None
|
||||
newItem = NWItem()
|
||||
newItem.setName(rootName)
|
||||
newItem.setType(nwItemType.ROOT)
|
||||
@@ -422,7 +428,12 @@ class NWProject():
|
||||
return
|
||||
|
||||
def _makeHandle(self, addSeed=""):
|
||||
newSeed = str(time()) + addSeed
|
||||
if self.handleSeed is None:
|
||||
newSeed = str(time()) + addSeed
|
||||
else:
|
||||
# This is used for debugging
|
||||
newSeed = str(self.handleSeed)
|
||||
self.handleSeed += 1
|
||||
logger.verbose("Generating handle with seed '%s'" % newSeed)
|
||||
itemHandle = sha256(newSeed.encode()).hexdigest()[0:13]
|
||||
if itemHandle in self.projTree.keys():
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""novelWriter Test Dummy GUI Classes
|
||||
"""
|
||||
|
||||
class DummyMain():
|
||||
|
||||
def __init__(self):
|
||||
self.mainConf = None
|
||||
return
|
||||
|
||||
def makeAlert(self, theMessage, theLevel):
|
||||
if theLevel == 1:
|
||||
lvlMsg = "WARNING: "
|
||||
elif theLevel == 2:
|
||||
lvlMsg = "ERROR: "
|
||||
else:
|
||||
lvlMsg = ""
|
||||
if isinstance(theMessage, list):
|
||||
for msgLine in logMsg:
|
||||
print(lvlMsg+msgLine)
|
||||
else:
|
||||
print(lvlMsg+theMessage)
|
||||
return
|
||||
|
||||
def setStatus(self, theMessage):
|
||||
return
|
||||
|
||||
def setProjectStatus(self, isChanged):
|
||||
return
|
||||
|
||||
# END Class GuiMain
|
||||
@@ -2,6 +2,13 @@
|
||||
"""novelWriter Test Tools
|
||||
"""
|
||||
|
||||
from os import path, mkdir
|
||||
|
||||
def ensureDir(theDir):
|
||||
if not path.isdir(theDir):
|
||||
mkdir(theDir)
|
||||
return
|
||||
|
||||
def cmpFiles(fileOne, fileTwo, ignoreLines=[]):
|
||||
foOne = open(fileOne,mode="r")
|
||||
foTwo = open(fileTwo,mode="r")
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<novelWriterXML appVersion="0.1.0" fileVersion="1.0" timeStamp="2019-05-12 14:21:08">
|
||||
<project>
|
||||
<name></name>
|
||||
<title></title>
|
||||
</project>
|
||||
<content count="6">
|
||||
<item handle="73475cb40a568" order="None" parent="None">
|
||||
<name>Novel</name>
|
||||
<type>ROOT</type>
|
||||
<class>NOVEL</class>
|
||||
<status>0</status>
|
||||
<expanded>False</expanded>
|
||||
</item>
|
||||
<item handle="44cb730c42048" order="None" parent="None">
|
||||
<name>Characters</name>
|
||||
<type>ROOT</type>
|
||||
<class>CHARACTER</class>
|
||||
<status>0</status>
|
||||
<expanded>False</expanded>
|
||||
</item>
|
||||
<item handle="71ee45a3c0db9" order="None" parent="None">
|
||||
<name>Plot</name>
|
||||
<type>ROOT</type>
|
||||
<class>PLOT</class>
|
||||
<status>0</status>
|
||||
<expanded>False</expanded>
|
||||
</item>
|
||||
<item handle="811786ad1ae74" order="None" parent="None">
|
||||
<name>World</name>
|
||||
<type>ROOT</type>
|
||||
<class>WORLD</class>
|
||||
<status>0</status>
|
||||
<expanded>False</expanded>
|
||||
</item>
|
||||
<item handle="25fc0e7096fc6" order="None" parent="73475cb40a568">
|
||||
<name>New Chapter</name>
|
||||
<type>FOLDER</type>
|
||||
<class>NOVEL</class>
|
||||
<status>0</status>
|
||||
<expanded>False</expanded>
|
||||
</item>
|
||||
<item handle="31489056e0916" order="None" parent="25fc0e7096fc6">
|
||||
<name>New Scene</name>
|
||||
<type>FILE</type>
|
||||
<class>NOVEL</class>
|
||||
<status>0</status>
|
||||
<expanded>False</expanded>
|
||||
<layout>SCENE</layout>
|
||||
<charCount>0</charCount>
|
||||
<wordCount>0</wordCount>
|
||||
<paraCount>0</paraCount>
|
||||
</item>
|
||||
</content>
|
||||
</novelWriterXML>
|
||||
@@ -0,0 +1,83 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<novelWriterXML appVersion="0.1.0" fileVersion="1.0" timeStamp="2019-05-12 14:40:19">
|
||||
<project>
|
||||
<name></name>
|
||||
<title></title>
|
||||
</project>
|
||||
<content count="10">
|
||||
<item handle="73475cb40a568" order="None" parent="None">
|
||||
<name>Novel</name>
|
||||
<type>ROOT</type>
|
||||
<class>NOVEL</class>
|
||||
<status>0</status>
|
||||
<expanded>False</expanded>
|
||||
</item>
|
||||
<item handle="44cb730c42048" order="None" parent="None">
|
||||
<name>Characters</name>
|
||||
<type>ROOT</type>
|
||||
<class>CHARACTER</class>
|
||||
<status>0</status>
|
||||
<expanded>False</expanded>
|
||||
</item>
|
||||
<item handle="71ee45a3c0db9" order="None" parent="None">
|
||||
<name>Plot</name>
|
||||
<type>ROOT</type>
|
||||
<class>PLOT</class>
|
||||
<status>0</status>
|
||||
<expanded>False</expanded>
|
||||
</item>
|
||||
<item handle="811786ad1ae74" order="None" parent="None">
|
||||
<name>World</name>
|
||||
<type>ROOT</type>
|
||||
<class>WORLD</class>
|
||||
<status>0</status>
|
||||
<expanded>False</expanded>
|
||||
</item>
|
||||
<item handle="25fc0e7096fc6" order="None" parent="73475cb40a568">
|
||||
<name>New Chapter</name>
|
||||
<type>FOLDER</type>
|
||||
<class>NOVEL</class>
|
||||
<status>0</status>
|
||||
<expanded>False</expanded>
|
||||
</item>
|
||||
<item handle="31489056e0916" order="None" parent="25fc0e7096fc6">
|
||||
<name>New Scene</name>
|
||||
<type>FILE</type>
|
||||
<class>NOVEL</class>
|
||||
<status>0</status>
|
||||
<expanded>False</expanded>
|
||||
<layout>SCENE</layout>
|
||||
<charCount>0</charCount>
|
||||
<wordCount>0</wordCount>
|
||||
<paraCount>0</paraCount>
|
||||
</item>
|
||||
<item handle="39fa9ec190eee" order="None" parent="None">
|
||||
<name>Timeline</name>
|
||||
<type>ROOT</type>
|
||||
<class>TIMELINE</class>
|
||||
<status>0</status>
|
||||
<expanded>False</expanded>
|
||||
</item>
|
||||
<item handle="d029fa3a95e17" order="None" parent="None">
|
||||
<name>Object</name>
|
||||
<type>ROOT</type>
|
||||
<class>OBJECT</class>
|
||||
<status>0</status>
|
||||
<expanded>False</expanded>
|
||||
</item>
|
||||
<item handle="81b8a03f97e87" order="None" parent="None">
|
||||
<name>Custom1</name>
|
||||
<type>ROOT</type>
|
||||
<class>CUSTOM</class>
|
||||
<status>0</status>
|
||||
<expanded>False</expanded>
|
||||
</item>
|
||||
<item handle="da4ea2a5506f2" order="None" parent="None">
|
||||
<name>Custom2</name>
|
||||
<type>ROOT</type>
|
||||
<class>CUSTOM</class>
|
||||
<status>0</status>
|
||||
<expanded>False</expanded>
|
||||
</item>
|
||||
</content>
|
||||
</novelWriterXML>
|
||||
@@ -1,18 +1,10 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""novelWriter Config Class Tester
|
||||
|
||||
novelWriter – Config Class Tester
|
||||
===================================
|
||||
|
||||
"""
|
||||
|
||||
import nw
|
||||
import filecmp
|
||||
|
||||
from nwtools import cmpFiles
|
||||
|
||||
from nwtools import *
|
||||
from os import path, unlink
|
||||
|
||||
from nw.config import Config
|
||||
|
||||
theConf = Config()
|
||||
@@ -22,6 +14,8 @@ testRef = path.join(testDir,"reference")
|
||||
tmpConf = path.join(testTemp,"novelwriter.conf")
|
||||
refConf = path.join(testRef, "novelwriter.conf")
|
||||
|
||||
ensureDir(testTemp)
|
||||
|
||||
# Clean out old stuff
|
||||
if path.isfile(tmpConf):
|
||||
unlink(tmpConf)
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""novelWriter Project Class Tester
|
||||
"""
|
||||
|
||||
import nw
|
||||
import types
|
||||
from os import path, unlink
|
||||
|
||||
from nwtools import *
|
||||
from nwdummy import DummyMain
|
||||
|
||||
from nw.config import Config
|
||||
from nw.project.project import NWProject
|
||||
from nw.project.item import NWItem
|
||||
from nw.enum import nwItemClass
|
||||
|
||||
theConf = Config()
|
||||
theMain = DummyMain()
|
||||
theMain.mainConf = theConf
|
||||
testDir = path.dirname(__file__)
|
||||
testTemp = path.join(testDir,"temp")
|
||||
testRef = path.join(testDir,"reference")
|
||||
testProj = path.join(testTemp,"proj")
|
||||
|
||||
ensureDir(testTemp)
|
||||
ensureDir(testProj)
|
||||
|
||||
theConf.initConfig(testRef)
|
||||
theProject = NWProject(theMain)
|
||||
theProject.handleSeed = 42
|
||||
|
||||
projFile = path.join(testProj,"nwProject.nwx")
|
||||
|
||||
def testProjectNew():
|
||||
assert theProject.newProject()
|
||||
assert theProject.setProjectPath(testProj)
|
||||
assert theProject.saveProject()
|
||||
assert cmpFiles(projFile, path.join(testRef,"new_nwProject.nwx"), [2])
|
||||
|
||||
def testProjectOpen():
|
||||
assert theProject.openProject(projFile)
|
||||
|
||||
def testProjectSave():
|
||||
assert theProject.saveProject()
|
||||
assert cmpFiles(projFile, path.join(testRef,"new_nwProject.nwx"), [2])
|
||||
assert not theProject.projChanged
|
||||
|
||||
def testProjectNewRoot():
|
||||
assert theProject.openProject(projFile)
|
||||
assert isinstance(theProject.newRoot("Novel", nwItemClass.NOVEL), type(None))
|
||||
assert isinstance(theProject.newRoot("Plot", nwItemClass.PLOT), type(None))
|
||||
assert isinstance(theProject.newRoot("Character", nwItemClass.CHARACTER), type(None))
|
||||
assert isinstance(theProject.newRoot("World", nwItemClass.WORLD), type(None))
|
||||
assert isinstance(theProject.newRoot("Timeline", nwItemClass.TIMELINE), str)
|
||||
assert isinstance(theProject.newRoot("Object", nwItemClass.OBJECT), str)
|
||||
assert isinstance(theProject.newRoot("Custom1", nwItemClass.CUSTOM), str)
|
||||
assert isinstance(theProject.newRoot("Custom2", nwItemClass.CUSTOM), str)
|
||||
assert theProject.projChanged
|
||||
assert theProject.saveProject()
|
||||
assert cmpFiles(projFile, path.join(testRef,"roots_nwProject.nwx"), [2])
|
||||
assert not theProject.projChanged
|
||||
Reference in New Issue
Block a user