From 38df69398783e23e2d3e011dd33d850fa6fcb94d Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Mon, 17 Oct 2022 21:15:52 +0200 Subject: [PATCH] Update tests --- sample/nwProject.nwx | 44 ++--- tests/minimal/nwProject.nwx | 14 +- .../coreDocTools_DocMerger_0000000000010.nwd | 6 +- .../coreDocTools_DocMerger_0000000000014.nwd | 8 +- .../coreIndex_LoadSave_tagsIndex.json | 15 -- .../coreProject_NewCustomA_nwProject.nwx | 34 ++-- .../coreProject_NewCustomB_nwProject.nwx | 22 +-- .../coreProject_NewFileFolder_nwProject.nwx | 16 +- .../coreProject_NewMinimal_nwProject.nwx | 8 +- .../coreProject_NewRoot_nwProject.nwx | 12 +- .../guiEditor_Main_Final_nwProject.nwx | 16 +- .../guiEditor_Main_Initial_nwProject.nwx | 8 +- .../guiProjSettings_Dialog_nwProject.nwx | 8 +- tests/test_core/test_core_index.py | 164 +++++++++--------- tests/test_core/test_core_item.py | 39 ++++- tests/test_core/test_core_tree.py | 18 +- tests/tools.py | 6 +- 17 files changed, 225 insertions(+), 213 deletions(-) diff --git a/sample/nwProject.nwx b/sample/nwProject.nwx index c822a904..75f59236 100644 --- a/sample/nwProject.nwx +++ b/sample/nwProject.nwx @@ -1,13 +1,13 @@ - + Sample Project Sample Project Jane Smith Jay Doh - 1382 + 1383 236 - 69339 + 69344 False @@ -55,43 +55,43 @@ Novel - + Title Page - + Page - + Part One - + Chapter One - + Making a Scene - + Another Scene - + Interlude - + A Note on Structure - + Chapter Two - + We Found John! @@ -99,11 +99,11 @@ Sequel - + Title Page - + Chapter One @@ -115,11 +115,11 @@ Main Characters - + John Smith - + Jane Smith @@ -127,15 +127,15 @@ Locations - + Earth - + Space - + Mars @@ -147,7 +147,7 @@ Scenes - + Old File @@ -155,7 +155,7 @@ Trash - + Delete Me! diff --git a/tests/minimal/nwProject.nwx b/tests/minimal/nwProject.nwx index 5862d48c..99f81105 100644 --- a/tests/minimal/nwProject.nwx +++ b/tests/minimal/nwProject.nwx @@ -1,13 +1,13 @@ - + Test Minimal Minimal Jane Doe John Doh - 17 + 19 2 - 150 + 167 True @@ -16,7 +16,7 @@ None None None - None + a508bb932959c None 10 10 @@ -48,7 +48,7 @@ Novel - + Title Page @@ -56,11 +56,11 @@ New Chapter - + New Chapter - + New Scene diff --git a/tests/reference/coreDocTools_DocMerger_0000000000010.nwd b/tests/reference/coreDocTools_DocMerger_0000000000010.nwd index 6dac570d..eb13ead2 100644 --- a/tests/reference/coreDocTools_DocMerger_0000000000010.nwd +++ b/tests/reference/coreDocTools_DocMerger_0000000000010.nwd @@ -7,7 +7,7 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc maximus justo non Nullam laoreet lorem nec malesuada vehicula. Vivamus tempus sodales lectus sed viverra. Aenean lacinia sollicitudin quam, quis tempus eros suscipit id. Duis sed rutrum nisi, ut pulvinar magna. Nam et cursus tortor. Phasellus ac odio tellus. Nullam in iaculis ipsum. Vivamus ante sem, ultricies sed varius quis, tristique nec tellus. Nullam eu urna vitae lacus hendrerit gravida. Quisque pulvinar erat ex, id efficitur velit sodales vitae. Proin vestibulum, sapien eget mattis euismod, tortor quam viverra risus, at congue mauris tortor eu nunc. Mauris pellentesque elit leo, quis eleifend sem placerat a. Vivamus iaculis dui eget tellus volutpat, ac varius nisi facilisis. -% Merge Novel Document: Scene 1.1 [New] +% Merge Novel Scene: Scene 1.1 [New] ### Scene 1.1 @@ -15,7 +15,7 @@ Nullam laoreet lorem nec malesuada vehicula. Vivamus tempus sodales lectus sed v Nullam a nisl magna. Praesent commodo nec diam aliquet vestibulum. In sapien velit, sodales feugiat porta ut, rhoncus a elit. Quisque egestas nisi eu eros laoreet, quis facilisis est pretium. Nullam bibendum sed tellus nec lobortis. Duis elit massa, volutpat a lacinia a, ullamcorper in dui. Suspendisse ac laoreet dui. Curabitur elementum, tortor elementum ultricies laoreet, nunc massa vulputate augue, vitae tincidunt nunc enim eget nisl. -% Merge Novel Document: Scene 1.2 [New] +% Merge Novel Scene: Scene 1.2 [New] ### Scene 1.2 @@ -23,7 +23,7 @@ Nullam a nisl magna. Praesent commodo nec diam aliquet vestibulum. In sapien vel Pellentesque nibh urna, volutpat et feugiat porta, rutrum sed lectus. Aliquam eget risus id orci tincidunt condimentum et sit amet purus. Curabitur tincidunt odio vel ante feugiat feugiat. Proin nunc lorem, molestie a sapien et, varius elementum nunc. Donec non fermentum nisl. In et massa placerat, faucibus felis eu, congue nisi. Proin sed tortor non lorem mattis cursus. Vestibulum magna neque, bibendum vel nibh et, tincidunt rhoncus nisi. Duis pulvinar mi a quam rutrum maximus. Nunc sollicitudin, urna in cursus facilisis, augue neque imperdiet metus, ac finibus lorem ante id nulla. Sed maximus eleifend justo id feugiat. Cras eget diam vel est blandit tempor nec a leo. Mauris risus est, fringilla in aliquam a, sagittis vel enim. Nullam sodales id erat placerat lobortis. -% Merge Novel Document: Scene 1.3 [New] +% Merge Novel Scene: Scene 1.3 [New] ### Scene 1.3 diff --git a/tests/reference/coreDocTools_DocMerger_0000000000014.nwd b/tests/reference/coreDocTools_DocMerger_0000000000014.nwd index 6a0d3548..199454dc 100644 --- a/tests/reference/coreDocTools_DocMerger_0000000000014.nwd +++ b/tests/reference/coreDocTools_DocMerger_0000000000014.nwd @@ -1,7 +1,7 @@ %%~name: All of Chapter 1 %%~path: 0000000000008/0000000000014 %%~kind: NOVEL/DOCUMENT -% Merge Novel Document: Chapter 1 [New] +% Merge Novel Chapter: Chapter 1 [New] ## Chapter 1 @@ -9,7 +9,7 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc maximus justo non Nullam laoreet lorem nec malesuada vehicula. Vivamus tempus sodales lectus sed viverra. Aenean lacinia sollicitudin quam, quis tempus eros suscipit id. Duis sed rutrum nisi, ut pulvinar magna. Nam et cursus tortor. Phasellus ac odio tellus. Nullam in iaculis ipsum. Vivamus ante sem, ultricies sed varius quis, tristique nec tellus. Nullam eu urna vitae lacus hendrerit gravida. Quisque pulvinar erat ex, id efficitur velit sodales vitae. Proin vestibulum, sapien eget mattis euismod, tortor quam viverra risus, at congue mauris tortor eu nunc. Mauris pellentesque elit leo, quis eleifend sem placerat a. Vivamus iaculis dui eget tellus volutpat, ac varius nisi facilisis. -% Merge Novel Document: Scene 1.1 [New] +% Merge Novel Scene: Scene 1.1 [New] ### Scene 1.1 @@ -17,7 +17,7 @@ Nullam laoreet lorem nec malesuada vehicula. Vivamus tempus sodales lectus sed v Nullam a nisl magna. Praesent commodo nec diam aliquet vestibulum. In sapien velit, sodales feugiat porta ut, rhoncus a elit. Quisque egestas nisi eu eros laoreet, quis facilisis est pretium. Nullam bibendum sed tellus nec lobortis. Duis elit massa, volutpat a lacinia a, ullamcorper in dui. Suspendisse ac laoreet dui. Curabitur elementum, tortor elementum ultricies laoreet, nunc massa vulputate augue, vitae tincidunt nunc enim eget nisl. -% Merge Novel Document: Scene 1.2 [New] +% Merge Novel Scene: Scene 1.2 [New] ### Scene 1.2 @@ -25,7 +25,7 @@ Nullam a nisl magna. Praesent commodo nec diam aliquet vestibulum. In sapien vel Pellentesque nibh urna, volutpat et feugiat porta, rutrum sed lectus. Aliquam eget risus id orci tincidunt condimentum et sit amet purus. Curabitur tincidunt odio vel ante feugiat feugiat. Proin nunc lorem, molestie a sapien et, varius elementum nunc. Donec non fermentum nisl. In et massa placerat, faucibus felis eu, congue nisi. Proin sed tortor non lorem mattis cursus. Vestibulum magna neque, bibendum vel nibh et, tincidunt rhoncus nisi. Duis pulvinar mi a quam rutrum maximus. Nunc sollicitudin, urna in cursus facilisis, augue neque imperdiet metus, ac finibus lorem ante id nulla. Sed maximus eleifend justo id feugiat. Cras eget diam vel est blandit tempor nec a leo. Mauris risus est, fringilla in aliquam a, sagittis vel enim. Nullam sodales id erat placerat lobortis. -% Merge Novel Document: Scene 1.3 [New] +% Merge Novel Scene: Scene 1.3 [New] ### Scene 1.3 diff --git a/tests/reference/coreIndex_LoadSave_tagsIndex.json b/tests/reference/coreIndex_LoadSave_tagsIndex.json index 60c59d86..cba693dc 100644 --- a/tests/reference/coreIndex_LoadSave_tagsIndex.json +++ b/tests/reference/coreIndex_LoadSave_tagsIndex.json @@ -6,31 +6,26 @@ }, "itemIndex": { "7a992350f3eb6": { - "level": "H1", "headings": { "T000001": {"level": "H1", "title": "Lorem Ipsum", "tag": "", "cCount": 230, "wCount": 40, "pCount": 3, "synopsis": ""} } }, "8c58a65414c23": { - "level": "H0", "headings": { "T000000": {"level": "H0", "title": "", "tag": "", "cCount": 1058, "wCount": 176, "pCount": 2, "synopsis": ""} } }, "88d59a277361b": { - "level": "H2", "headings": { "T000001": {"level": "H2", "title": "Prologue", "tag": "", "cCount": 584, "wCount": 92, "pCount": 1, "synopsis": "Explanation from the lipsum.com website."} } }, "db7e733775d4d": { - "level": "H1", "headings": { "T000001": {"level": "H1", "title": "Act One", "tag": "", "cCount": 35, "wCount": 6, "pCount": 1, "synopsis": ""} } }, "fb609cd8319dc": { - "level": "H2", "headings": { "T000001": {"level": "H2", "title": "Chapter One", "tag": "", "cCount": 419, "wCount": 67, "pCount": 1, "synopsis": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque at aliquam quam."} }, @@ -39,7 +34,6 @@ } }, "88243afbe5ed8": { - "level": "H3", "headings": { "T000001": {"level": "H3", "title": "Scene One", "tag": "", "cCount": 1197, "wCount": 174, "pCount": 2, "synopsis": "Aenean ut placerat velit. Etiam laoreet ullamcorper risus, eget lobortis enim scelerisque non. Suspendisse id maximus nunc, et mollis sapien. Curabitur vel semper sapien, non pulvinar dolor. Etiam finibus nisi vel mi molestie consectetur."}, "T000013": {"level": "H4", "title": "Scene One, Section Two", "tag": "", "cCount": 1561, "wCount": 230, "pCount": 2, "synopsis": ""} @@ -49,7 +43,6 @@ } }, "f96ec11c6a3da": { - "level": "H3", "headings": { "T000001": {"level": "H3", "title": "Scene Two", "tag": "", "cCount": 2034, "wCount": 299, "pCount": 3, "synopsis": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Integer sapien nulla, dictum at lacus a, dignissim consectetur dolor. Nunc vel eleifend lacus, eu dapibus orci."}, "T000015": {"level": "H4", "title": "Scene Two, Section Two", "tag": "", "cCount": 2009, "wCount": 301, "pCount": 3, "synopsis": ""} @@ -59,13 +52,11 @@ } }, "846352075de7d": { - "level": "H2", "headings": { "T000001": {"level": "H2", "title": "Why do we use it?", "tag": "", "cCount": 631, "wCount": 109, "pCount": 3, "synopsis": ""} } }, "441420a886d82": { - "level": "H2", "headings": { "T000001": {"level": "H2", "title": "Chapter Two", "tag": "", "cCount": 477, "wCount": 70, "pCount": 1, "synopsis": "Curabitur a elit posuere, varius ex et, convallis neque. Phasellus sagittis pharetra sem vitae dapibus. Curabitur varius lorem non pulvinar congue."} }, @@ -74,7 +65,6 @@ } }, "eb103bc70c90c": { - "level": "H3", "headings": { "T000001": {"level": "H3", "title": "Scene Three", "tag": "", "cCount": 3006, "wCount": 439, "pCount": 4, "synopsis": "Aenean ut libero ut lectus porttitor rhoncus vel et massa. Nam pretium, nibh et varius vehicula, urna metus blandit eros, euismod pharetra diam diam et libero. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos."} }, @@ -83,7 +73,6 @@ } }, "f8c0562e50f1b": { - "level": "H3", "headings": { "T000001": {"level": "H3", "title": "Scene Four", "tag": "", "cCount": 3839, "wCount": 563, "pCount": 6, "synopsis": "Nam tempor blandit magna laoreet aliquet. Vestibulum auctor posuere leo, ac gravida nisi rhoncus varius. Aenean posuere dolor vitae condimentum volutpat. Donec egestas volutpat risus, quis luctus justo."} }, @@ -92,7 +81,6 @@ } }, "47666c91c7ccf": { - "level": "H3", "headings": { "T000001": {"level": "H3", "title": "Scene Five", "tag": "", "cCount": 3644, "wCount": 543, "pCount": 5, "synopsis": "Praesent eget est porta, dictum ante in, egestas risus. Mauris risus mauris, consequat aliquam mauris et, feugiat iaculis ipsum. Aliquam arcu ipsum, fermentum ut arcu sed, lobortis euismod sem. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus."} }, @@ -101,7 +89,6 @@ } }, "4c4f28287af27": { - "level": "H1", "headings": { "T000001": {"level": "H1", "title": "Nobody Owens", "tag": "Bod", "cCount": 1864, "wCount": 284, "pCount": 3, "synopsis": ""} }, @@ -110,13 +97,11 @@ } }, "2426c6f0ca922": { - "level": "H1", "headings": { "T000001": {"level": "H1", "title": "Main Plot", "tag": "Main", "cCount": 1369, "wCount": 195, "pCount": 2, "synopsis": ""} } }, "04468803b92e1": { - "level": "H1", "headings": { "T000001": {"level": "H1", "title": "Ancient Europe", "tag": "Europe", "cCount": 1770, "wCount": 259, "pCount": 3, "synopsis": ""} } diff --git a/tests/reference/coreProject_NewCustomA_nwProject.nwx b/tests/reference/coreProject_NewCustomA_nwProject.nwx index 48ae6363..c61b7f3f 100644 --- a/tests/reference/coreProject_NewCustomA_nwProject.nwx +++ b/tests/reference/coreProject_NewCustomA_nwProject.nwx @@ -1,5 +1,5 @@ - + Test Custom Test Novel @@ -48,55 +48,55 @@ Novel - + Title Page - + Chapter 1 - + Scene 1.1 - + Scene 1.2 - + Scene 1.3 - + Chapter 2 - + Scene 2.1 - + Scene 2.2 - + Scene 2.3 - + Chapter 3 - + Scene 3.1 - + Scene 3.2 - + Scene 3.3 @@ -104,7 +104,7 @@ Plot - + Main Plot @@ -112,7 +112,7 @@ Characters - + Protagonist @@ -120,7 +120,7 @@ Locations - + Main Location diff --git a/tests/reference/coreProject_NewCustomB_nwProject.nwx b/tests/reference/coreProject_NewCustomB_nwProject.nwx index 9399dd3f..9bc1bbf0 100644 --- a/tests/reference/coreProject_NewCustomB_nwProject.nwx +++ b/tests/reference/coreProject_NewCustomB_nwProject.nwx @@ -1,5 +1,5 @@ - + Test Custom Test Novel @@ -48,31 +48,31 @@ Novel - + Title Page - + Scene 1 - + Scene 2 - + Scene 3 - + Scene 4 - + Scene 5 - + Scene 6 @@ -80,7 +80,7 @@ Plot - + Main Plot @@ -88,7 +88,7 @@ Characters - + Protagonist @@ -96,7 +96,7 @@ Locations - + Main Location diff --git a/tests/reference/coreProject_NewFileFolder_nwProject.nwx b/tests/reference/coreProject_NewFileFolder_nwProject.nwx index c0ec400a..94655075 100644 --- a/tests/reference/coreProject_NewFileFolder_nwProject.nwx +++ b/tests/reference/coreProject_NewFileFolder_nwProject.nwx @@ -1,5 +1,5 @@ - + New Project New Novel @@ -17,8 +17,8 @@ None None None - 4 - 1 + 13 + 10 3 @@ -59,7 +59,7 @@ World - + Title Page @@ -67,11 +67,11 @@ New Chapter - + New Chapter - + New Scene @@ -79,11 +79,11 @@ Stuff - + Hello - + Jane diff --git a/tests/reference/coreProject_NewMinimal_nwProject.nwx b/tests/reference/coreProject_NewMinimal_nwProject.nwx index 633f9f4c..08a5d568 100644 --- a/tests/reference/coreProject_NewMinimal_nwProject.nwx +++ b/tests/reference/coreProject_NewMinimal_nwProject.nwx @@ -1,5 +1,5 @@ - + New Project @@ -46,15 +46,15 @@ Novel - + Title Page - + New Chapter - + New Scene diff --git a/tests/reference/coreProject_NewRoot_nwProject.nwx b/tests/reference/coreProject_NewRoot_nwProject.nwx index 3e372adb..24be3ad5 100644 --- a/tests/reference/coreProject_NewRoot_nwProject.nwx +++ b/tests/reference/coreProject_NewRoot_nwProject.nwx @@ -1,5 +1,5 @@ - + New Project New Novel @@ -17,8 +17,8 @@ None None None - 0 - 0 + 9 + 9 0 @@ -59,7 +59,7 @@ World - + Title Page @@ -67,11 +67,11 @@ New Chapter - + New Chapter - + New Scene diff --git a/tests/reference/guiEditor_Main_Final_nwProject.nwx b/tests/reference/guiEditor_Main_Final_nwProject.nwx index 84e7e999..1f8718b2 100644 --- a/tests/reference/guiEditor_Main_Final_nwProject.nwx +++ b/tests/reference/guiEditor_Main_Final_nwProject.nwx @@ -1,12 +1,12 @@ - + New Project New Novel Jane Doe 4 2 - 5 + 4 True @@ -47,7 +47,7 @@ Novel - + Title Page @@ -55,11 +55,11 @@ New Chapter - + New Chapter - + New Scene @@ -67,7 +67,7 @@ Plot - + New Note @@ -75,7 +75,7 @@ Characters - + New Note @@ -83,7 +83,7 @@ World - + New Note diff --git a/tests/reference/guiEditor_Main_Initial_nwProject.nwx b/tests/reference/guiEditor_Main_Initial_nwProject.nwx index 0563c440..2ee65716 100644 --- a/tests/reference/guiEditor_Main_Initial_nwProject.nwx +++ b/tests/reference/guiEditor_Main_Initial_nwProject.nwx @@ -1,5 +1,5 @@ - + New Project New Novel @@ -47,7 +47,7 @@ Novel - + Title Page @@ -55,11 +55,11 @@ New Chapter - + New Chapter - + New Scene diff --git a/tests/reference/guiProjSettings_Dialog_nwProject.nwx b/tests/reference/guiProjSettings_Dialog_nwProject.nwx index 1db9d48c..cff9285d 100644 --- a/tests/reference/guiProjSettings_Dialog_nwProject.nwx +++ b/tests/reference/guiProjSettings_Dialog_nwProject.nwx @@ -1,5 +1,5 @@ - + Project Name Project Title @@ -52,7 +52,7 @@ Novel - + Title Page @@ -60,11 +60,11 @@ New Chapter - + New Chapter - + New Scene diff --git a/tests/test_core/test_core_index.py b/tests/test_core/test_core_index.py index e2eeaa93..0d3518c6 100644 --- a/tests/test_core/test_core_index.py +++ b/tests/test_core/test_core_index.py @@ -26,7 +26,7 @@ import pytest from shutil import copyfile from mock import causeException -from tools import buildTestProject, cmpFiles, writeFile +from tools import C, buildTestProject, cmpFiles, writeFile from novelwriter.enum import nwItemClass, nwItemLayout from novelwriter.core.index import NWIndex, countWords, TagsIndex @@ -189,15 +189,17 @@ def testCoreIndex_CheckThese(mockGUI, fncDir, mockRnd): """Test the tag checker function checkThese. """ theProject = NWProject(mockGUI) + mockRnd.reset() buildTestProject(theProject, fncDir) theIndex = theProject.index + theIndex.clearIndex() - nHandle = theProject.newFile("Hello", "0000000000010") - cHandle = theProject.newFile("Jane", "0000000000012") + nHandle = theProject.newFile("Hello", C.hNovelRoot) + cHandle = theProject.newFile("Jane", C.hCharRoot) nItem = theProject.tree[nHandle] cItem = theProject.tree[cHandle] - assert theIndex.rootChangedSince("0000000000010", 0) is False + assert theIndex.rootChangedSince(C.hNovelRoot, 0) is False assert theIndex.indexChangedSince(0) is False assert theIndex.scanText(cHandle, ( @@ -227,11 +229,11 @@ def testCoreIndex_CheckThese(mockGUI, fncDir, mockRnd): "@time": [] } - assert theIndex.rootChangedSince("0000000000010", 0) is True + assert theIndex.rootChangedSince(C.hNovelRoot, 0) is True assert theIndex.indexChangedSince(0) is True - assert theIndex.getHandleHeaderLevel(cHandle) == "H1" - assert theIndex.getHandleHeaderLevel(nHandle) == "H1" + assert cItem.mainHeading == "H1" + assert nItem.mainHeading == "H1" # Zero Items assert theIndex.checkThese([], cItem) == [] @@ -265,12 +267,13 @@ def testCoreIndex_ScanText(mockGUI, fncDir, mockRnd): """Check the index text scanner. """ theProject = NWProject(mockGUI) + mockRnd.reset() buildTestProject(theProject, fncDir) theIndex = theProject.index # Some items for fail to scan tests - dHandle = theProject.newFolder("Folder", "0000000000010") - xHandle = theProject.newFile("No Layout", "0000000000010") + dHandle = theProject.newFolder("Folder", C.hNovelRoot) + xHandle = theProject.newFile("No Layout", C.hNovelRoot) xItem = theProject.tree[xHandle] xItem.setLayout(nwItemLayout.NO_LAYOUT) @@ -290,21 +293,23 @@ def testCoreIndex_ScanText(mockGUI, fncDir, mockRnd): theProject.tree.updateItemData(xItem.itemHandle) assert xItem.itemRoot == tHandle assert xItem.itemClass == nwItemClass.TRASH - assert theIndex.scanText(xHandle, "Hello World!") is False + assert theIndex.scanText(xHandle, "## Hello World!") is True + assert xItem.mainHeading == "H2" # Create the archive root aHandle = theProject.newRoot(nwItemClass.ARCHIVE) assert theProject.tree[aHandle] is not None xItem.setParent(aHandle) theProject.tree.updateItemData(xItem.itemHandle) - assert theIndex.scanText(xHandle, "Hello World!") is False + assert theIndex.scanText(xHandle, "### Hello World!") is True + assert xItem.mainHeading == "H3" # Make some usable items - tHandle = theProject.newFile("Title", "0000000000010") - pHandle = theProject.newFile("Page", "0000000000010") - nHandle = theProject.newFile("Hello", "0000000000010") - cHandle = theProject.newFile("Jane", "0000000000012") - sHandle = theProject.newFile("Scene", "0000000000010") + tHandle = theProject.newFile("Title", C.hNovelRoot) + pHandle = theProject.newFile("Page", C.hNovelRoot) + nHandle = theProject.newFile("Hello", C.hNovelRoot) + cHandle = theProject.newFile("Jane", C.hCharRoot) + sHandle = theProject.newFile("Scene", C.hNovelRoot) # Text Indexing # ============= @@ -474,23 +479,24 @@ def testCoreIndex_ExtractData(mockGUI, fncDir, mockRnd): """Check the index data extraction functions. """ theProject = NWProject(mockGUI) + mockRnd.reset() buildTestProject(theProject, fncDir) theIndex = theProject.index - theIndex.reIndexHandle("0000000000010") - theIndex.reIndexHandle("0000000000011") - theIndex.reIndexHandle("0000000000012") - theIndex.reIndexHandle("0000000000013") - theIndex.reIndexHandle("0000000000014") - theIndex.reIndexHandle("0000000000015") - theIndex.reIndexHandle("0000000000016") - theIndex.reIndexHandle("0000000000017") + theIndex.reIndexHandle(C.hNovelRoot) + theIndex.reIndexHandle(C.hPlotRoot) + theIndex.reIndexHandle(C.hCharRoot) + theIndex.reIndexHandle(C.hWorldRoot) + theIndex.reIndexHandle(C.hTitlePage) + theIndex.reIndexHandle(C.hChapterDir) + theIndex.reIndexHandle(C.hChapterDoc) + theIndex.reIndexHandle(C.hSceneDoc) - nHandle = theProject.newFile("Hello", "0000000000010") - cHandle = theProject.newFile("Jane", "0000000000012") + nHandle = theProject.newFile("Hello", C.hNovelRoot) + cHandle = theProject.newFile("Jane", C.hCharRoot) assert theIndex.getNovelData("", "") is None - assert theIndex.getNovelData("0000000000010", "") is None + assert theIndex.getNovelData(C.hNovelRoot, "") is None assert theIndex.scanText(cHandle, ( "# Jane Smith\n" @@ -511,10 +517,10 @@ def testCoreIndex_ExtractData(mockGUI, fncDir, mockRnd): theKeys.append(aKey) assert theKeys == [ - "0000000000014:T000001", - "0000000000016:T000001", - "0000000000017:T000001", - "%s:T000001" % nHandle, + f"{C.hTitlePage}:T000001", + f"{C.hChapterDoc}:T000001", + f"{C.hSceneDoc}:T000001", + f"{nHandle}:T000001", ] # Check that excluded files can be skipped @@ -525,10 +531,10 @@ def testCoreIndex_ExtractData(mockGUI, fncDir, mockRnd): theKeys.append(aKey) assert theKeys == [ - "0000000000014:T000001", - "0000000000016:T000001", - "0000000000017:T000001", - "%s:T000001" % nHandle, + f"{C.hTitlePage}:T000001", + f"{C.hChapterDoc}:T000001", + f"{C.hSceneDoc}:T000001", + f"{nHandle}:T000001", ] theKeys = [] @@ -536,9 +542,9 @@ def testCoreIndex_ExtractData(mockGUI, fncDir, mockRnd): theKeys.append(aKey) assert theKeys == [ - "0000000000014:T000001", - "0000000000016:T000001", - "0000000000017:T000001", + f"{C.hTitlePage}:T000001", + f"{C.hChapterDoc}:T000001", + f"{C.hSceneDoc}:T000001", ] # The novel file should have the correct counts @@ -567,7 +573,7 @@ def testCoreIndex_ExtractData(mockGUI, fncDir, mockRnd): assert theIndex.getBackReferenceList(None) == {} # The Title Page file should have no references as it has no tag - assert theIndex.getBackReferenceList("0000000000014") == {} + assert theIndex.getBackReferenceList(C.hTitlePage) == {} # The character file should have a record of the reference from the novel file theRefs = theIndex.getBackReferenceList(cHandle) @@ -656,9 +662,9 @@ def testCoreIndex_ExtractData(mockGUI, fncDir, mockRnd): # Novel Stats # =========== - hHandle = theProject.newFile("Chapter", "0000000000010") - sHandle = theProject.newFile("Scene One", "0000000000010") - tHandle = theProject.newFile("Scene Two", "0000000000010") + hHandle = theProject.newFile("Chapter", C.hNovelRoot) + sHandle = theProject.newFile("Scene One", C.hNovelRoot) + tHandle = theProject.newFile("Scene Two", C.hNovelRoot) theProject.tree[hHandle].itemLayout == nwItemLayout.DOCUMENT theProject.tree[sHandle].itemLayout == nwItemLayout.DOCUMENT @@ -669,9 +675,9 @@ def testCoreIndex_ExtractData(mockGUI, fncDir, mockRnd): assert theIndex.scanText(tHandle, "### Scene Two\n\n") assert [(h, t) for h, t, _ in theIndex._itemIndex.iterNovelStructure(skipExcl=False)] == [ - ("0000000000014", "T000001"), - ("0000000000016", "T000001"), - ("0000000000017", "T000001"), + (C.hTitlePage, "T000001"), + (C.hChapterDoc, "T000001"), + (C.hSceneDoc, "T000001"), (nHandle, "T000001"), (nHandle, "T000011"), (hHandle, "T000001"), @@ -680,9 +686,9 @@ def testCoreIndex_ExtractData(mockGUI, fncDir, mockRnd): ] assert [(h, t) for h, t, _ in theIndex._itemIndex.iterNovelStructure(skipExcl=True)] == [ - ("0000000000014", "T000001"), - ("0000000000016", "T000001"), - ("0000000000017", "T000001"), + (C.hTitlePage, "T000001"), + (C.hChapterDoc, "T000001"), + (C.hSceneDoc, "T000001"), (hHandle, "T000001"), (sHandle, "T000001"), (tHandle, "T000001"), @@ -691,9 +697,9 @@ def testCoreIndex_ExtractData(mockGUI, fncDir, mockRnd): # Add a fake handle to the tree and check that it's ignored theProject.tree._treeOrder.append("0000000000000") assert [(h, t) for h, t, _ in theIndex._itemIndex.iterNovelStructure(skipExcl=False)] == [ - ("0000000000014", "T000001"), - ("0000000000016", "T000001"), - ("0000000000017", "T000001"), + (C.hTitlePage, "T000001"), + (C.hChapterDoc, "T000001"), + (C.hSceneDoc, "T000001"), (nHandle, "T000001"), (nHandle, "T000011"), (hHandle, "T000001"), @@ -709,29 +715,29 @@ def testCoreIndex_ExtractData(mockGUI, fncDir, mockRnd): assert theIndex.getNovelTitleCounts(skipExcl=True) == [0, 1, 2, 3, 0] # Table of Contents - assert theIndex.getTableOfContents("0000000000010", 0, skipExcl=True) == [] - assert theIndex.getTableOfContents("0000000000010", 1, skipExcl=True) == [ - ("0000000000014:T000001", 1, "New Novel", 15), + assert theIndex.getTableOfContents(C.hNovelRoot, 0, skipExcl=True) == [] + assert theIndex.getTableOfContents(C.hNovelRoot, 1, skipExcl=True) == [ + (f"{C.hTitlePage}:T000001", 1, "New Novel", 15), ] - assert theIndex.getTableOfContents("0000000000010", 2, skipExcl=True) == [ - ("0000000000014:T000001", 1, "New Novel", 5), - ("0000000000016:T000001", 2, "New Chapter", 4), - ("%s:T000001" % hHandle, 2, "Chapter One", 6), + assert theIndex.getTableOfContents(C.hNovelRoot, 2, skipExcl=True) == [ + (f"{C.hTitlePage}:T000001", 1, "New Novel", 5), + (f"{C.hChapterDoc}:T000001", 2, "New Chapter", 4), + (f"{hHandle}:T000001", 2, "Chapter One", 6), ] - assert theIndex.getTableOfContents("0000000000010", 3, skipExcl=True) == [ - ("0000000000014:T000001", 1, "New Novel", 5), - ("0000000000016:T000001", 2, "New Chapter", 2), - ("0000000000017:T000001", 3, "New Scene", 2), - ("%s:T000001" % hHandle, 2, "Chapter One", 2), - ("%s:T000001" % sHandle, 3, "Scene One", 2), - ("%s:T000001" % tHandle, 3, "Scene Two", 2), + assert theIndex.getTableOfContents(C.hNovelRoot, 3, skipExcl=True) == [ + (f"{C.hTitlePage}:T000001", 1, "New Novel", 5), + (f"{C.hChapterDoc}:T000001", 2, "New Chapter", 2), + (f"{C.hSceneDoc}:T000001", 3, "New Scene", 2), + (f"{hHandle}:T000001", 2, "Chapter One", 2), + (f"{sHandle}:T000001", 3, "Scene One", 2), + (f"{tHandle}:T000001", 3, "Scene Two", 2), ] - assert theIndex.getTableOfContents("0000000000010", 0, skipExcl=False) == [] - assert theIndex.getTableOfContents("0000000000010", 1, skipExcl=False) == [ - ("0000000000014:T000001", 1, "New Novel", 9), - ("%s:T000001" % nHandle, 1, "Hello World!", 12), - ("%s:T000011" % nHandle, 1, "Hello World!", 22), + assert theIndex.getTableOfContents(C.hNovelRoot, 0, skipExcl=False) == [] + assert theIndex.getTableOfContents(C.hNovelRoot, 1, skipExcl=False) == [ + (f"{C.hTitlePage}:T000001", 1, "New Novel", 9), + (f"{nHandle}:T000001", 1, "Hello World!", 12), + (f"{nHandle}:T000011", 1, "Hello World!", 22), ] # Header Word Counts @@ -741,7 +747,7 @@ def testCoreIndex_ExtractData(mockGUI, fncDir, mockRnd): assert theIndex.getHandleWordCounts(sHandle) == [("%s:T000001" % sHandle, 2)] assert theIndex.getHandleWordCounts(tHandle) == [("%s:T000001" % tHandle, 2)] assert theIndex.getHandleWordCounts(nHandle) == [ - ("%s:T000001" % nHandle, 12), ("%s:T000011" % nHandle, 16) + (f"{nHandle}:T000001", 12), (f"{nHandle}:T000011", 16) ] assert theIndex.saveIndex() is True @@ -926,11 +932,13 @@ def testCoreIndex_ItemIndex(mockGUI, fncDir, mockRnd): """Check the ItemIndex class. """ theProject = NWProject(mockGUI) + mockRnd.reset() buildTestProject(theProject, fncDir) + theProject.index.clearIndex() - nHandle = "0000000000014" - cHandle = "0000000000016" - sHandle = "0000000000017" + nHandle = C.hTitlePage + cHandle = C.hChapterDoc + sHandle = C.hSceneDoc assert theProject.index.saveIndex() is True itemIndex = theProject.index._itemIndex @@ -948,13 +956,11 @@ def testCoreIndex_ItemIndex(mockGUI, fncDir, mockRnd): itemIndex.add(cHandle, theProject.tree[cHandle]) assert cHandle in itemIndex assert itemIndex[cHandle].item == theProject.tree[cHandle] - assert itemIndex.mainItemHeader(cHandle) == "H0" assert itemIndex.allItemTags(cHandle) == [] assert list(itemIndex.iterItemHeaders(cHandle))[0][0] == "T000000" # Add a heading to the item, which should replace the T000000 heading itemIndex.addItemHeading(cHandle, "T000001", "H2", "Chapter One") - assert itemIndex.mainItemHeader(cHandle) == "H2" assert list(itemIndex.iterItemHeaders(cHandle))[0][0] == "T000001" # Set the remainig data values @@ -966,7 +972,6 @@ def testCoreIndex_ItemIndex(mockGUI, fncDir, mockRnd): itemIndex.addHeadingReferences(cHandle, "T000001", ["Jane", "John"], "@char") idxData = itemIndex.packData() - assert idxData[cHandle]["level"] == "H2" assert idxData[cHandle]["headings"]["T000001"] == { "level": "H2", "title": "Chapter One", "tag": "One", "cCount": 60, "wCount": 10, "pCount": 2, "synopsis": "In the beginning ...", @@ -1026,7 +1031,6 @@ def testCoreIndex_ItemIndex(mockGUI, fncDir, mockRnd): assert allHeads[2][1] == "T000001" # Ask for stuff that doesn't exist - assert itemIndex.mainItemHeader("blablabla") == "H0" assert itemIndex.allItemTags("blablabla") == [] # Novel Structure @@ -1048,7 +1052,7 @@ def testCoreIndex_ItemIndex(mockGUI, fncDir, mockRnd): assert nStruct[3][0] == uHandle # Novel structure with root handle set - nStruct = list(itemIndex.iterNovelStructure(rootHandle="0000000000010")) + nStruct = list(itemIndex.iterNovelStructure(rootHandle=C.hNovelRoot)) assert len(nStruct) == 3 assert nStruct[0][0] == nHandle assert nStruct[1][0] == cHandle @@ -1098,7 +1102,7 @@ def testCoreIndex_ItemIndex(mockGUI, fncDir, mockRnd): itemIndex.unpackData({"stuff": "more stuff"}) # Unknown keys should be skipped - itemIndex.unpackData({"0000000000000": {}}) + itemIndex.unpackData({C.hInvalid: {}}) assert itemIndex._items == {} # Known keys can be added, even witout data diff --git a/tests/test_core/test_core_item.py b/tests/test_core/test_core_item.py index c0b92591..bd166b47 100644 --- a/tests/test_core/test_core_item.py +++ b/tests/test_core/test_core_item.py @@ -213,13 +213,34 @@ def testCoreItem_Methods(mockGUI): theItem.setLayout("DOCUMENT") assert theItem.isFileType() is True assert theItem.isDocumentLayout() is True + + theItem.setMainHeading("HH") + assert theItem.mainHeading == "H0" assert theItem.describeMe() == "Novel Document" - assert theItem.describeMe("H0") == "Novel Document" - assert theItem.describeMe("H1") == "Novel Title Page" - assert theItem.describeMe("H2") == "Novel Chapter" - assert theItem.describeMe("H3") == "Novel Scene" - assert theItem.describeMe("H4") == "Novel Section" - assert theItem.describeMe("H5") == "Novel Document" + + theItem.setMainHeading("H0") + assert theItem.mainHeading == "H0" + assert theItem.describeMe() == "Novel Document" + + theItem.setMainHeading("H1") + assert theItem.mainHeading == "H1" + assert theItem.describeMe() == "Novel Title Page" + + theItem.setMainHeading("H2") + assert theItem.mainHeading == "H2" + assert theItem.describeMe() == "Novel Chapter" + + theItem.setMainHeading("H3") + assert theItem.mainHeading == "H3" + assert theItem.describeMe() == "Novel Scene" + + theItem.setMainHeading("H4") + assert theItem.mainHeading == "H4" + assert theItem.describeMe() == "Novel Section" + + theItem.setMainHeading("H5") + assert theItem.mainHeading == "H4" + assert theItem.describeMe() == "Novel Section" theItem.setLayout("NOTE") assert theItem.isNoteLayout() is True @@ -504,9 +525,9 @@ def testCoreItem_XMLPackUnpack(mockGUI, caplog, mockRnd): assert etree.tostring(xContent, pretty_print=False, encoding="utf-8") == ( b'' b'A Name' + b'type="FILE" class="NOVEL" layout="NOTE">A Name' b'' ) % bytes(importKeys[3], encoding="utf8") diff --git a/tests/test_core/test_core_tree.py b/tests/test_core/test_core_tree.py index cfdefe70..c3c20d34 100644 --- a/tests/test_core/test_core_tree.py +++ b/tests/test_core/test_core_tree.py @@ -420,13 +420,13 @@ def testCoreTree_XMLPackUnpack(mockGUI, mockItems): b'type="FOLDER" class="NOVEL">Act One' b'Chapter One' + b'type="FILE" class="NOVEL" layout="DOCUMENT">Chapter One' b'Scene One' + b'type="FILE" class="NOVEL" layout="DOCUMENT">Scene One' b'Outtakes' @@ -437,9 +437,9 @@ def testCoreTree_XMLPackUnpack(mockGUI, mockItems): b'class="CHARACTER">Characters' b'Jane Doe' + b'type="FILE" class="CHARACTER" layout="NOTE">Jane Doe' b'' b'' ) diff --git a/tests/tools.py b/tests/tools.py index 5c126707..4744d472 100644 --- a/tests/tools.py +++ b/tests/tools.py @@ -173,13 +173,16 @@ def buildTestProject(theObject, projPath): xHandle[8] = theProject.newFile("New Scene", xHandle[6]) aDoc = NWDoc(theProject, xHandle[5]) - aDoc.writeDocument("#! New Novel\n\n>> By Jane DOe <<\n") + aDoc.writeDocument("#! New Novel\n\n>> By Jane Doe <<\n") + theProject.index.reIndexHandle(xHandle[5]) aDoc = NWDoc(theProject, xHandle[7]) aDoc.writeDocument("## %s\n\n" % theProject.tr("New Chapter")) + theProject.index.reIndexHandle(xHandle[7]) aDoc = NWDoc(theProject, xHandle[8]) aDoc.writeDocument("### %s\n\n" % theProject.tr("New Scene")) + theProject.index.reIndexHandle(xHandle[8]) theProject.projOpened = time.time() theProject.setProjectChanged(True) @@ -188,6 +191,5 @@ def buildTestProject(theObject, projPath): if theGUI is not None: theGUI.hasProject = True theGUI.rebuildTrees() - theGUI.rebuildIndex(beQuiet=True) return