diff --git a/novelwriter/core/index.py b/novelwriter/core/index.py index e2152ba3..6005b280 100644 --- a/novelwriter/core/index.py +++ b/novelwriter/core/index.py @@ -480,16 +480,6 @@ class NWIndex: # Extract Data ## - def novelStructure(self, rootHandle=None, skipExcl=True): - """Iterate over all titles in the novel, in the correct order as - they appear in the tree view and in the respective document - files, but skipping all note files. - """ - novStruct = self._itemIndex.iterNovelStructure(rootHandle=rootHandle, skipExcl=skipExcl) - for tHandle, sTitle, hItem in novStruct: - yield f"{tHandle}:{sTitle}", tHandle, sTitle, hItem - return - def getItemData(self, tHandle): """Get the index data for a given item. """ @@ -503,6 +493,16 @@ class NWIndex: return tItem[sTitle] return None + def novelStructure(self, rootHandle=None, skipExcl=True): + """Iterate over all titles in the novel, in the correct order as + they appear in the tree view and in the respective document + files, but skipping all note files. + """ + novStruct = self._itemIndex.iterNovelStructure(rootHandle=rootHandle, skipExcl=skipExcl) + for tHandle, sTitle, hItem in novStruct: + yield f"{tHandle}:{sTitle}", tHandle, sTitle, hItem + return + def getNovelWordCount(self, skipExcl=True): """Count the number of words in the novel project. """ @@ -600,13 +600,6 @@ class NWIndex: return theRefs - def getNovelData(self, tHandle, sTitle): - """Return the novel data of a given handle and title. - """ - if tHandle in self._itemIndex: - return self._itemIndex[tHandle][sTitle] - return None - def getBackReferenceList(self, tHandle): """Build a list of files referring back to our file, specified by tHandle. diff --git a/novelwriter/gui/noveltree.py b/novelwriter/gui/noveltree.py index bd796db7..654dec2c 100644 --- a/novelwriter/gui/noveltree.py +++ b/novelwriter/gui/noveltree.py @@ -729,7 +729,7 @@ class GuiNovelTree(QTreeWidget): logger.debug("Generating meta data tooltip for '%s:%s'", tHandle, sTitle) pIndex = self.theProject.index - novIdx = pIndex.getNovelData(tHandle, sTitle) + novIdx = pIndex.getItemHeader(tHandle, sTitle) refTags = pIndex.getReferences(tHandle, sTitle) synopText = novIdx.synopsis diff --git a/novelwriter/gui/outline.py b/novelwriter/gui/outline.py index dd0bb3d2..bc2763d7 100644 --- a/novelwriter/gui/outline.py +++ b/novelwriter/gui/outline.py @@ -1049,7 +1049,7 @@ class GuiOutlineDetails(QScrollArea): """ pIndex = self.theProject.index nwItem = self.theProject.tree[tHandle] - novIdx = pIndex.getNovelData(tHandle, sTitle) + novIdx = pIndex.getItemHeader(tHandle, sTitle) theRefs = pIndex.getReferences(tHandle, sTitle) if nwItem is None or novIdx is None: return False diff --git a/tests/reference/coreIndex_LoadSave_tagsIndex.json b/tests/reference/coreIndex_LoadSave_tagsIndex.json index cba693dc..738e7916 100644 --- a/tests/reference/coreIndex_LoadSave_tagsIndex.json +++ b/tests/reference/coreIndex_LoadSave_tagsIndex.json @@ -1,109 +1,109 @@ { "tagsIndex": { - "Bod": {"handle": "4c4f28287af27", "heading": "T000001", "class": "CHARACTER"}, - "Main": {"handle": "2426c6f0ca922", "heading": "T000001", "class": "PLOT"}, - "Europe": {"handle": "04468803b92e1", "heading": "T000001", "class": "WORLD"} + "Bod": {"handle": "4c4f28287af27", "heading": "T0001", "class": "CHARACTER"}, + "Main": {"handle": "2426c6f0ca922", "heading": "T0001", "class": "PLOT"}, + "Europe": {"handle": "04468803b92e1", "heading": "T0001", "class": "WORLD"} }, "itemIndex": { "7a992350f3eb6": { "headings": { - "T000001": {"level": "H1", "title": "Lorem Ipsum", "tag": "", "cCount": 230, "wCount": 40, "pCount": 3, "synopsis": ""} + "T0001": {"level": "H1", "title": "Lorem Ipsum", "line": 1, "tag": "", "cCount": 230, "wCount": 40, "pCount": 3, "synopsis": ""} } }, "8c58a65414c23": { "headings": { - "T000000": {"level": "H0", "title": "", "tag": "", "cCount": 1058, "wCount": 176, "pCount": 2, "synopsis": ""} + "T0000": {"level": "H0", "title": "", "line": 0, "tag": "", "cCount": 1058, "wCount": 176, "pCount": 2, "synopsis": ""} } }, "88d59a277361b": { "headings": { - "T000001": {"level": "H2", "title": "Prologue", "tag": "", "cCount": 584, "wCount": 92, "pCount": 1, "synopsis": "Explanation from the lipsum.com website."} + "T0001": {"level": "H2", "title": "Prologue", "line": 1, "tag": "", "cCount": 584, "wCount": 92, "pCount": 1, "synopsis": "Explanation from the lipsum.com website."} } }, "db7e733775d4d": { "headings": { - "T000001": {"level": "H1", "title": "Act One", "tag": "", "cCount": 35, "wCount": 6, "pCount": 1, "synopsis": ""} + "T0001": {"level": "H1", "title": "Act One", "line": 1, "tag": "", "cCount": 35, "wCount": 6, "pCount": 1, "synopsis": ""} } }, "fb609cd8319dc": { "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."} + "T0001": {"level": "H2", "title": "Chapter One", "line": 1, "tag": "", "cCount": 419, "wCount": 67, "pCount": 1, "synopsis": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque at aliquam quam."} }, "references": { - "T000001": {"Bod": "@pov", "Main": "@plot", "Europe": "@location"} + "T0001": {"Bod": "@pov", "Main": "@plot", "Europe": "@location"} } }, "88243afbe5ed8": { "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": ""} + "T0001": {"level": "H3", "title": "Scene One", "line": 1, "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."}, + "T0002": {"level": "H4", "title": "Scene One, Section Two", "line": 13, "tag": "", "cCount": 1561, "wCount": 230, "pCount": 2, "synopsis": ""} }, "references": { - "T000001": {"Bod": "@pov", "Main": "@plot", "Europe": "@location"} + "T0001": {"Bod": "@pov", "Main": "@plot", "Europe": "@location"} } }, "f96ec11c6a3da": { "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": ""} + "T0001": {"level": "H3", "title": "Scene Two", "line": 1, "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."}, + "T0002": {"level": "H4", "title": "Scene Two, Section Two", "line": 15, "tag": "", "cCount": 2009, "wCount": 301, "pCount": 3, "synopsis": ""} }, "references": { - "T000001": {"Bod": "@pov", "Main": "@plot", "Europe": "@location"} + "T0001": {"Bod": "@pov", "Main": "@plot", "Europe": "@location"} } }, "846352075de7d": { "headings": { - "T000001": {"level": "H2", "title": "Why do we use it?", "tag": "", "cCount": 631, "wCount": 109, "pCount": 3, "synopsis": ""} + "T0001": {"level": "H2", "title": "Why do we use it?", "line": 1, "tag": "", "cCount": 631, "wCount": 109, "pCount": 3, "synopsis": ""} } }, "441420a886d82": { "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."} + "T0001": {"level": "H2", "title": "Chapter Two", "line": 1, "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."} }, "references": { - "T000001": {"Bod": "@pov", "Main": "@plot", "Europe": "@location"} + "T0001": {"Bod": "@pov", "Main": "@plot", "Europe": "@location"} } }, "eb103bc70c90c": { "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."} + "T0001": {"level": "H3", "title": "Scene Three", "line": 1, "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."} }, "references": { - "T000001": {"Bod": "@pov", "Main": "@plot", "Europe": "@location"} + "T0001": {"Bod": "@pov", "Main": "@plot", "Europe": "@location"} } }, "f8c0562e50f1b": { "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."} + "T0001": {"level": "H3", "title": "Scene Four", "line": 1, "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."} }, "references": { - "T000001": {"Bod": "@pov", "Main": "@plot", "Europe": "@location"} + "T0001": {"Bod": "@pov", "Main": "@plot", "Europe": "@location"} } }, "47666c91c7ccf": { "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."} + "T0001": {"level": "H3", "title": "Scene Five", "line": 1, "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."} }, "references": { - "T000001": {"Bod": "@pov", "Main": "@plot", "Europe": "@location"} + "T0001": {"Bod": "@pov", "Main": "@plot", "Europe": "@location"} } }, "4c4f28287af27": { "headings": { - "T000001": {"level": "H1", "title": "Nobody Owens", "tag": "Bod", "cCount": 1864, "wCount": 284, "pCount": 3, "synopsis": ""} + "T0001": {"level": "H1", "title": "Nobody Owens", "line": 1, "tag": "Bod", "cCount": 1864, "wCount": 284, "pCount": 3, "synopsis": ""} }, "references": { - "T000001": {"Main": "@plot"} + "T0001": {"Main": "@plot"} } }, "2426c6f0ca922": { "headings": { - "T000001": {"level": "H1", "title": "Main Plot", "tag": "Main", "cCount": 1369, "wCount": 195, "pCount": 2, "synopsis": ""} + "T0001": {"level": "H1", "title": "Main Plot", "line": 1, "tag": "Main", "cCount": 1369, "wCount": 195, "pCount": 2, "synopsis": ""} } }, "04468803b92e1": { "headings": { - "T000001": {"level": "H1", "title": "Ancient Europe", "tag": "Europe", "cCount": 1770, "wCount": 259, "pCount": 3, "synopsis": ""} + "T0001": {"level": "H1", "title": "Ancient Europe", "line": 1, "tag": "Europe", "cCount": 1770, "wCount": 259, "pCount": 3, "synopsis": ""} } } } diff --git a/tests/test_base/test_base_common.py b/tests/test_base/test_base_common.py index e11895dc..a3d9d28e 100644 --- a/tests/test_base/test_base_common.py +++ b/tests/test_base/test_base_common.py @@ -208,12 +208,12 @@ def testBaseCommon_IsHandle(): def testBaseCommon_IsTitleTag(): """Test the isItemClass function. """ - assert isTitleTag("T123456") is True + assert isTitleTag("T1234") is True - assert isTitleTag("t123456") is False - assert isTitleTag("S123456") is False - assert isTitleTag("T12345A") is False - assert isTitleTag("T1234567") is False + assert isTitleTag("t1234") is False + assert isTitleTag("S1234") is False + assert isTitleTag("T123A") is False + assert isTitleTag("T12345") is False assert isTitleTag("None") is False assert isTitleTag(None) is False diff --git a/tests/test_core/test_core_index.py b/tests/test_core/test_core_index.py index 6d85dfb0..644c77cd 100644 --- a/tests/test_core/test_core_index.py +++ b/tests/test_core/test_core_index.py @@ -29,7 +29,7 @@ from tools import C, buildTestProject, cmpFiles, writeFile from novelwriter.enum import nwItemClass, nwItemLayout from novelwriter.constants import nwFiles -from novelwriter.core.index import NWIndex, countWords, TagsIndex +from novelwriter.core.index import IndexItem, NWIndex, countWords, TagsIndex from novelwriter.core.project import NWProject @@ -231,10 +231,10 @@ def testCoreIndex_CheckThese(mockGUI, fncPath, mockRnd): "@invalid: John\n" # Checks for issue #688 )) assert theIndex._tagsIndex.tagHandle("Jane") == cHandle - assert theIndex._tagsIndex.tagHeading("Jane") == "T000001" + assert theIndex._tagsIndex.tagHeading("Jane") == "T0001" assert theIndex._tagsIndex.tagClass("Jane") == "CHARACTER" - assert theIndex.getNovelData(nHandle, "T000001").title == "Hello World!" - assert theIndex.getReferences(nHandle, "T000001") == { + assert theIndex.getItemHeader(nHandle, "T0001").title == "Hello World!" + assert theIndex.getReferences(nHandle, "T0001") == { "@char": [], "@custom": [], "@entity": [], @@ -345,9 +345,9 @@ def testCoreIndex_ScanText(mockGUI, fncPath, mockRnd): "Well, not really.\n" )) assert theIndex._tagsIndex.tagHandle("Jane") == cHandle - assert theIndex._tagsIndex.tagHeading("Jane") == "T000001" + assert theIndex._tagsIndex.tagHeading("Jane") == "T0001" assert theIndex._tagsIndex.tagClass("Jane") == "CHARACTER" - assert theIndex.getNovelData(nHandle, "T000001").title == "Hello World!" + assert theIndex.getItemHeader(nHandle, "T0001").title == "Hello World!" # Title Indexing # ============== @@ -369,40 +369,45 @@ def testCoreIndex_ScanText(mockGUI, fncPath, mockRnd): "##### Title Five\n\n" # Not interpreted as a title, the hashes are counted as a word "Paragraph Five.\n\n" )) - assert theIndex._itemIndex[nHandle]["T000001"].references == {} - assert theIndex._itemIndex[nHandle]["T000007"].references == {} - assert theIndex._itemIndex[nHandle]["T000013"].references == {} - assert theIndex._itemIndex[nHandle]["T000019"].references == {} + assert theIndex._itemIndex[nHandle]["T0001"].references == {} + assert theIndex._itemIndex[nHandle]["T0002"].references == {} + assert theIndex._itemIndex[nHandle]["T0003"].references == {} + assert theIndex._itemIndex[nHandle]["T0004"].references == {} - assert theIndex._itemIndex[nHandle]["T000001"].level == "H1" - assert theIndex._itemIndex[nHandle]["T000007"].level == "H2" - assert theIndex._itemIndex[nHandle]["T000013"].level == "H3" - assert theIndex._itemIndex[nHandle]["T000019"].level == "H4" + assert theIndex._itemIndex[nHandle]["T0001"].level == "H1" + assert theIndex._itemIndex[nHandle]["T0002"].level == "H2" + assert theIndex._itemIndex[nHandle]["T0003"].level == "H3" + assert theIndex._itemIndex[nHandle]["T0004"].level == "H4" - assert theIndex._itemIndex[nHandle]["T000001"].title == "Title One" - assert theIndex._itemIndex[nHandle]["T000007"].title == "Title Two" - assert theIndex._itemIndex[nHandle]["T000013"].title == "Title Three" - assert theIndex._itemIndex[nHandle]["T000019"].title == "Title Four" + assert theIndex._itemIndex[nHandle]["T0001"].line == 1 + assert theIndex._itemIndex[nHandle]["T0002"].line == 7 + assert theIndex._itemIndex[nHandle]["T0003"].line == 13 + assert theIndex._itemIndex[nHandle]["T0004"].line == 19 - assert theIndex._itemIndex[nHandle]["T000001"].charCount == 23 - assert theIndex._itemIndex[nHandle]["T000007"].charCount == 23 - assert theIndex._itemIndex[nHandle]["T000013"].charCount == 27 - assert theIndex._itemIndex[nHandle]["T000019"].charCount == 56 + assert theIndex._itemIndex[nHandle]["T0001"].title == "Title One" + assert theIndex._itemIndex[nHandle]["T0002"].title == "Title Two" + assert theIndex._itemIndex[nHandle]["T0003"].title == "Title Three" + assert theIndex._itemIndex[nHandle]["T0004"].title == "Title Four" - assert theIndex._itemIndex[nHandle]["T000001"].wordCount == 4 - assert theIndex._itemIndex[nHandle]["T000007"].wordCount == 4 - assert theIndex._itemIndex[nHandle]["T000013"].wordCount == 4 - assert theIndex._itemIndex[nHandle]["T000019"].wordCount == 9 + assert theIndex._itemIndex[nHandle]["T0001"].charCount == 23 + assert theIndex._itemIndex[nHandle]["T0002"].charCount == 23 + assert theIndex._itemIndex[nHandle]["T0003"].charCount == 27 + assert theIndex._itemIndex[nHandle]["T0004"].charCount == 56 - assert theIndex._itemIndex[nHandle]["T000001"].paraCount == 1 - assert theIndex._itemIndex[nHandle]["T000007"].paraCount == 1 - assert theIndex._itemIndex[nHandle]["T000013"].paraCount == 1 - assert theIndex._itemIndex[nHandle]["T000019"].paraCount == 3 + assert theIndex._itemIndex[nHandle]["T0001"].wordCount == 4 + assert theIndex._itemIndex[nHandle]["T0002"].wordCount == 4 + assert theIndex._itemIndex[nHandle]["T0003"].wordCount == 4 + assert theIndex._itemIndex[nHandle]["T0004"].wordCount == 9 - assert theIndex._itemIndex[nHandle]["T000001"].synopsis == "Synopsis One." - assert theIndex._itemIndex[nHandle]["T000007"].synopsis == "Synopsis Two." - assert theIndex._itemIndex[nHandle]["T000013"].synopsis == "Synopsis Three." - assert theIndex._itemIndex[nHandle]["T000019"].synopsis == "Synopsis Four." + assert theIndex._itemIndex[nHandle]["T0001"].paraCount == 1 + assert theIndex._itemIndex[nHandle]["T0002"].paraCount == 1 + assert theIndex._itemIndex[nHandle]["T0003"].paraCount == 1 + assert theIndex._itemIndex[nHandle]["T0004"].paraCount == 3 + + assert theIndex._itemIndex[nHandle]["T0001"].synopsis == "Synopsis One." + assert theIndex._itemIndex[nHandle]["T0002"].synopsis == "Synopsis Two." + assert theIndex._itemIndex[nHandle]["T0003"].synopsis == "Synopsis Three." + assert theIndex._itemIndex[nHandle]["T0004"].synopsis == "Synopsis Four." # Note File assert theIndex.scanText(cHandle, ( @@ -411,13 +416,14 @@ def testCoreIndex_ScanText(mockGUI, fncPath, mockRnd): "% synopsis: Synopsis One.\n\n" "Paragraph One.\n\n" )) - assert theIndex._itemIndex[cHandle]["T000001"].references == {} - assert theIndex._itemIndex[cHandle]["T000001"].level == "H1" - assert theIndex._itemIndex[cHandle]["T000001"].title == "Title One" - assert theIndex._itemIndex[cHandle]["T000001"].charCount == 23 - assert theIndex._itemIndex[cHandle]["T000001"].wordCount == 4 - assert theIndex._itemIndex[cHandle]["T000001"].paraCount == 1 - assert theIndex._itemIndex[cHandle]["T000001"].synopsis == "Synopsis One." + assert theIndex._itemIndex[cHandle]["T0001"].references == {} + assert theIndex._itemIndex[cHandle]["T0001"].level == "H1" + assert theIndex._itemIndex[cHandle]["T0001"].line == 1 + assert theIndex._itemIndex[cHandle]["T0001"].title == "Title One" + assert theIndex._itemIndex[cHandle]["T0001"].charCount == 23 + assert theIndex._itemIndex[cHandle]["T0001"].wordCount == 4 + assert theIndex._itemIndex[cHandle]["T0001"].paraCount == 1 + assert theIndex._itemIndex[cHandle]["T0001"].synopsis == "Synopsis One." # Valid and Invalid References assert theIndex.scanText(sHandle, ( @@ -428,7 +434,7 @@ def testCoreIndex_ScanText(mockGUI, fncPath, mockRnd): "% synopsis: Synopsis One.\n\n" "Paragraph One.\n\n" )) - assert theIndex._itemIndex[sHandle]["T000001"].references == { + assert theIndex._itemIndex[sHandle]["T0001"].references == { "One": {"@pov"}, "Two": {"@char"} } @@ -439,25 +445,27 @@ def testCoreIndex_ScanText(mockGUI, fncPath, mockRnd): "#! My Project\n\n" ">> By Jane Doe <<\n\n" )) - assert theIndex._itemIndex[cHandle]["T000001"].references == {} - assert theIndex._itemIndex[tHandle]["T000001"].level == "H1" - assert theIndex._itemIndex[tHandle]["T000001"].title == "My Project" - assert theIndex._itemIndex[tHandle]["T000001"].charCount == 21 - assert theIndex._itemIndex[tHandle]["T000001"].wordCount == 5 - assert theIndex._itemIndex[tHandle]["T000001"].paraCount == 1 - assert theIndex._itemIndex[tHandle]["T000001"].synopsis == "" + assert theIndex._itemIndex[cHandle]["T0001"].references == {} + assert theIndex._itemIndex[tHandle]["T0001"].level == "H1" + assert theIndex._itemIndex[tHandle]["T0001"].line == 1 + assert theIndex._itemIndex[tHandle]["T0001"].title == "My Project" + assert theIndex._itemIndex[tHandle]["T0001"].charCount == 21 + assert theIndex._itemIndex[tHandle]["T0001"].wordCount == 5 + assert theIndex._itemIndex[tHandle]["T0001"].paraCount == 1 + assert theIndex._itemIndex[tHandle]["T0001"].synopsis == "" assert theIndex.scanText(tHandle, ( "##! Prologue\n\n" "In the beginning there was time ...\n\n" )) - assert theIndex._itemIndex[cHandle]["T000001"].references == {} - assert theIndex._itemIndex[tHandle]["T000001"].level == "H2" - assert theIndex._itemIndex[tHandle]["T000001"].title == "Prologue" - assert theIndex._itemIndex[tHandle]["T000001"].charCount == 43 - assert theIndex._itemIndex[tHandle]["T000001"].wordCount == 8 - assert theIndex._itemIndex[tHandle]["T000001"].paraCount == 1 - assert theIndex._itemIndex[tHandle]["T000001"].synopsis == "" + assert theIndex._itemIndex[cHandle]["T0001"].references == {} + assert theIndex._itemIndex[tHandle]["T0001"].level == "H2" + assert theIndex._itemIndex[tHandle]["T0001"].line == 1 + assert theIndex._itemIndex[tHandle]["T0001"].title == "Prologue" + assert theIndex._itemIndex[tHandle]["T0001"].charCount == 43 + assert theIndex._itemIndex[tHandle]["T0001"].wordCount == 8 + assert theIndex._itemIndex[tHandle]["T0001"].paraCount == 1 + assert theIndex._itemIndex[tHandle]["T0001"].synopsis == "" # Page wo/Title # ============= @@ -466,25 +474,27 @@ def testCoreIndex_ScanText(mockGUI, fncPath, mockRnd): assert theIndex.scanText(pHandle, ( "This is a page with some text on it.\n\n" )) - assert theIndex._itemIndex[pHandle]["T000000"].references == {} - assert theIndex._itemIndex[pHandle]["T000000"].level == "H0" - assert theIndex._itemIndex[pHandle]["T000000"].title == "" - assert theIndex._itemIndex[pHandle]["T000000"].charCount == 36 - assert theIndex._itemIndex[pHandle]["T000000"].wordCount == 9 - assert theIndex._itemIndex[pHandle]["T000000"].paraCount == 1 - assert theIndex._itemIndex[pHandle]["T000000"].synopsis == "" + assert theIndex._itemIndex[pHandle]["T0000"].references == {} + assert theIndex._itemIndex[pHandle]["T0000"].level == "H0" + assert theIndex._itemIndex[pHandle]["T0000"].line == 0 + assert theIndex._itemIndex[pHandle]["T0000"].title == "" + assert theIndex._itemIndex[pHandle]["T0000"].charCount == 36 + assert theIndex._itemIndex[pHandle]["T0000"].wordCount == 9 + assert theIndex._itemIndex[pHandle]["T0000"].paraCount == 1 + assert theIndex._itemIndex[pHandle]["T0000"].synopsis == "" theProject.tree[pHandle]._layout = nwItemLayout.NOTE assert theIndex.scanText(pHandle, ( "This is a page with some text on it.\n\n" )) - assert theIndex._itemIndex[pHandle]["T000000"].references == {} - assert theIndex._itemIndex[pHandle]["T000000"].level == "H0" - assert theIndex._itemIndex[pHandle]["T000000"].title == "" - assert theIndex._itemIndex[pHandle]["T000000"].charCount == 36 - assert theIndex._itemIndex[pHandle]["T000000"].wordCount == 9 - assert theIndex._itemIndex[pHandle]["T000000"].paraCount == 1 - assert theIndex._itemIndex[pHandle]["T000000"].synopsis == "" + assert theIndex._itemIndex[pHandle]["T0000"].references == {} + assert theIndex._itemIndex[pHandle]["T0000"].level == "H0" + assert theIndex._itemIndex[pHandle]["T0000"].line == 0 + assert theIndex._itemIndex[pHandle]["T0000"].title == "" + assert theIndex._itemIndex[pHandle]["T0000"].charCount == 36 + assert theIndex._itemIndex[pHandle]["T0000"].wordCount == 9 + assert theIndex._itemIndex[pHandle]["T0000"].paraCount == 1 + assert theIndex._itemIndex[pHandle]["T0000"].synopsis == "" assert theProject.closeProject() is True @@ -512,8 +522,8 @@ def testCoreIndex_ExtractData(mockGUI, fncPath, mockRnd): nHandle = theProject.newFile("Hello", C.hNovelRoot) cHandle = theProject.newFile("Jane", C.hCharRoot) - assert theIndex.getNovelData("", "") is None - assert theIndex.getNovelData(C.hNovelRoot, "") is None + assert theIndex.getItemHeader("", "") is None + assert theIndex.getItemHeader(C.hNovelRoot, "") is None assert theIndex.scanText(cHandle, ( "# Jane Smith\n" @@ -534,10 +544,10 @@ def testCoreIndex_ExtractData(mockGUI, fncPath, mockRnd): theKeys.append(aKey) assert theKeys == [ - f"{C.hTitlePage}:T000001", - f"{C.hChapterDoc}:T000001", - f"{C.hSceneDoc}:T000001", - f"{nHandle}:T000001", + f"{C.hTitlePage}:T0001", + f"{C.hChapterDoc}:T0001", + f"{C.hSceneDoc}:T0001", + f"{nHandle}:T0001", ] # Check that excluded files can be skipped @@ -548,10 +558,10 @@ def testCoreIndex_ExtractData(mockGUI, fncPath, mockRnd): theKeys.append(aKey) assert theKeys == [ - f"{C.hTitlePage}:T000001", - f"{C.hChapterDoc}:T000001", - f"{C.hSceneDoc}:T000001", - f"{nHandle}:T000001", + f"{C.hTitlePage}:T0001", + f"{C.hChapterDoc}:T0001", + f"{C.hSceneDoc}:T0001", + f"{nHandle}:T0001", ] theKeys = [] @@ -559,9 +569,9 @@ def testCoreIndex_ExtractData(mockGUI, fncPath, mockRnd): theKeys.append(aKey) assert theKeys == [ - f"{C.hTitlePage}:T000001", - f"{C.hChapterDoc}:T000001", - f"{C.hSceneDoc}:T000001", + f"{C.hTitlePage}:T0001", + f"{C.hChapterDoc}:T0001", + f"{C.hSceneDoc}:T0001", ] # The novel file should have the correct counts @@ -570,6 +580,13 @@ def testCoreIndex_ExtractData(mockGUI, fncPath, mockRnd): assert wC == 12 # Words in text and title only assert pC == 2 # Paragraphs in text only + # getItemData + # =========== + + theItem = theIndex.getItemData(nHandle) + assert isinstance(theItem, IndexItem) + assert theItem.headings() == ["T0001"] + # getReferences # ============= @@ -594,13 +611,13 @@ def testCoreIndex_ExtractData(mockGUI, fncPath, mockRnd): # The character file should have a record of the reference from the novel file theRefs = theIndex.getBackReferenceList(cHandle) - assert theRefs == {nHandle: "T000001"} + assert theRefs == {nHandle: "T0001"} # getTagSource # ============ - assert theIndex.getTagSource("Jane") == (cHandle, "T000001") - assert theIndex.getTagSource("John") == (None, "T000000") + assert theIndex.getTagSource("Jane") == (cHandle, "T0001") + assert theIndex.getTagSource("John") == (None, "T0000") # getCounts # ========= @@ -632,13 +649,13 @@ def testCoreIndex_ExtractData(mockGUI, fncPath, mockRnd): assert pC == 4 # First part - cC, wC, pC = theIndex.getCounts(nHandle, "T000001") + cC, wC, pC = theIndex.getCounts(nHandle, "T0001") assert cC == 62 assert wC == 12 assert pC == 2 # Second part - cC, wC, pC = theIndex.getCounts(nHandle, "T000011") + cC, wC, pC = theIndex.getCounts(nHandle, "T0002") assert cC == 90 assert wC == 16 assert pC == 2 @@ -665,13 +682,13 @@ def testCoreIndex_ExtractData(mockGUI, fncPath, mockRnd): assert pC == 4 # First part - cC, wC, pC = theIndex.getCounts(cHandle, "T000001") + cC, wC, pC = theIndex.getCounts(cHandle, "T0001") assert cC == 62 assert wC == 12 assert pC == 2 # Second part - cC, wC, pC = theIndex.getCounts(cHandle, "T000011") + cC, wC, pC = theIndex.getCounts(cHandle, "T0002") assert cC == 90 assert wC == 16 assert pC == 2 @@ -692,36 +709,36 @@ def testCoreIndex_ExtractData(mockGUI, fncPath, mockRnd): assert theIndex.scanText(tHandle, "### Scene Two\n\n") assert [(h, t) for h, t, _ in theIndex._itemIndex.iterNovelStructure(skipExcl=False)] == [ - (C.hTitlePage, "T000001"), - (C.hChapterDoc, "T000001"), - (C.hSceneDoc, "T000001"), - (nHandle, "T000001"), - (nHandle, "T000011"), - (hHandle, "T000001"), - (sHandle, "T000001"), - (tHandle, "T000001"), + (C.hTitlePage, "T0001"), + (C.hChapterDoc, "T0001"), + (C.hSceneDoc, "T0001"), + (nHandle, "T0001"), + (nHandle, "T0002"), + (hHandle, "T0001"), + (sHandle, "T0001"), + (tHandle, "T0001"), ] assert [(h, t) for h, t, _ in theIndex._itemIndex.iterNovelStructure(skipExcl=True)] == [ - (C.hTitlePage, "T000001"), - (C.hChapterDoc, "T000001"), - (C.hSceneDoc, "T000001"), - (hHandle, "T000001"), - (sHandle, "T000001"), - (tHandle, "T000001"), + (C.hTitlePage, "T0001"), + (C.hChapterDoc, "T0001"), + (C.hSceneDoc, "T0001"), + (hHandle, "T0001"), + (sHandle, "T0001"), + (tHandle, "T0001"), ] # 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)] == [ - (C.hTitlePage, "T000001"), - (C.hChapterDoc, "T000001"), - (C.hSceneDoc, "T000001"), - (nHandle, "T000001"), - (nHandle, "T000011"), - (hHandle, "T000001"), - (sHandle, "T000001"), - (tHandle, "T000001"), + (C.hTitlePage, "T0001"), + (C.hChapterDoc, "T0001"), + (C.hSceneDoc, "T0001"), + (nHandle, "T0001"), + (nHandle, "T0002"), + (hHandle, "T0001"), + (sHandle, "T0001"), + (tHandle, "T0001"), ] theProject.tree._treeOrder.remove("0000000000000") @@ -734,37 +751,37 @@ def testCoreIndex_ExtractData(mockGUI, fncPath, mockRnd): # Table of Contents assert theIndex.getTableOfContents(C.hNovelRoot, 0, skipExcl=True) == [] assert theIndex.getTableOfContents(C.hNovelRoot, 1, skipExcl=True) == [ - (f"{C.hTitlePage}:T000001", 1, "New Novel", 15), + (f"{C.hTitlePage}:T0001", 1, "New Novel", 15), ] 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), + (f"{C.hTitlePage}:T0001", 1, "New Novel", 5), + (f"{C.hChapterDoc}:T0001", 2, "New Chapter", 4), + (f"{hHandle}:T0001", 2, "Chapter One", 6), ] 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), + (f"{C.hTitlePage}:T0001", 1, "New Novel", 5), + (f"{C.hChapterDoc}:T0001", 2, "New Chapter", 2), + (f"{C.hSceneDoc}:T0001", 3, "New Scene", 2), + (f"{hHandle}:T0001", 2, "Chapter One", 2), + (f"{sHandle}:T0001", 3, "Scene One", 2), + (f"{tHandle}:T0001", 3, "Scene Two", 2), ] 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), + (f"{C.hTitlePage}:T0001", 1, "New Novel", 9), + (f"{nHandle}:T0001", 1, "Hello World!", 12), + (f"{nHandle}:T0002", 1, "Hello World!", 22), ] # Header Word Counts bHandle = "0000000000000" assert theIndex.getHandleWordCounts(bHandle) == [] - assert theIndex.getHandleWordCounts(hHandle) == [("%s:T000001" % hHandle, 2)] - assert theIndex.getHandleWordCounts(sHandle) == [("%s:T000001" % sHandle, 2)] - assert theIndex.getHandleWordCounts(tHandle) == [("%s:T000001" % tHandle, 2)] + assert theIndex.getHandleWordCounts(hHandle) == [("%s:T0001" % hHandle, 2)] + assert theIndex.getHandleWordCounts(sHandle) == [("%s:T0001" % sHandle, 2)] + assert theIndex.getHandleWordCounts(tHandle) == [("%s:T0001" % tHandle, 2)] assert theIndex.getHandleWordCounts(nHandle) == [ - (f"{nHandle}:T000001", 12), (f"{nHandle}:T000011", 16) + (f"{nHandle}:T0001", 12), (f"{nHandle}:T0002", 16) ] assert theIndex.saveIndex() is True @@ -773,11 +790,11 @@ def testCoreIndex_ExtractData(mockGUI, fncPath, mockRnd): # Header Record bHandle = "0000000000000" assert theIndex.getHandleHeaders(bHandle) == [] - assert theIndex.getHandleHeaders(hHandle) == [("T000001", "H2", "Chapter One")] - assert theIndex.getHandleHeaders(sHandle) == [("T000001", "H3", "Scene One")] - assert theIndex.getHandleHeaders(tHandle) == [("T000001", "H3", "Scene Two")] + assert theIndex.getHandleHeaders(hHandle) == [("T0001", "H2", "Chapter One")] + assert theIndex.getHandleHeaders(sHandle) == [("T0001", "H3", "Scene One")] + assert theIndex.getHandleHeaders(tHandle) == [("T0001", "H3", "Scene Two")] assert theIndex.getHandleHeaders(nHandle) == [ - ("T000001", "H1", "Hello World!"), ("T000011", "H1", "Hello World!") + ("T0001", "H1", "Hello World!"), ("T0002", "H1", "Hello World!") ] assert theProject.closeProject() is True @@ -796,25 +813,25 @@ def testCoreIndex_TagsIndex(): content = { "Tag1": { "handle": "0000000000001", - "heading": "T000001", + "heading": "T0001", "class": nwItemClass.NOVEL.name, }, "Tag2": { "handle": "0000000000002", - "heading": "T000002", + "heading": "T0002", "class": nwItemClass.CHARACTER.name, }, "Tag3": { "handle": "0000000000003", - "heading": "T000003", + "heading": "T0003", "class": nwItemClass.PLOT.name, }, } # Add data - tagsIndex.add("Tag1", "0000000000001", "T000001", nwItemClass.NOVEL) - tagsIndex.add("Tag2", "0000000000002", "T000002", nwItemClass.CHARACTER) - tagsIndex.add("Tag3", "0000000000003", "T000003", nwItemClass.PLOT) + tagsIndex.add("Tag1", "0000000000001", "T0001", nwItemClass.NOVEL) + tagsIndex.add("Tag2", "0000000000002", "T0002", nwItemClass.CHARACTER) + tagsIndex.add("Tag3", "0000000000003", "T0003", nwItemClass.PLOT) assert tagsIndex._tags == content # Get items @@ -836,10 +853,10 @@ def testCoreIndex_TagsIndex(): assert tagsIndex.tagHandle("Tag4") is None # Read back headings - assert tagsIndex.tagHeading("Tag1") == "T000001" - assert tagsIndex.tagHeading("Tag2") == "T000002" - assert tagsIndex.tagHeading("Tag3") == "T000003" - assert tagsIndex.tagHeading("Tag4") == "T000000" + assert tagsIndex.tagHeading("Tag1") == "T0001" + assert tagsIndex.tagHeading("Tag2") == "T0002" + assert tagsIndex.tagHeading("Tag3") == "T0003" + assert tagsIndex.tagHeading("Tag4") == "T0000" # Read back classes assert tagsIndex.tagClass("Tag1") == nwItemClass.NOVEL.name @@ -880,7 +897,7 @@ def testCoreIndex_TagsIndex(): tagsIndex.unpackData({ 1234: { "handle": "0000000000001", - "heading": "T000001", + "heading": "T0001", "class": "NOVEL", } }) @@ -889,7 +906,7 @@ def testCoreIndex_TagsIndex(): with pytest.raises(KeyError): tagsIndex.unpackData({ "Tag1": { - "heading": "T000001", + "heading": "T0001", "class": "NOVEL", } }) @@ -908,7 +925,7 @@ def testCoreIndex_TagsIndex(): tagsIndex.unpackData({ "Tag1": { "handle": "0000000000001", - "heading": "T000001", + "heading": "T0001", } }) @@ -917,7 +934,7 @@ def testCoreIndex_TagsIndex(): tagsIndex.unpackData({ "Tag1": { "handle": "blablabla", - "heading": "T000001", + "heading": "T0001", "class": "NOVEL", } }) @@ -937,7 +954,7 @@ def testCoreIndex_TagsIndex(): tagsIndex.unpackData({ "Tag1": { "handle": "0000000000001", - "heading": "T000001", + "heading": "T0001", "class": "blabla", } }) @@ -975,66 +992,70 @@ def testCoreIndex_ItemIndex(mockGUI, fncPath, mockRnd): assert cHandle in itemIndex assert itemIndex[cHandle].item == theProject.tree[cHandle] assert itemIndex.allItemTags(cHandle) == [] - assert list(itemIndex.iterItemHeaders(cHandle))[0][0] == "T000000" + assert list(itemIndex.iterItemHeaders(cHandle))[0][0] == "T0000" # Add a heading to the item, which should replace the T000000 heading - itemIndex.addItemHeading(cHandle, "T000001", "H2", "Chapter One") - assert list(itemIndex.iterItemHeaders(cHandle))[0][0] == "T000001" + assert itemIndex.addItemHeading(cHandle, 1, "H2", "Chapter One") == "T0001" + assert list(itemIndex.iterItemHeaders(cHandle))[0][0] == "T0001" + + # Add a heading to an invalid item + assert itemIndex.addItemHeading(C.hInvalid, 1, "H1", "Stuff") == "T0000" # Set the remainig data values - itemIndex.setHeadingCounts(cHandle, "T000001", 60, 10, 2) - itemIndex.setHeadingSynopsis(cHandle, "T000001", "In the beginning ...") - itemIndex.setHeadingTag(cHandle, "T000001", "One") - itemIndex.addHeadingReferences(cHandle, "T000001", ["Jane"], "@pov") - itemIndex.addHeadingReferences(cHandle, "T000001", ["Jane"], "@focus") - itemIndex.addHeadingReferences(cHandle, "T000001", ["Jane", "John"], "@char") + itemIndex.setHeadingCounts(cHandle, "T0001", 60, 10, 2) + itemIndex.setHeadingSynopsis(cHandle, "T0001", "In the beginning ...") + itemIndex.setHeadingTag(cHandle, "T0001", "One") + itemIndex.addHeadingReferences(cHandle, "T0001", ["Jane"], "@pov") + itemIndex.addHeadingReferences(cHandle, "T0001", ["Jane"], "@focus") + itemIndex.addHeadingReferences(cHandle, "T0001", ["Jane", "John"], "@char") idxData = itemIndex.packData() - assert idxData[cHandle]["headings"]["T000001"] == { - "level": "H2", "title": "Chapter One", "tag": "One", + assert idxData[cHandle]["headings"]["T0001"] == { + "level": "H2", "line": 1, "title": "Chapter One", "tag": "One", "cCount": 60, "wCount": 10, "pCount": 2, "synopsis": "In the beginning ...", } - assert "@pov" in idxData[cHandle]["references"]["T000001"]["Jane"] - assert "@focus" in idxData[cHandle]["references"]["T000001"]["Jane"] - assert "@char" in idxData[cHandle]["references"]["T000001"]["Jane"] - assert "@char" in idxData[cHandle]["references"]["T000001"]["John"] + assert "@pov" in idxData[cHandle]["references"]["T0001"]["Jane"] + assert "@focus" in idxData[cHandle]["references"]["T0001"]["Jane"] + assert "@char" in idxData[cHandle]["references"]["T0001"]["Jane"] + assert "@char" in idxData[cHandle]["references"]["T0001"]["John"] # Add the other two files itemIndex.add(nHandle, theProject.tree[nHandle]) itemIndex.add(sHandle, theProject.tree[sHandle]) - itemIndex.addItemHeading(nHandle, "T000001", "H1", "Novel") - itemIndex.addItemHeading(sHandle, "T000001", "H3", "Scene One") + itemIndex.addItemHeading(nHandle, 1, "H1", "Novel") + itemIndex.addItemHeading(sHandle, 1, "H3", "Scene One") # Check Item and Heading Direct Access # ==================================== # Check repr strings assert repr(itemIndex[nHandle]) == f"" - assert repr(itemIndex[nHandle]["T000001"]) == "" + assert repr(itemIndex[nHandle]["T0001"]) == "" # Check content of a single item - assert "T000001" in itemIndex[nHandle] + assert "T0001" in itemIndex[nHandle] assert itemIndex[cHandle].allTags() == ["One"] # Check the content of a single heading - assert itemIndex[cHandle]["T000001"].key == "T000001" - assert itemIndex[cHandle]["T000001"].level == "H2" - assert itemIndex[cHandle]["T000001"].title == "Chapter One" - assert itemIndex[cHandle]["T000001"].tag == "One" - assert itemIndex[cHandle]["T000001"].charCount == 60 - assert itemIndex[cHandle]["T000001"].wordCount == 10 - assert itemIndex[cHandle]["T000001"].paraCount == 2 - assert itemIndex[cHandle]["T000001"].synopsis == "In the beginning ..." - assert "Jane" in itemIndex[cHandle]["T000001"].references - assert "John" in itemIndex[cHandle]["T000001"].references + assert itemIndex[cHandle]["T0001"].key == "T0001" + assert itemIndex[cHandle]["T0001"].level == "H2" + assert itemIndex[cHandle]["T0001"].line == 1 + assert itemIndex[cHandle]["T0001"].title == "Chapter One" + assert itemIndex[cHandle]["T0001"].tag == "One" + assert itemIndex[cHandle]["T0001"].charCount == 60 + assert itemIndex[cHandle]["T0001"].wordCount == 10 + assert itemIndex[cHandle]["T0001"].paraCount == 2 + assert itemIndex[cHandle]["T0001"].synopsis == "In the beginning ..." + assert "Jane" in itemIndex[cHandle]["T0001"].references + assert "John" in itemIndex[cHandle]["T0001"].references # Check heading level setter - itemIndex[cHandle]["T000001"].setLevel("H3") # Change it - assert itemIndex[cHandle]["T000001"].level == "H3" - itemIndex[cHandle]["T000001"].setLevel("H2") # Set it back - assert itemIndex[cHandle]["T000001"].level == "H2" - itemIndex[cHandle]["T000001"].setLevel("H5") # Invalid level - assert itemIndex[cHandle]["T000001"].level == "H2" + itemIndex[cHandle]["T0001"].setLevel("H3") # Change it + assert itemIndex[cHandle]["T0001"].level == "H3" + itemIndex[cHandle]["T0001"].setLevel("H2") # Set it back + assert itemIndex[cHandle]["T0001"].level == "H2" + itemIndex[cHandle]["T0001"].setLevel("H5") # Invalid level + assert itemIndex[cHandle]["T0001"].level == "H2" # Data Extraction # =============== @@ -1044,9 +1065,9 @@ def testCoreIndex_ItemIndex(mockGUI, fncPath, mockRnd): assert allHeads[0][0] == cHandle assert allHeads[1][0] == nHandle assert allHeads[2][0] == sHandle - assert allHeads[0][1] == "T000001" - assert allHeads[1][1] == "T000001" - assert allHeads[2][1] == "T000001" + assert allHeads[0][1] == "T0001" + assert allHeads[1][1] == "T0001" + assert allHeads[2][1] == "T0001" # Ask for stuff that doesn't exist assert itemIndex.allItemTags("blablabla") == [] @@ -1058,7 +1079,7 @@ def testCoreIndex_ItemIndex(mockGUI, fncPath, mockRnd): mHandle = theProject.newRoot(nwItemClass.NOVEL) uHandle = theProject.newFile("Title Page", mHandle) itemIndex.add(uHandle, theProject.tree[uHandle]) - itemIndex.addItemHeading(uHandle, "T000001", "H1", "Novel 2") + itemIndex.addItemHeading(uHandle, "T0001", "H1", "Novel 2") assert uHandle in itemIndex # Structure of all novels @@ -1134,20 +1155,20 @@ def testCoreIndex_ItemIndex(mockGUI, fncPath, mockRnd): # Reference without a heading should be rejected itemIndex.unpackData({ cHandle: { - "headings": {"T000001": {}}, - "references": {"T000001": {}, "T000002": {}}, + "headings": {"T0001": {}}, + "references": {"T0001": {}, "T0002": {}}, } }) - assert "T000001" in itemIndex[cHandle] - assert "T000002" not in itemIndex[cHandle] + assert "T0001" in itemIndex[cHandle] + assert "T0002" not in itemIndex[cHandle] itemIndex.clear() # Tag keys must be strings with pytest.raises(ValueError): itemIndex.unpackData({ cHandle: { - "headings": {"T000001": {}}, - "references": {"T000001": {1234: "@pov"}}, + "headings": {"T0001": {}}, + "references": {"T0001": {1234: "@pov"}}, } }) @@ -1155,8 +1176,8 @@ def testCoreIndex_ItemIndex(mockGUI, fncPath, mockRnd): with pytest.raises(ValueError): itemIndex.unpackData({ cHandle: { - "headings": {"T000001": {}}, - "references": {"T000001": {"John": []}}, + "headings": {"T0001": {}}, + "references": {"T0001": {"John": []}}, } }) @@ -1164,16 +1185,16 @@ def testCoreIndex_ItemIndex(mockGUI, fncPath, mockRnd): with pytest.raises(ValueError): itemIndex.unpackData({ cHandle: { - "headings": {"T000001": {}}, - "references": {"T000001": {"John": "@pov,@char,@stuff"}}, + "headings": {"T0001": {}}, + "references": {"T0001": {"John": "@pov,@char,@stuff"}}, } }) # This should pass itemIndex.unpackData({ cHandle: { - "headings": {"T000001": {}}, - "references": {"T000001": {"John": "@pov,@char"}}, + "headings": {"T0001": {}}, + "references": {"T0001": {"John": "@pov,@char"}}, } }) diff --git a/tests/test_gui/test_gui_noveltree.py b/tests/test_gui/test_gui_noveltree.py index 20c38d03..15101972 100644 --- a/tests/test_gui/test_gui_noveltree.py +++ b/tests/test_gui/test_gui_noveltree.py @@ -92,7 +92,7 @@ def testGuiNovelTree_TreeItems(qtbot, monkeypatch, nwGUI, projPath, mockRnd): assert not topItem.isSelected() topItem.setSelected(True) assert novelTree.selectedItems()[0] == topItem - assert novelView.getSelectedHandle() == (C.hTitlePage, 0) + assert novelView.getSelectedHandle() == (C.hTitlePage, "T0001") # Refresh using the slot for the butoom novelBar._refreshNovelTree() @@ -142,31 +142,31 @@ def testGuiNovelTree_TreeItems(qtbot, monkeypatch, nwGUI, projPath, mockRnd): novelBar.setLastColType(NovelTreeColumn.HIDDEN) assert novelTree.isColumnHidden(novelTree.C_EXTRA) is True assert novelTree.lastColType == NovelTreeColumn.HIDDEN - assert novelTree._getLastColumnText(C.hSceneDoc, "T000001") == ("", "") + assert novelTree._getLastColumnText(C.hSceneDoc, "T0001") == ("", "") novelBar.setLastColType(NovelTreeColumn.POV) assert novelTree.isColumnHidden(novelTree.C_EXTRA) is False assert novelTree.lastColType == NovelTreeColumn.POV - assert novelTree._getLastColumnText(C.hSceneDoc, "T000001") == ( + assert novelTree._getLastColumnText(C.hSceneDoc, "T0001") == ( "Jane", "Point of View: Jane" ) novelBar.setLastColType(NovelTreeColumn.FOCUS) assert novelTree.isColumnHidden(novelTree.C_EXTRA) is False assert novelTree.lastColType == NovelTreeColumn.FOCUS - assert novelTree._getLastColumnText(C.hSceneDoc, "T000001") == ( + assert novelTree._getLastColumnText(C.hSceneDoc, "T0001") == ( "Jane", "Focus: Jane" ) novelBar.setLastColType(NovelTreeColumn.PLOT) assert novelTree.isColumnHidden(novelTree.C_EXTRA) is False assert novelTree.lastColType == NovelTreeColumn.PLOT - assert novelTree._getLastColumnText(C.hSceneDoc, "T000001") == ( + assert novelTree._getLastColumnText(C.hSceneDoc, "T0001") == ( "", "Plot: " ) novelTree._lastCol = None - assert novelTree._getLastColumnText("0000000000000", "T000000") == ("", "") + assert novelTree._getLastColumnText("0000000000000", "T0000") == ("", "") # Item Meta # ========= diff --git a/tests/test_gui/test_gui_outline.py b/tests/test_gui/test_gui_outline.py index 23f61c5b..707f497d 100644 --- a/tests/test_gui/test_gui_outline.py +++ b/tests/test_gui/test_gui_outline.py @@ -225,9 +225,9 @@ def testGuiOutline_Content(qtbot, nwGUI, nwLipsum): selItem = outlineTree.topLevelItem(4) outlineTree.setCurrentItem(selItem) - tHandle, tLine = outlineTree.getSelectedHandle() + tHandle, sTitle = outlineTree.getSelectedHandle() assert tHandle == "88243afbe5ed8" - assert tLine == 0 + assert sTitle == "T0001" assert outlineData.titleLabel.text() == "Scene" assert outlineData.titleValue.text() == "Scene One" @@ -243,9 +243,9 @@ def testGuiOutline_Content(qtbot, nwGUI, nwLipsum): selItem = outlineTree.topLevelItem(5) outlineTree.setCurrentItem(selItem) - tHandle, tLine = outlineTree.getSelectedHandle() + tHandle, sTitle = outlineTree.getSelectedHandle() assert tHandle == "88243afbe5ed8" - assert tLine == 12 + assert sTitle == "T0002" assert outlineData.titleLabel.text() == "Section" assert outlineData.titleValue.text() == "Scene One, Section Two"