From a46803232c39a4a4bd86a7998b01effa5f0b850a Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Tue, 11 Aug 2020 00:02:02 +0200 Subject: [PATCH] Added tests for new sample and new custom project --- tests/conftest.py | 14 ++ tests/nwdummy.py | 6 + tests/reference/proj/4_nwProject.nwx | 270 +++++++++++++++++++++++++++ tests/test_project.py | 57 +++++- 4 files changed, 345 insertions(+), 2 deletions(-) create mode 100644 tests/reference/proj/4_nwProject.nwx diff --git a/tests/conftest.py b/tests/conftest.py index c064c1d8..09031f4f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -38,6 +38,20 @@ def nwTempBuild(nwTemp): mkdir(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="session") def nwRef(): testDir = path.dirname(__file__) diff --git a/tests/nwdummy.py b/tests/nwdummy.py index 880a54eb..2e46352c 100644 --- a/tests/nwdummy.py +++ b/tests/nwdummy.py @@ -33,6 +33,12 @@ class DummyMain(): def setProjectStatus(self, isChanged): return + def openProject(self, projPath): + return + + def rebuildIndex(self): + return + # END Class GuiMain class StatusBar(): diff --git a/tests/reference/proj/4_nwProject.nwx b/tests/reference/proj/4_nwProject.nwx new file mode 100644 index 00000000..3dd716cc --- /dev/null +++ b/tests/reference/proj/4_nwProject.nwx @@ -0,0 +1,270 @@ + + + + Test Custom + Test Novel + Jane Doe + John Doh + 1 + 1 + 0 + + + True + False + True + None + None + 0 + 0 + 0 + + + %title% + Chapter %ch%: %title% + %title% + * * * +
+
+ + New + Note + Draft + Finished + + + New + Minor + Major + Main + +
+ + + Novel + ROOT + NOVEL + New + False + + + Plot + ROOT + PLOT + New + False + + + Characters + ROOT + CHARACTER + New + False + + + Locations + ROOT + WORLD + New + False + + + Timeline + ROOT + TIMELINE + New + False + + + Objects + ROOT + OBJECT + New + False + + + Entity + ROOT + ENTITY + New + False + + + Title Page + FILE + NOVEL + New + True + TITLE + 0 + 0 + 0 + 0 + + + Chapter 1 + FOLDER + NOVEL + New + False + + + Chapter 1 + FILE + NOVEL + New + True + CHAPTER + 0 + 0 + 0 + 0 + + + Scene 1.1 + FILE + NOVEL + New + True + SCENE + 0 + 0 + 0 + 0 + + + Scene 1.2 + FILE + NOVEL + New + True + SCENE + 0 + 0 + 0 + 0 + + + Scene 1.3 + FILE + NOVEL + New + True + SCENE + 0 + 0 + 0 + 0 + + + Chapter 2 + FOLDER + NOVEL + New + False + + + Chapter 2 + FILE + NOVEL + New + True + CHAPTER + 0 + 0 + 0 + 0 + + + Scene 2.1 + FILE + NOVEL + New + True + SCENE + 0 + 0 + 0 + 0 + + + Scene 2.2 + FILE + NOVEL + New + True + SCENE + 0 + 0 + 0 + 0 + + + Scene 2.3 + FILE + NOVEL + New + True + SCENE + 0 + 0 + 0 + 0 + + + Chapter 3 + FOLDER + NOVEL + New + False + + + Chapter 3 + FILE + NOVEL + New + True + CHAPTER + 0 + 0 + 0 + 0 + + + Scene 3.1 + FILE + NOVEL + New + True + SCENE + 0 + 0 + 0 + 0 + + + Scene 3.2 + FILE + NOVEL + New + True + SCENE + 0 + 0 + 0 + 0 + + + Scene 3.3 + FILE + NOVEL + New + True + SCENE + 0 + 0 + 0 + 0 + + +
diff --git a/tests/test_project.py b/tests/test_project.py index 8f35e35f..e27df3c4 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -22,9 +22,9 @@ theProject = NWProject(theMain) theProject.projTree.setSeed(42) @pytest.mark.project -def testProjectNew(nwTempProj,nwRef,nwTemp): +def testProjectNewMinimal(nwTempProj, nwRef, nwTemp): projFile = path.join(nwTempProj,"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}) assert theProject.setProjectPath(nwTempProj) @@ -217,3 +217,56 @@ def testIndexMeta(nwTempProj): assert str(theRefs) == "{'0e17daca5f3e1': 'T000001'}" 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 +def testProjectNewCustom(nwTempCustom, nwRef, nwTemp): + projData = { + "projName": "Test Custom", + "projTitle": "Test Novel", + "projAuthors": "Jane Doe\nJohn Doh\n", + "projPath": nwTempCustom, + "popSample": False, + "popMinimal": False, + "popCustom": True, + "addRoots": [ + nwItemClass.PLOT, + nwItemClass.CHARACTER, + nwItemClass.WORLD, + nwItemClass.TIMELINE, + nwItemClass.OBJECT, + nwItemClass.ENTITY, + ], + "numChapters": 3, + "numScenes": 3, + "chFolders": True, + } + theProject.mainConf = theConf + theProject.projTree.setSeed(42) + assert theProject.newProject(projData) + assert theProject.saveProject() + assert theProject.closeProject() + projFile = path.join(nwTempCustom, "nwProject.nwx") + refFile = path.join(nwRef, "proj", "4_nwProject.nwx") + assert cmpFiles(projFile, refFile, [2, 6, 7, 8]) + +@pytest.mark.project +def testProjectNewSample(nwTempSample, nwLipsum, nwRef, nwTemp): + projData = { + "projName": "Test Sample", + "projTitle": "Test Novel", + "projAuthors": "Jane Doe\nJohn Doh\n", + "projPath": nwTempSample, + "popSample": True, + "popMinimal": False, + "popCustom": False, + } + theProject.mainConf = theConf + assert theProject.newProject(projData) + assert theProject.openProject(nwTempSample) + assert theProject.projName == "Sample Project" + assert theProject.saveProject() + assert theProject.closeProject()