Made project tests independent

This commit is contained in:
Veronica K. B. Olsen
2020-08-28 12:31:38 +02:00
parent 447ddb73de
commit 8340c0665d
12 changed files with 390 additions and 122 deletions
+39 -18
View File
@@ -5,10 +5,14 @@
import sys import sys
import pytest import pytest
import shutil import shutil
from os import path, mkdir from os import path, mkdir
from nwdummy import DummyMain
sys.path.insert(1, path.abspath(path.join(path.dirname(__file__), path.pardir))) sys.path.insert(1, path.abspath(path.join(path.dirname(__file__), path.pardir)))
from nw.config import Config # noqa: E402
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
def nwTemp(): def nwTemp():
testDir = path.dirname(__file__) testDir = path.dirname(__file__)
@@ -19,6 +23,24 @@ def nwTemp():
mkdir(tempDir) mkdir(tempDir)
return tempDir return tempDir
@pytest.fixture(scope="session")
def nwRef():
testDir = path.dirname(__file__)
refDir = path.join(testDir, "reference")
return refDir
@pytest.fixture(scope="session")
def nwConf(nwRef, nwTemp):
theConf = Config()
theConf.initConfig(nwRef, nwTemp)
return theConf
@pytest.fixture(scope="session")
def nwDummy(nwRef, nwTemp, nwConf):
theDummy = DummyMain()
theDummy.mainConf = nwConf
return theDummy
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
def nwTempProj(nwTemp): def nwTempProj(nwTemp):
projDir = path.join(nwTemp, "proj") projDir = path.join(nwTemp, "proj")
@@ -40,20 +62,6 @@ def nwTempBuild(nwTemp):
mkdir(buildDir) mkdir(buildDir)
return buildDir return buildDir
@pytest.fixture(scope="session")
def nwTempCustom(nwTemp):
customDir = path.join(nwTemp, "custom")
if not path.isdir(customDir):
mkdir(customDir)
return customDir
@pytest.fixture(scope="session")
def nwTempSample(nwTemp):
sampleDir = path.join(nwTemp, "sample")
if not path.isdir(sampleDir):
mkdir(sampleDir)
return sampleDir
@pytest.fixture(scope="function") @pytest.fixture(scope="function")
def nwFuncTemp(nwTemp): def nwFuncTemp(nwTemp):
funcDir = path.join(nwTemp, "ftemp") funcDir = path.join(nwTemp, "ftemp")
@@ -66,11 +74,24 @@ def nwFuncTemp(nwTemp):
shutil.rmtree(funcDir) shutil.rmtree(funcDir)
return return
@pytest.fixture(scope="session") @pytest.fixture(scope="function")
def nwRef(): def nwMinimal(nwTemp):
testDir = path.dirname(__file__) testDir = path.dirname(__file__)
refDir = path.join(testDir, "reference") minimalStore = path.join(testDir, "minimal")
return refDir minimalDir = path.join(nwTemp, "minimal")
if path.isdir(minimalDir):
shutil.rmtree(minimalDir)
shutil.copytree(minimalStore, minimalDir)
cacheDir = path.join(minimalDir, "cache")
if path.isdir(cacheDir):
shutil.rmtree(cacheDir)
metaDir = path.join(minimalDir, "meta")
if path.isdir(metaDir):
shutil.rmtree(metaDir)
yield minimalDir
if path.isdir(minimalDir):
shutil.rmtree(minimalDir)
return
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
def nwLipsum(): def nwLipsum():
+17
View File
@@ -0,0 +1,17 @@
[
[
"content/8c659a11cd429.nwd",
"NOVEL",
"New Scene"
],
[
"content/a35baf2e93843.nwd",
"NOVEL",
"Title Page"
],
[
"content/f5ab3e30151e1.nwd",
"NOVEL",
"New Chapter"
]
]
+10
View File
@@ -0,0 +1,10 @@
Table of Contents
===================
File Name Class Document Label
--------------------------------------------------------------------------------
content/8c659a11cd429.nwd NOVEL New Scene
content/a35baf2e93843.nwd NOVEL Title Page
content/f5ab3e30151e1.nwd NOVEL New Chapter
+3
View File
@@ -0,0 +1,3 @@
%%~ 8c659a11cd429:a6d311a93600a:a508bb932959c:NOVEL:SCENE:New Scene
### New Scene
+4
View File
@@ -0,0 +1,4 @@
%%~ a35baf2e93843:a508bb932959c:NOVEL:TITLE:Title Page
# Minimal
By Jane Doe, John Doh
+3
View File
@@ -0,0 +1,3 @@
%%~ f5ab3e30151e1:a6d311a93600a:a508bb932959c:NOVEL:CHAPTER:New Chapter
## New Chapter
+1
View File
@@ -0,0 +1 @@
{}
+2
View File
@@ -0,0 +1,2 @@
# Start Time End Time Novel Notes
2020-08-28 11:36:36 2020-08-28 11:36:48 10 0
+91
View File
@@ -0,0 +1,91 @@
{
"tagIndex": {},
"refIndex": {
"a35baf2e93843": {
"T000000": {
"tags": [],
"updated": 1598607396
},
"T000001": {
"tags": [],
"updated": 1598607396
}
},
"f5ab3e30151e1": {
"T000000": {
"tags": [],
"updated": 1598607396
},
"T000001": {
"tags": [],
"updated": 1598607396
}
},
"8c659a11cd429": {
"T000000": {
"tags": [],
"updated": 1598607396
},
"T000001": {
"tags": [],
"updated": 1598607396
}
}
},
"novelIndex": {
"a35baf2e93843": {
"T000001": {
"level": "H1",
"title": "Minimal",
"layout": "TITLE",
"synopsis": "",
"cCount": 7,
"wCount": 1,
"pCount": 0,
"updated": 1598607396
}
},
"f5ab3e30151e1": {
"T000001": {
"level": "H2",
"title": "New Chapter",
"layout": "CHAPTER",
"synopsis": "",
"cCount": 11,
"wCount": 2,
"pCount": 0,
"updated": 1598607396
}
},
"8c659a11cd429": {
"T000001": {
"level": "H3",
"title": "New Scene",
"layout": "SCENE",
"synopsis": "",
"cCount": 9,
"wCount": 2,
"pCount": 0,
"updated": 1598607396
}
}
},
"noteIndex": {},
"textCounts": {
"a35baf2e93843": [
28,
6,
1
],
"f5ab3e30151e1": [
11,
2,
0
],
"8c659a11cd429": [
9,
2,
0
]
}
}
+115
View File
@@ -0,0 +1,115 @@
<?xml version='1.0' encoding='utf-8'?>
<novelWriterXML appVersion="0.12.1" hexVersion="0x001201f0" fileVersion="1.2" timeStamp="2020-08-28 11:36:45">
<project>
<name>Test Minimal</name>
<title>Minimal</title>
<author>Jane Doe</author>
<author>John Doh</author>
<saveCount>1</saveCount>
<autoCount>1</autoCount>
<editTime>8</editTime>
</project>
<settings>
<doBackup>True</doBackup>
<spellCheck>False</spellCheck>
<autoOutline>True</autoOutline>
<lastEdited>None</lastEdited>
<lastViewed>None</lastViewed>
<lastWordCount>10</lastWordCount>
<novelWordCount>10</novelWordCount>
<notesWordCount>0</notesWordCount>
<autoReplace/>
<titleFormat>
<title>%title%</title>
<chapter>Chapter %ch%: %title%</chapter>
<unnumbered>%title%</unnumbered>
<scene>* * *</scene>
<section></section>
</titleFormat>
<status>
<entry blue="100" green="100" red="100">New</entry>
<entry blue="0" green="50" red="200">Note</entry>
<entry blue="0" green="150" red="200">Draft</entry>
<entry blue="0" green="200" red="50">Finished</entry>
</status>
<importance>
<entry blue="100" green="100" red="100">New</entry>
<entry blue="0" green="50" red="200">Minor</entry>
<entry blue="0" green="150" red="200">Major</entry>
<entry blue="0" green="200" red="50">Main</entry>
</importance>
</settings>
<content count="8">
<item handle="a508bb932959c" order="0" parent="None">
<name>Novel</name>
<type>ROOT</type>
<class>NOVEL</class>
<status>New</status>
<expanded>False</expanded>
</item>
<item handle="a35baf2e93843" order="0" parent="a508bb932959c">
<name>Title Page</name>
<type>FILE</type>
<class>NOVEL</class>
<status>New</status>
<exported>True</exported>
<layout>TITLE</layout>
<charCount>28</charCount>
<wordCount>6</wordCount>
<paraCount>1</paraCount>
<cursorPos>0</cursorPos>
</item>
<item handle="a6d311a93600a" order="1" parent="a508bb932959c">
<name>New Chapter</name>
<type>FOLDER</type>
<class>NOVEL</class>
<status>New</status>
<expanded>False</expanded>
</item>
<item handle="f5ab3e30151e1" order="0" parent="a6d311a93600a">
<name>New Chapter</name>
<type>FILE</type>
<class>NOVEL</class>
<status>New</status>
<exported>True</exported>
<layout>CHAPTER</layout>
<charCount>11</charCount>
<wordCount>2</wordCount>
<paraCount>0</paraCount>
<cursorPos>0</cursorPos>
</item>
<item handle="8c659a11cd429" order="1" parent="a6d311a93600a">
<name>New Scene</name>
<type>FILE</type>
<class>NOVEL</class>
<status>New</status>
<exported>True</exported>
<layout>SCENE</layout>
<charCount>9</charCount>
<wordCount>2</wordCount>
<paraCount>0</paraCount>
<cursorPos>0</cursorPos>
</item>
<item handle="7695ce551d265" order="1" parent="None">
<name>Plot</name>
<type>ROOT</type>
<class>PLOT</class>
<status>New</status>
<expanded>False</expanded>
</item>
<item handle="afb3043c7b2b3" order="2" parent="None">
<name>Characters</name>
<type>ROOT</type>
<class>CHARACTER</class>
<status>New</status>
<expanded>False</expanded>
</item>
<item handle="9d5247ab588e0" order="3" parent="None">
<name>World</name>
<type>ROOT</type>
<class>WORLD</class>
<status>New</status>
<expanded>False</expanded>
</item>
</content>
</novelWriterXML>
+5 -33
View File
@@ -1,9 +1,9 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version='1.0' encoding='utf-8'?>
<novelWriterXML appVersion="0.11.1" hexVersion="0x001101f0" fileVersion="1.2" timeStamp="2020-08-10 21:29:43"> <novelWriterXML appVersion="0.12.1" hexVersion="0x001201f0" fileVersion="1.2" timeStamp="2020-08-28 11:58:47">
<project> <project>
<name>New Project</name> <name>New Project</name>
<title></title> <title></title>
<saveCount>5</saveCount> <saveCount>2</saveCount>
<autoCount>1</autoCount> <autoCount>1</autoCount>
<editTime>0</editTime> <editTime>0</editTime>
</project> </project>
@@ -37,7 +37,7 @@
<entry blue="0" green="200" red="50">Main</entry> <entry blue="0" green="200" red="50">Main</entry>
</importance> </importance>
</settings> </settings>
<content count="14"> <content count="10">
<item handle="73475cb40a568" order="None" parent="None"> <item handle="73475cb40a568" order="None" parent="None">
<name>Novel</name> <name>Novel</name>
<type>ROOT</type> <type>ROOT</type>
@@ -109,35 +109,7 @@
<paraCount>0</paraCount> <paraCount>0</paraCount>
<cursorPos>0</cursorPos> <cursorPos>0</cursorPos>
</item> </item>
<item handle="1a6562590ef19" order="None" parent="None"> <item handle="1a6562590ef19" order="None" parent="31489056e0916">
<name>Timeline</name>
<type>ROOT</type>
<class>TIMELINE</class>
<status>New</status>
<expanded>False</expanded>
</item>
<item handle="031b4af5197ec" order="None" parent="None">
<name>Object</name>
<type>ROOT</type>
<class>OBJECT</class>
<status>New</status>
<expanded>False</expanded>
</item>
<item handle="41cfc0d1f2d12" order="None" parent="None">
<name>Custom1</name>
<type>ROOT</type>
<class>CUSTOM</class>
<status>New</status>
<expanded>False</expanded>
</item>
<item handle="2858dcd1057d3" order="None" parent="None">
<name>Custom2</name>
<type>ROOT</type>
<class>CUSTOM</class>
<status>New</status>
<expanded>False</expanded>
</item>
<item handle="2fca346db6561" order="None" parent="73475cb40a568">
<name>Hello</name> <name>Hello</name>
<type>FILE</type> <type>FILE</type>
<class>NOVEL</class> <class>NOVEL</class>
@@ -149,7 +121,7 @@
<paraCount>0</paraCount> <paraCount>0</paraCount>
<cursorPos>0</cursorPos> <cursorPos>0</cursorPos>
</item> </item>
<item handle="02d20bbd7e394" order="None" parent="71ee45a3c0db9"> <item handle="031b4af5197ec" order="None" parent="71ee45a3c0db9">
<name>Jane</name> <name>Jane</name>
<type>FILE</type> <type>FILE</type>
<class>CHARACTER</class> <class>CHARACTER</class>
+100 -71
View File
@@ -4,63 +4,66 @@
import pytest import pytest
from os import path from os import path
from shutil import copyfile
from nwtools import cmpFiles from nwtools import cmpFiles
from nwdummy import DummyMain
from nw.config import Config
from nw.core.project import NWProject from nw.core.project import NWProject
from nw.core.index import NWIndex from nw.core.index import NWIndex
from nw.constants import nwItemClass from nw.constants import nwItemClass
theConf = Config()
theMain = DummyMain()
theMain.mainConf = theConf
theProject = NWProject(theMain)
theProject.projTree.setSeed(42)
@pytest.mark.project @pytest.mark.project
def testProjectNewMinimal(nwTempProj, nwRef, nwTemp): def testProjectNewOpenSave(nwFuncTemp, nwTempProj, nwRef, nwTemp, nwDummy):
projFile = path.join(nwTempProj, "nwProject.nwx") projFile = path.join(nwFuncTemp, "nwProject.nwx")
testFile = path.join(nwTempProj, "1_nwProject.nwx")
refFile = path.join(nwRef, "proj", "1_nwProject.nwx") refFile = path.join(nwRef, "proj", "1_nwProject.nwx")
assert theConf.initConfig(nwRef, nwTemp)
assert theProject.newProject({"projPath": nwTempProj}) theProject = NWProject(nwDummy)
assert theProject.setProjectPath(nwTempProj) theProject.projTree.setSeed(42)
assert theProject.newProject({"projPath": nwFuncTemp})
assert theProject.setProjectPath(nwFuncTemp)
assert theProject.saveProject() assert theProject.saveProject()
assert theProject.closeProject() assert theProject.closeProject()
assert cmpFiles(projFile, refFile, [2, 6, 7, 8])
@pytest.mark.project # Check the new project
def testProjectOpen(nwTempProj): copyfile(projFile, testFile)
projFile = path.join(nwTempProj, "nwProject.nwx") assert cmpFiles(testFile, refFile, [2, 6, 7, 8])
# Open again
assert theProject.openProject(projFile) assert theProject.openProject(projFile)
@pytest.mark.project # Save and close
def testProjectSave(nwTempProj, nwRef):
projFile = path.join(nwTempProj, "nwProject.nwx")
refFile = path.join(nwRef, "proj", "1_nwProject.nwx")
assert theProject.saveProject() assert theProject.saveProject()
assert theProject.closeProject() assert theProject.closeProject()
assert cmpFiles(projFile, refFile, [2, 6, 7, 8]) copyfile(projFile, testFile)
assert cmpFiles(testFile, refFile, [2, 6, 7, 8])
assert not theProject.projChanged assert not theProject.projChanged
@pytest.mark.project # Open a second time
def testProjectOpenTwice(nwTempProj, nwRef):
projFile = path.join(nwTempProj, "nwProject.nwx")
refFile = path.join(nwRef, "proj", "1_nwProject.nwx")
assert theProject.openProject(projFile) assert theProject.openProject(projFile)
assert not theProject.openProject(projFile) assert not theProject.openProject(projFile)
assert theProject.openProject(projFile, overrideLock=True) assert theProject.openProject(projFile, overrideLock=True)
assert theProject.saveProject() assert theProject.saveProject()
assert theProject.closeProject() assert theProject.closeProject()
assert cmpFiles(projFile, refFile, [2, 6, 7, 8]) copyfile(projFile, testFile)
assert cmpFiles(testFile, refFile, [2, 6, 7, 8])
@pytest.mark.project @pytest.mark.project
def testProjectNewRoot(nwTempProj, nwRef): def testProjectNewRoot(nwFuncTemp, nwTempProj, nwRef, nwDummy):
projFile = path.join(nwTempProj, "nwProject.nwx") projFile = path.join(nwFuncTemp, "nwProject.nwx")
testFile = path.join(nwTempProj, "2_nwProject.nwx")
refFile = path.join(nwRef, "proj", "2_nwProject.nwx") refFile = path.join(nwRef, "proj", "2_nwProject.nwx")
theProject = NWProject(nwDummy)
theProject.projTree.setSeed(42)
assert theProject.newProject({"projPath": nwFuncTemp})
assert theProject.setProjectPath(nwFuncTemp)
assert theProject.saveProject()
assert theProject.closeProject()
assert theProject.openProject(projFile) assert theProject.openProject(projFile)
assert isinstance(theProject.newRoot("Novel", nwItemClass.NOVEL), type(None)) assert isinstance(theProject.newRoot("Novel", nwItemClass.NOVEL), type(None))
assert isinstance(theProject.newRoot("Plot", nwItemClass.PLOT), type(None)) assert isinstance(theProject.newRoot("Plot", nwItemClass.PLOT), type(None))
assert isinstance(theProject.newRoot("Character", nwItemClass.CHARACTER), type(None)) assert isinstance(theProject.newRoot("Character", nwItemClass.CHARACTER), type(None))
@@ -69,31 +72,48 @@ def testProjectNewRoot(nwTempProj, nwRef):
assert isinstance(theProject.newRoot("Object", nwItemClass.OBJECT), str) assert isinstance(theProject.newRoot("Object", nwItemClass.OBJECT), str)
assert isinstance(theProject.newRoot("Custom1", nwItemClass.CUSTOM), str) assert isinstance(theProject.newRoot("Custom1", nwItemClass.CUSTOM), str)
assert isinstance(theProject.newRoot("Custom2", nwItemClass.CUSTOM), str) assert isinstance(theProject.newRoot("Custom2", nwItemClass.CUSTOM), str)
assert theProject.projChanged assert theProject.projChanged
assert theProject.saveProject() assert theProject.saveProject()
assert theProject.closeProject() assert theProject.closeProject()
assert cmpFiles(projFile, refFile, [2, 6, 7, 8])
copyfile(projFile, testFile)
assert cmpFiles(testFile, refFile, [2, 6, 7, 8])
assert not theProject.projChanged assert not theProject.projChanged
@pytest.mark.project @pytest.mark.project
def testProjectNewFile(nwTempProj, nwRef): def testProjectNewFile(nwFuncTemp, nwTempProj, nwRef, nwDummy):
projFile = path.join(nwTempProj, "nwProject.nwx") projFile = path.join(nwFuncTemp, "nwProject.nwx")
testFile = path.join(nwTempProj, "3_nwProject.nwx")
refFile = path.join(nwRef, "proj", "3_nwProject.nwx") refFile = path.join(nwRef, "proj", "3_nwProject.nwx")
theProject = NWProject(nwDummy)
theProject.projTree.setSeed(42)
assert theProject.newProject({"projPath": nwFuncTemp})
assert theProject.setProjectPath(nwFuncTemp)
assert theProject.saveProject()
assert theProject.closeProject()
assert theProject.openProject(projFile) assert theProject.openProject(projFile)
assert isinstance(theProject.newFile("Hello", nwItemClass.NOVEL, "73475cb40a568"), str)
assert isinstance(theProject.newFile("Hello", nwItemClass.NOVEL, "31489056e0916"), str)
assert isinstance(theProject.newFile("Jane", nwItemClass.CHARACTER, "71ee45a3c0db9"), str) assert isinstance(theProject.newFile("Jane", nwItemClass.CHARACTER, "71ee45a3c0db9"), str)
assert theProject.projChanged assert theProject.projChanged
assert theProject.saveProject() assert theProject.saveProject()
assert theProject.closeProject() assert theProject.closeProject()
assert cmpFiles(projFile, refFile, [2, 6, 7, 8])
copyfile(projFile, testFile)
assert cmpFiles(testFile, refFile, [2, 6, 7, 8])
assert not theProject.projChanged assert not theProject.projChanged
@pytest.mark.project @pytest.mark.project
def testIndexScanThis(nwTempProj): def testIndexScanThis(nwMinimal, nwDummy):
projFile = path.join(nwTempProj, "nwProject.nwx")
assert theProject.openProject(projFile)
theIndex = NWIndex(theProject, theMain) theProject = NWProject(nwDummy)
theProject.projTree.setSeed(42)
assert theProject.openProject(nwMinimal)
theIndex = NWIndex(theProject, nwDummy)
isValid, theBits, thePos = theIndex.scanThis("tag: this, and this") isValid, theBits, thePos = theIndex.scanThis("tag: this, and this")
assert not isValid assert not isValid
@@ -135,15 +155,17 @@ def testIndexScanThis(nwTempProj):
assert theProject.closeProject() assert theProject.closeProject()
@pytest.mark.project @pytest.mark.project
def testIndexCheckThese(nwTempProj): def testIndexCheckThese(nwMinimal, nwDummy):
projFile = path.join(nwTempProj, "nwProject.nwx")
assert theProject.openProject(projFile)
theIndex = NWIndex(theProject, theMain) theProject = NWProject(nwDummy)
nHandle = "0e17daca5f3e1" theProject.projTree.setSeed(42)
nItem = theProject.projTree[nHandle] assert theProject.openProject(nwMinimal)
cHandle = "02d20bbd7e394"
cItem = theProject.projTree[cHandle] theIndex = NWIndex(theProject, nwDummy)
nHandle = theProject.newFile("Hello", nwItemClass.NOVEL, "a508bb932959c")
cHandle = theProject.newFile("Jane", nwItemClass.CHARACTER, "afb3043c7b2b3")
nItem = theProject.projTree[nHandle]
cItem = theProject.projTree[cHandle]
assert theIndex.scanText(cHandle, ( assert theIndex.scanText(cHandle, (
"# Jane Smith\n" "# Jane Smith\n"
@@ -153,7 +175,7 @@ def testIndexCheckThese(nwTempProj):
"# Hello World!\n" "# Hello World!\n"
"@pov: Jane" "@pov: Jane"
)) ))
assert str(theIndex.tagIndex) == "{'Jane': [2, '02d20bbd7e394', 'CHARACTER', 'T000001']}" assert str(theIndex.tagIndex) == "{'Jane': [2, '%s', 'CHARACTER', 'T000001']}" % cHandle
assert theIndex.novelIndex[nHandle]["T000001"]["title"] == "Hello World!" assert theIndex.novelIndex[nHandle]["T000001"]["title"] == "Hello World!"
assert str(theIndex.checkThese(["@tag", "Jane"], cItem)) == "[True, True]" assert str(theIndex.checkThese(["@tag", "Jane"], cItem)) == "[True, True]"
@@ -168,13 +190,15 @@ def testIndexCheckThese(nwTempProj):
assert theProject.closeProject() assert theProject.closeProject()
@pytest.mark.project @pytest.mark.project
def testIndexMeta(nwTempProj): def testIndexMeta(nwMinimal, nwDummy):
projFile = path.join(nwTempProj, "nwProject.nwx")
assert theProject.openProject(projFile)
theIndex = NWIndex(theProject, theMain) theProject = NWProject(nwDummy)
nHandle = "0e17daca5f3e1" theProject.projTree.setSeed(42)
cHandle = "02d20bbd7e394" assert theProject.openProject(nwMinimal)
theIndex = NWIndex(theProject, nwDummy)
nHandle = theProject.newFile("Hello", nwItemClass.NOVEL, "a508bb932959c")
cHandle = theProject.newFile("Jane", nwItemClass.CHARACTER, "afb3043c7b2b3")
assert theIndex.scanText(cHandle, ( assert theIndex.scanText(cHandle, (
"# Jane Smith\n" "# Jane Smith\n"
@@ -191,11 +215,11 @@ def testIndexMeta(nwTempProj):
"\n" "\n"
"Well, not really.\n" "Well, not really.\n"
)) ))
assert str(theIndex.tagIndex) == "{'Jane': [2, '02d20bbd7e394', 'CHARACTER', 'T000001']}" assert str(theIndex.tagIndex) == "{'Jane': [2, '%s', 'CHARACTER', 'T000001']}" % cHandle
assert theIndex.novelIndex[nHandle]["T000001"]["title"] == "Hello World!" assert theIndex.novelIndex[nHandle]["T000001"]["title"] == "Hello World!"
# The novel structure should contain the pointer to the novel file header # The novel structure should contain the pointer to the novel file header
assert str(theIndex.getNovelStructure()) == "['0e17daca5f3e1:T000001']" assert str(theIndex.getNovelStructure()) == "['%s:T000001']" % nHandle
# The novel file should have the correct counts # The novel file should have the correct counts
cC, wC, pC = theIndex.getCounts(nHandle) cC, wC, pC = theIndex.getCounts(nHandle)
@@ -210,21 +234,22 @@ def testIndexMeta(nwTempProj):
# The character file should have a record of the reference from the novel file # The character file should have a record of the reference from the novel file
theRefs = theIndex.getBackReferenceList(cHandle) theRefs = theIndex.getBackReferenceList(cHandle)
assert str(theRefs) == "{'0e17daca5f3e1': 'T000001'}" assert str(theRefs) == "{'%s': 'T000001'}" % nHandle
assert theProject.closeProject() assert theProject.closeProject()
# The two following tests must be at the end as they mess up the config object
# and the handle seed. They go into their own folders, but use the same project
# object as the test above.
@pytest.mark.project @pytest.mark.project
def testProjectNewCustom(nwTempCustom, nwRef, nwTemp): def testProjectNewCustom(nwFuncTemp, nwTempProj, nwRef, nwDummy):
projFile = path.join(nwFuncTemp, "nwProject.nwx")
testFile = path.join(nwTempProj, "4_nwProject.nwx")
refFile = path.join(nwRef, "proj", "4_nwProject.nwx")
projData = { projData = {
"projName": "Test Custom", "projName": "Test Custom",
"projTitle": "Test Novel", "projTitle": "Test Novel",
"projAuthors": "Jane Doe\nJohn Doh\n", "projAuthors": "Jane Doe\nJohn Doh\n",
"projPath": nwTempCustom, "projPath": nwFuncTemp,
"popSample": False, "popSample": False,
"popMinimal": False, "popMinimal": False,
"popCustom": True, "popCustom": True,
@@ -240,29 +265,33 @@ def testProjectNewCustom(nwTempCustom, nwRef, nwTemp):
"numScenes": 3, "numScenes": 3,
"chFolders": True, "chFolders": True,
} }
theProject.mainConf = theConf theProject = NWProject(nwDummy)
theProject.projTree.setSeed(42) theProject.projTree.setSeed(42)
assert theProject.newProject(projData) assert theProject.newProject(projData)
assert theProject.saveProject() assert theProject.saveProject()
assert theProject.closeProject() assert theProject.closeProject()
projFile = path.join(nwTempCustom, "nwProject.nwx")
refFile = path.join(nwRef, "proj", "4_nwProject.nwx") copyfile(projFile, testFile)
assert cmpFiles(projFile, refFile, [2, 6, 7, 8]) assert cmpFiles(testFile, refFile, [2, 6, 7, 8])
@pytest.mark.project @pytest.mark.project
def testProjectNewSample(nwTempSample, nwLipsum, nwRef, nwTemp): def testProjectNewSample(nwFuncTemp, nwRef, nwConf, nwDummy):
projData = { projData = {
"projName": "Test Sample", "projName": "Test Sample",
"projTitle": "Test Novel", "projTitle": "Test Novel",
"projAuthors": "Jane Doe\nJohn Doh\n", "projAuthors": "Jane Doe\nJohn Doh\n",
"projPath": nwTempSample, "projPath": nwFuncTemp,
"popSample": True, "popSample": True,
"popMinimal": False, "popMinimal": False,
"popCustom": False, "popCustom": False,
} }
theProject.mainConf = theConf theProject = NWProject(nwDummy)
theProject.projTree.setSeed(42)
theProject.mainConf = nwConf
assert theProject.newProject(projData) assert theProject.newProject(projData)
assert theProject.openProject(nwTempSample) assert theProject.openProject(nwFuncTemp)
assert theProject.projName == "Sample Project" assert theProject.projName == "Sample Project"
assert theProject.saveProject() assert theProject.saveProject()
assert theProject.closeProject() assert theProject.closeProject()