Use the new index instead of the old

This commit is contained in:
Veronica Berglyd Olsen
2022-05-28 21:59:52 +02:00
parent 01be8be44f
commit 94ba7a2f94
7 changed files with 343 additions and 1015 deletions
+121 -95
View File
@@ -1,99 +1,125 @@
{
"tagIndex": {
"Bod": [3, "4c4f28287af27", "CHARACTER", "T000001"],
"Main": [3, "2426c6f0ca922", "PLOT", "T000001"],
"Europe": [3, "04468803b92e1", "WORLD", "T000001"]
},
"refIndex": {
"fb609cd8319dc": {
"T000001": [[3, "@pov", "Bod"], [4, "@plot", "Main"], [5, "@location", "Europe"]]
"tagsIndex": {
"Bod": {"handle": "4c4f28287af27", "heading": "T000001", "class": "CHARACTER"},
"Main": {"handle": "2426c6f0ca922", "heading": "T000001", "class": "PLOT"},
"Europe": {"handle": "04468803b92e1", "heading": "T000001", "class": "WORLD"}
},
"88243afbe5ed8": {
"T000001": [[3, "@pov", "Bod"], [4, "@plot", "Main"], [5, "@location", "Europe"]]
},
"f96ec11c6a3da": {
"T000001": [[3, "@pov", "Bod"], [4, "@plot", "Main"], [5, "@location", "Europe"]]
},
"441420a886d82": {
"T000001": [[3, "@pov", "Bod"], [4, "@plot", "Main"], [5, "@location", "Europe"]]
},
"eb103bc70c90c": {
"T000001": [[3, "@pov", "Bod"], [4, "@plot", "Main"], [5, "@location", "Europe"]]
},
"f8c0562e50f1b": {
"T000001": [[3, "@pov", "Bod"], [4, "@plot", "Main"], [5, "@location", "Europe"]]
},
"47666c91c7ccf": {
"T000001": [[3, "@pov", "Bod"], [4, "@plot", "Main"], [5, "@location", "Europe"]]
},
"4c4f28287af27": {
"T000001": [[4, "@plot", "Main"]]
"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."}
},
"references": {
"T000001": {"Bod": ["@pov"], "Main": ["@plot"], "Europe": ["@location"]}
}
},
"88243afbe5ed8": {
"level": "H0",
"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": ""}
},
"references": {
"T000001": {"Bod": ["@pov"], "Main": ["@plot"], "Europe": ["@location"]}
}
},
"f96ec11c6a3da": {
"level": "H0",
"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": ""}
},
"references": {
"T000001": {"Bod": ["@pov"], "Main": ["@plot"], "Europe": ["@location"]}
}
},
"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."}
},
"references": {
"T000001": {"Bod": ["@pov"], "Main": ["@plot"], "Europe": ["@location"]}
}
},
"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."}
},
"references": {
"T000001": {"Bod": ["@pov"], "Main": ["@plot"], "Europe": ["@location"]}
}
},
"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."}
},
"references": {
"T000001": {"Bod": ["@pov"], "Main": ["@plot"], "Europe": ["@location"]}
}
},
"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."}
},
"references": {
"T000001": {"Bod": ["@pov"], "Main": ["@plot"], "Europe": ["@location"]}
}
},
"4c4f28287af27": {
"level": "H1",
"headings": {
"T000001": {"level": "H1", "title": "Nobody Owens", "tag": "Bod", "cCount": 1864, "wCount": 284, "pCount": 3, "synopsis": ""}
},
"references": {
"T000001": {"Main": ["@plot"]}
}
},
"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": ""}
}
}
}
},
"fileIndex": {
"7a992350f3eb6": {
"T000001": {"level": "H1", "title": "Lorem Ipsum", "layout": "DOCUMENT", "cCount": 230, "wCount": 40, "pCount": 3, "synopsis": ""}
},
"8c58a65414c23": {
"T000000": {"level": "H0", "title": "", "layout": "DOCUMENT", "cCount": 1058, "wCount": 176, "pCount": 2, "synopsis": ""}
},
"88d59a277361b": {
"T000001": {"level": "H2", "title": "Prologue", "layout": "DOCUMENT", "cCount": 584, "wCount": 92, "pCount": 1, "synopsis": "Explanation from the lipsum.com website."}
},
"db7e733775d4d": {
"T000001": {"level": "H1", "title": "Act One", "layout": "DOCUMENT", "cCount": 35, "wCount": 6, "pCount": 1, "synopsis": ""}
},
"fb609cd8319dc": {
"T000001": {"level": "H2", "title": "Chapter One", "layout": "DOCUMENT", "cCount": 419, "wCount": 67, "pCount": 1, "synopsis": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque at aliquam quam."}
},
"88243afbe5ed8": {
"T000001": {"level": "H3", "title": "Scene One", "layout": "DOCUMENT", "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", "layout": "DOCUMENT", "cCount": 1561, "wCount": 230, "pCount": 2, "synopsis": ""}
},
"f96ec11c6a3da": {
"T000001": {"level": "H3", "title": "Scene Two", "layout": "DOCUMENT", "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", "layout": "DOCUMENT", "cCount": 2009, "wCount": 301, "pCount": 3, "synopsis": ""}
},
"846352075de7d": {
"T000001": {"level": "H2", "title": "Why do we use it?", "layout": "DOCUMENT", "cCount": 631, "wCount": 109, "pCount": 3, "synopsis": ""}
},
"441420a886d82": {
"T000001": {"level": "H2", "title": "Chapter Two", "layout": "DOCUMENT", "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."}
},
"eb103bc70c90c": {
"T000001": {"level": "H3", "title": "Scene Three", "layout": "DOCUMENT", "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."}
},
"f8c0562e50f1b": {
"T000001": {"level": "H3", "title": "Scene Four", "layout": "DOCUMENT", "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."}
},
"47666c91c7ccf": {
"T000001": {"level": "H3", "title": "Scene Five", "layout": "DOCUMENT", "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."}
},
"4c4f28287af27": {
"T000001": {"level": "H1", "title": "Nobody Owens", "layout": "NOTE", "cCount": 1864, "wCount": 284, "pCount": 3, "synopsis": ""}
},
"2426c6f0ca922": {
"T000001": {"level": "H1", "title": "Main Plot", "layout": "NOTE", "cCount": 1369, "wCount": 195, "pCount": 2, "synopsis": ""}
},
"04468803b92e1": {
"T000001": {"level": "H1", "title": "Ancient Europe", "layout": "NOTE", "cCount": 1770, "wCount": 259, "pCount": 3, "synopsis": ""}
}
},
"fileMeta": {
"7a992350f3eb6": ["H1", 230, 40, 3],
"8c58a65414c23": ["H0", 1058, 176, 2],
"88d59a277361b": ["H2", 584, 92, 1],
"db7e733775d4d": ["H1", 35, 6, 1],
"fb609cd8319dc": ["H2", 419, 67, 1],
"88243afbe5ed8": ["H3", 2758, 404, 4],
"f96ec11c6a3da": ["H3", 4043, 600, 6],
"846352075de7d": ["H2", 631, 109, 3],
"441420a886d82": ["H2", 477, 70, 1],
"eb103bc70c90c": ["H3", 3006, 439, 4],
"f8c0562e50f1b": ["H3", 3839, 563, 6],
"47666c91c7ccf": ["H3", 3644, 543, 5],
"4c4f28287af27": ["H1", 1864, 284, 3],
"2426c6f0ca922": ["H1", 1369, 195, 2],
"04468803b92e1": ["H1", 1770, 259, 3]
}
}
+75 -625
View File
@@ -69,27 +69,19 @@ def testCoreIndex_LoadSave(monkeypatch, nwLipsum, mockGUI, outDir, refDir):
# Take a copy of the index
tagIndex = str(theIndex._tags)
refIndex = str(theIndex._refIndex)
fileIndex = str(theIndex._fileIndex)
textCounts = str(theIndex._fileMeta)
itemsIndex = str({handle: item.packData() for handle, item in theIndex._items.items()})
# Delete a handle
assert theIndex._tags.get("Bod", None) is not None
assert theIndex._refIndex.get("4c4f28287af27", None) is not None
assert theIndex._fileIndex.get("4c4f28287af27", None) is not None
assert theIndex._fileMeta.get("4c4f28287af27", None) is not None
assert theIndex._items.get("4c4f28287af27", None) is not None
theIndex.deleteHandle("4c4f28287af27")
assert theIndex._tags.get("Bod", None) is None
assert theIndex._refIndex.get("4c4f28287af27", None) is None
assert theIndex._fileIndex.get("4c4f28287af27", None) is None
assert theIndex._fileMeta.get("4c4f28287af27", None) is None
assert theIndex._items.get("4c4f28287af27", None) is None
# Clear the index
theIndex.clearIndex()
assert theIndex._tags == {}
assert theIndex._refIndex == {}
assert theIndex._fileIndex == {}
assert theIndex._fileMeta == {}
assert theIndex._items == {}
# Make the load fail
with monkeypatch.context() as mp:
@@ -100,9 +92,9 @@ def testCoreIndex_LoadSave(monkeypatch, nwLipsum, mockGUI, outDir, refDir):
assert theIndex.loadIndex() is True
assert str(theIndex._tags) == tagIndex
assert str(theIndex._refIndex) == refIndex
assert str(theIndex._fileIndex) == fileIndex
assert str(theIndex._fileMeta) == textCounts
assert str(
{handle: item.packData() for handle, item in theIndex._items.items()}
) == itemsIndex
# Break the index and check that we notice
# assert theIndex.indexBroken is False
@@ -201,7 +193,7 @@ def testCoreIndex_CheckThese(nwMinimal, mockGUI):
assert theIndex._tags == {
"Jane": {"handle": cHandle, "heading": "T000001", "class": "CHARACTER"}
}
assert theIndex.getNovelData(nHandle, "T000001")["title"] == "Hello World!"
assert theIndex.getNovelData(nHandle, "T000001").title == "Hello World!"
assert theIndex.getReferences(nHandle, "T000001") == {
"@char": [],
"@custom": [],
@@ -314,7 +306,7 @@ def testCoreIndex_ScanText(nwMinimal, mockGUI):
assert theIndex._tags == {
"Jane": {"handle": cHandle, "heading": "T000001", "class": "CHARACTER"}
}
assert theIndex.getNovelData(nHandle, "T000001")["title"] == "Hello World!"
assert theIndex.getNovelData(nHandle, "T000001").title == "Hello World!"
# Title Indexing
# ==============
@@ -336,42 +328,40 @@ def testCoreIndex_ScanText(nwMinimal, mockGUI):
"##### Title Five\n\n" # Not interpreted as a title, the hashes are counted as a word
"Paragraph Five.\n\n"
))
assert nHandle not in theIndex._refIndex
assert theIndex._items[nHandle]["T000001"].references == {}
assert theIndex._items[nHandle]["T000007"].references == {}
assert theIndex._items[nHandle]["T000013"].references == {}
assert theIndex._items[nHandle]["T000019"].references == {}
assert theIndex._fileIndex[nHandle]["T000001"]["level"] == "H1"
assert theIndex._fileIndex[nHandle]["T000007"]["level"] == "H2"
assert theIndex._fileIndex[nHandle]["T000013"]["level"] == "H3"
assert theIndex._fileIndex[nHandle]["T000019"]["level"] == "H4"
assert theIndex._items[nHandle]["T000001"].level == "H1"
assert theIndex._items[nHandle]["T000007"].level == "H2"
assert theIndex._items[nHandle]["T000013"].level == "H3"
assert theIndex._items[nHandle]["T000019"].level == "H4"
assert theIndex._fileIndex[nHandle]["T000001"]["title"] == "Title One"
assert theIndex._fileIndex[nHandle]["T000007"]["title"] == "Title Two"
assert theIndex._fileIndex[nHandle]["T000013"]["title"] == "Title Three"
assert theIndex._fileIndex[nHandle]["T000019"]["title"] == "Title Four"
assert theIndex._items[nHandle]["T000001"].title == "Title One"
assert theIndex._items[nHandle]["T000007"].title == "Title Two"
assert theIndex._items[nHandle]["T000013"].title == "Title Three"
assert theIndex._items[nHandle]["T000019"].title == "Title Four"
assert theIndex._fileIndex[nHandle]["T000001"]["layout"] == "DOCUMENT"
assert theIndex._fileIndex[nHandle]["T000007"]["layout"] == "DOCUMENT"
assert theIndex._fileIndex[nHandle]["T000013"]["layout"] == "DOCUMENT"
assert theIndex._fileIndex[nHandle]["T000019"]["layout"] == "DOCUMENT"
assert theIndex._items[nHandle]["T000001"].charCount == 23
assert theIndex._items[nHandle]["T000007"].charCount == 23
assert theIndex._items[nHandle]["T000013"].charCount == 27
assert theIndex._items[nHandle]["T000019"].charCount == 56
assert theIndex._fileIndex[nHandle]["T000001"]["cCount"] == 23
assert theIndex._fileIndex[nHandle]["T000007"]["cCount"] == 23
assert theIndex._fileIndex[nHandle]["T000013"]["cCount"] == 27
assert theIndex._fileIndex[nHandle]["T000019"]["cCount"] == 56
assert theIndex._items[nHandle]["T000001"].wordCount == 4
assert theIndex._items[nHandle]["T000007"].wordCount == 4
assert theIndex._items[nHandle]["T000013"].wordCount == 4
assert theIndex._items[nHandle]["T000019"].wordCount == 9
assert theIndex._fileIndex[nHandle]["T000001"]["wCount"] == 4
assert theIndex._fileIndex[nHandle]["T000007"]["wCount"] == 4
assert theIndex._fileIndex[nHandle]["T000013"]["wCount"] == 4
assert theIndex._fileIndex[nHandle]["T000019"]["wCount"] == 9
assert theIndex._items[nHandle]["T000001"].paraCount == 1
assert theIndex._items[nHandle]["T000007"].paraCount == 1
assert theIndex._items[nHandle]["T000013"].paraCount == 1
assert theIndex._items[nHandle]["T000019"].paraCount == 3
assert theIndex._fileIndex[nHandle]["T000001"]["pCount"] == 1
assert theIndex._fileIndex[nHandle]["T000007"]["pCount"] == 1
assert theIndex._fileIndex[nHandle]["T000013"]["pCount"] == 1
assert theIndex._fileIndex[nHandle]["T000019"]["pCount"] == 3
assert theIndex._fileIndex[nHandle]["T000001"]["synopsis"] == "Synopsis One."
assert theIndex._fileIndex[nHandle]["T000007"]["synopsis"] == "Synopsis Two."
assert theIndex._fileIndex[nHandle]["T000013"]["synopsis"] == "Synopsis Three."
assert theIndex._fileIndex[nHandle]["T000019"]["synopsis"] == "Synopsis Four."
assert theIndex._items[nHandle]["T000001"].synopsis == "Synopsis One."
assert theIndex._items[nHandle]["T000007"].synopsis == "Synopsis Two."
assert theIndex._items[nHandle]["T000013"].synopsis == "Synopsis Three."
assert theIndex._items[nHandle]["T000019"].synopsis == "Synopsis Four."
# Note File
assert theIndex.scanText(cHandle, (
@@ -380,15 +370,13 @@ def testCoreIndex_ScanText(nwMinimal, mockGUI):
"% synopsis: Synopsis One.\n\n"
"Paragraph One.\n\n"
))
assert cHandle not in theIndex._refIndex
assert theIndex._fileIndex[cHandle]["T000001"]["level"] == "H1"
assert theIndex._fileIndex[cHandle]["T000001"]["title"] == "Title One"
assert theIndex._fileIndex[cHandle]["T000001"]["layout"] == "NOTE"
assert theIndex._fileIndex[cHandle]["T000001"]["cCount"] == 23
assert theIndex._fileIndex[cHandle]["T000001"]["wCount"] == 4
assert theIndex._fileIndex[cHandle]["T000001"]["pCount"] == 1
assert theIndex._fileIndex[cHandle]["T000001"]["synopsis"] == "Synopsis One."
assert theIndex._items[cHandle]["T000001"].references == {}
assert theIndex._items[cHandle]["T000001"].level == "H1"
assert theIndex._items[cHandle]["T000001"].title == "Title One"
assert theIndex._items[cHandle]["T000001"].charCount == 23
assert theIndex._items[cHandle]["T000001"].wordCount == 4
assert theIndex._items[cHandle]["T000001"].paraCount == 1
assert theIndex._items[cHandle]["T000001"].synopsis == "Synopsis One."
# Valid and Invalid References
assert theIndex.scanText(sHandle, (
@@ -399,9 +387,9 @@ def testCoreIndex_ScanText(nwMinimal, mockGUI):
"% synopsis: Synopsis One.\n\n"
"Paragraph One.\n\n"
))
assert theIndex._refIndex[sHandle]["T000001"] == (
[[3, "@pov", "One"], [5, "@char", "Two"]]
)
assert theIndex._items[sHandle]["T000001"].references == {
"One": {"@pov"}, "Two": {"@char"}
}
# Special Titles
# ==============
@@ -410,29 +398,25 @@ def testCoreIndex_ScanText(nwMinimal, mockGUI):
"#! My Project\n\n"
">> By Jane Doe <<\n\n"
))
assert tHandle not in theIndex._refIndex
assert theIndex._fileIndex[tHandle]["T000001"]["level"] == "H1"
assert theIndex._fileIndex[tHandle]["T000001"]["title"] == "My Project"
assert theIndex._fileIndex[tHandle]["T000001"]["layout"] == "DOCUMENT"
assert theIndex._fileIndex[tHandle]["T000001"]["cCount"] == 21
assert theIndex._fileIndex[tHandle]["T000001"]["wCount"] == 5
assert theIndex._fileIndex[tHandle]["T000001"]["pCount"] == 1
assert theIndex._fileIndex[tHandle]["T000001"]["synopsis"] == ""
assert theIndex._items[cHandle]["T000001"].references == {}
assert theIndex._items[tHandle]["T000001"].level == "H1"
assert theIndex._items[tHandle]["T000001"].title == "My Project"
assert theIndex._items[tHandle]["T000001"].charCount == 21
assert theIndex._items[tHandle]["T000001"].wordCount == 5
assert theIndex._items[tHandle]["T000001"].paraCount == 1
assert theIndex._items[tHandle]["T000001"].synopsis == ""
assert theIndex.scanText(tHandle, (
"##! Prologue\n\n"
"In the beginning there was time ...\n\n"
))
assert tHandle not in theIndex._refIndex
assert theIndex._fileIndex[tHandle]["T000001"]["level"] == "H2"
assert theIndex._fileIndex[tHandle]["T000001"]["title"] == "Prologue"
assert theIndex._fileIndex[tHandle]["T000001"]["layout"] == "DOCUMENT"
assert theIndex._fileIndex[tHandle]["T000001"]["cCount"] == 43
assert theIndex._fileIndex[tHandle]["T000001"]["wCount"] == 8
assert theIndex._fileIndex[tHandle]["T000001"]["pCount"] == 1
assert theIndex._fileIndex[tHandle]["T000001"]["synopsis"] == ""
assert theIndex._items[cHandle]["T000001"].references == {}
assert theIndex._items[tHandle]["T000001"].level == "H2"
assert theIndex._items[tHandle]["T000001"].title == "Prologue"
assert theIndex._items[tHandle]["T000001"].charCount == 43
assert theIndex._items[tHandle]["T000001"].wordCount == 8
assert theIndex._items[tHandle]["T000001"].paraCount == 1
assert theIndex._items[tHandle]["T000001"].synopsis == ""
# Page wo/Title
# =============
@@ -441,27 +425,25 @@ def testCoreIndex_ScanText(nwMinimal, mockGUI):
assert theIndex.scanText(pHandle, (
"This is a page with some text on it.\n\n"
))
assert pHandle in theIndex._fileIndex
assert theIndex._fileIndex[pHandle]["T000000"]["level"] == "H0"
assert theIndex._fileIndex[pHandle]["T000000"]["title"] == ""
assert theIndex._fileIndex[pHandle]["T000000"]["layout"] == "DOCUMENT"
assert theIndex._fileIndex[pHandle]["T000000"]["cCount"] == 36
assert theIndex._fileIndex[pHandle]["T000000"]["wCount"] == 9
assert theIndex._fileIndex[pHandle]["T000000"]["pCount"] == 1
assert theIndex._fileIndex[pHandle]["T000000"]["synopsis"] == ""
assert theIndex._items[pHandle]["T000000"].references == {}
assert theIndex._items[pHandle]["T000000"].level == "H0"
assert theIndex._items[pHandle]["T000000"].title == ""
assert theIndex._items[pHandle]["T000000"].charCount == 36
assert theIndex._items[pHandle]["T000000"].wordCount == 9
assert theIndex._items[pHandle]["T000000"].paraCount == 1
assert theIndex._items[pHandle]["T000000"].synopsis == ""
theProject.tree[pHandle]._layout = nwItemLayout.NOTE
assert theIndex.scanText(pHandle, (
"This is a page with some text on it.\n\n"
))
assert pHandle in theIndex._fileIndex
assert theIndex._fileIndex[pHandle]["T000000"]["level"] == "H0"
assert theIndex._fileIndex[pHandle]["T000000"]["title"] == ""
assert theIndex._fileIndex[pHandle]["T000000"]["layout"] == "NOTE"
assert theIndex._fileIndex[pHandle]["T000000"]["cCount"] == 36
assert theIndex._fileIndex[pHandle]["T000000"]["wCount"] == 9
assert theIndex._fileIndex[pHandle]["T000000"]["pCount"] == 1
assert theIndex._fileIndex[pHandle]["T000000"]["synopsis"] == ""
assert theIndex._items[pHandle]["T000000"].references == {}
assert theIndex._items[pHandle]["T000000"].level == "H0"
assert theIndex._items[pHandle]["T000000"].title == ""
assert theIndex._items[pHandle]["T000000"].charCount == 36
assert theIndex._items[pHandle]["T000000"].wordCount == 9
assert theIndex._items[pHandle]["T000000"].paraCount == 1
assert theIndex._items[pHandle]["T000000"].synopsis == ""
assert theProject.closeProject() is True
@@ -700,538 +682,6 @@ def testCoreIndex_ExtractData(nwMinimal, mockGUI):
# END Test testCoreIndex_ExtractData
# @pytest.mark.core
# def testCoreIndex_CheckTagIndex(mockGUI):
# """Test the tag index checker.
# """
# theProject = NWProject(mockGUI)
# theIndex = NWIndex(theProject)
# # Valid Index
# theIndex._tagIndex = {
# "John": [3, "14298de4d9524", "CHARACTER", "T000001"],
# "Jane": [3, "bb2c23b3c42cc", "CHARACTER", "T000001"],
# }
# assert theIndex._checkTagIndex() is None
# # Wrong Key Type
# theIndex._tagIndex = {
# "John": [3, "14298de4d9524", "CHARACTER", "T000001"],
# 123456: [3, "bb2c23b3c42cc", "CHARACTER", "T000001"],
# }
# with pytest.raises(KeyError):
# theIndex._checkTagIndex()
# # Wrong Length
# theIndex._tagIndex = {
# "John": [3, "14298de4d9524", "CHARACTER", "T000001"],
# "Jane": [3, "bb2c23b3c42cc", "CHARACTER", "T000001", "Stuff"],
# }
# with pytest.raises(IndexError):
# theIndex._checkTagIndex()
# # Wrong Type of Entry 0
# theIndex._tagIndex = {
# "John": [3, "14298de4d9524", "CHARACTER", "T000001"],
# "Jane": ["3", "bb2c23b3c42cc", "CHARACTER", "T000001"],
# }
# with pytest.raises(ValueError):
# theIndex._checkTagIndex()
# # Wrong Type of Entry 1
# theIndex._tagIndex = {
# "John": [3, "14298de4d9524", "CHARACTER", "T000001"],
# "Jane": [3, 0xbb2c23b3c42cc, "CHARACTER", "T000001"],
# }
# with pytest.raises(ValueError):
# theIndex._checkTagIndex()
# # Wrong Type of Entry 2
# theIndex._tagIndex = {
# "John": [3, "14298de4d9524", "CHARACTER", "T000001"],
# "Jane": [3, "bb2c23b3c42cc", "INVALID_CLASS", "T000001"],
# }
# with pytest.raises(ValueError):
# theIndex._checkTagIndex()
# # Wrong Type of Entry 3
# theIndex._tagIndex = {
# "John": [3, "14298de4d9524", "CHARACTER", "T000001"],
# "Jane": [3, "bb2c23b3c42cc", "CHARACTER", "INVALID"],
# }
# with pytest.raises(ValueError):
# theIndex._checkTagIndex()
# # END Test testCoreIndex_CheckTagIndex
@pytest.mark.core
def testCoreIndex_CheckRefIndex(mockGUI):
"""Test the reference index checker.
"""
theProject = NWProject(mockGUI)
theIndex = NWIndex(theProject)
# Valid Index
theIndex._refIndex = {
"6a2d6d5f4f401": {
"T000000": [],
"T000001": [[3, "@pov", "Jane"], [4, "@location", "Earth"]],
}
}
assert theIndex._checkRefIndex() is None
# Invalid Handle
theIndex._refIndex = {
"Ha2d6d5f4f401": {
"T000000": [],
"T000001": [[3, "@pov", "Jane"], [4, "@location", "Earth"]],
}
}
with pytest.raises(KeyError):
theIndex._checkRefIndex()
# Invalid Title
theIndex._refIndex = {
"6a2d6d5f4f401": {
"T000000": [],
"INVALID": [[3, "@pov", "Jane"], [4, "@location", "Earth"]],
}
}
with pytest.raises(KeyError):
theIndex._checkRefIndex()
# Wrong Length
theIndex._refIndex = {
"6a2d6d5f4f401": {
"T000000": [],
"T000001": [[3, "@pov", "Jane"], [4, "@location", "Earth", "Stuff"]],
}
}
with pytest.raises(IndexError):
theIndex._checkRefIndex()
# Wrong Type of Entry 0
theIndex._refIndex = {
"6a2d6d5f4f401": {
"T000000": [],
"T000001": [[3, "@pov", "Jane"], ["4", "@location", "Earth"]],
}
}
with pytest.raises(ValueError):
theIndex._checkRefIndex()
# Wrong Type of Entry 1
theIndex._refIndex = {
"6a2d6d5f4f401": {
"T000000": [],
"T000001": [[3, "@pov", "Jane"], [4, "@stuff", "Earth"]],
}
}
with pytest.raises(ValueError):
theIndex._checkRefIndex()
# Wrong Type of Entry 2
theIndex._refIndex = {
"6a2d6d5f4f401": {
"T000000": [],
"T000001": [[3, "@pov", "Jane"], [4, "@location", 123456]],
}
}
with pytest.raises(ValueError):
theIndex._checkRefIndex()
# END Test testCoreIndex_CheckRefIndex
@pytest.mark.core
def testCoreIndex_CheckFileIndex(mockGUI):
"""Test the file index checker.
"""
theProject = NWProject(mockGUI)
theIndex = NWIndex(theProject)
# Valid Index
theIndex._fileIndex = {
"53b69b83cdafc": {
"T000001": {
"level": "H1",
"title": "My Novel",
"layout": "DOCUMENT",
"cCount": 72,
"wCount": 15,
"pCount": 2,
"synopsis": "text",
}
}
}
theIndex._fileIndex = theIndex._fileIndex.copy()
assert theIndex._checkFileIndex() is None
# Invalid Handle
theIndex._fileIndex = {
"H3b69b83cdafc": {
"T000001": {
"level": "H1",
"title": "My Novel",
"layout": "DOCUMENT",
"cCount": 72,
"wCount": 15,
"pCount": 2,
"synopsis": "text",
}
}
}
with pytest.raises(KeyError):
theIndex._checkFileIndex()
# Invalid Title
theIndex._fileIndex = {
"53b69b83cdafc": {
"INVALID": {
"level": "H1",
"title": "My Novel",
"layout": "DOCUMENT",
"cCount": 72,
"wCount": 15,
"pCount": 2,
"synopsis": "text",
}
}
}
with pytest.raises(KeyError):
theIndex._checkFileIndex()
# Wrong Length
theIndex._fileIndex = {
"53b69b83cdafc": {
"T000001": {
"level": "H1",
"title": "My Novel",
"layout": "DOCUMENT",
"cCount": 72,
"wCount": 15,
"pCount": 2,
"synopsis": "text",
"stuff": None
}
}
}
with pytest.raises(IndexError):
theIndex._checkFileIndex()
# Missing Keys
# ============
# Missing 'level'
theIndex._fileIndex = {
"53b69b83cdafc": {
"T000001": {
"stuff": "H1",
"title": "My Novel",
"layout": "DOCUMENT",
"cCount": 72,
"wCount": 15,
"pCount": 2,
"synopsis": "text",
}
}
}
with pytest.raises(KeyError):
theIndex._checkFileIndex()
# Missing 'title'
theIndex._fileIndex = {
"53b69b83cdafc": {
"T000001": {
"level": "H1",
"stuff": "My Novel",
"layout": "DOCUMENT",
"cCount": 72,
"wCount": 15,
"pCount": 2,
"synopsis": "text",
}
}
}
with pytest.raises(KeyError):
theIndex._checkFileIndex()
# Missing 'layout'
theIndex._fileIndex = {
"53b69b83cdafc": {
"T000001": {
"level": "H1",
"title": "My Novel",
"stuff": "DOCUMENT",
"cCount": 72,
"wCount": 15,
"pCount": 2,
"synopsis": "text",
}
}
}
with pytest.raises(KeyError):
theIndex._checkFileIndex()
# Missing 'cCount'
theIndex._fileIndex = {
"53b69b83cdafc": {
"T000001": {
"level": "H1",
"title": "My Novel",
"layout": "DOCUMENT",
"stuff": 72,
"wCount": 15,
"pCount": 2,
"synopsis": "text",
}
}
}
with pytest.raises(KeyError):
theIndex._checkFileIndex()
# Missing 'wCount'
theIndex._fileIndex = {
"53b69b83cdafc": {
"T000001": {
"level": "H1",
"title": "My Novel",
"layout": "DOCUMENT",
"cCount": 72,
"stuff": 15,
"pCount": 2,
"synopsis": "text",
}
}
}
with pytest.raises(KeyError):
theIndex._checkFileIndex()
# Missing 'pCount'
theIndex._fileIndex = {
"53b69b83cdafc": {
"T000001": {
"level": "H1",
"title": "My Novel",
"layout": "DOCUMENT",
"cCount": 72,
"wCount": 15,
"stuff": 2,
"synopsis": "text",
}
}
}
with pytest.raises(KeyError):
theIndex._checkFileIndex()
# Missing 'synopsis'
theIndex._fileIndex = {
"53b69b83cdafc": {
"T000001": {
"level": "H1",
"title": "My Novel",
"layout": "DOCUMENT",
"cCount": 72,
"wCount": 15,
"pCount": 2,
"stuff": "text",
}
}
}
with pytest.raises(KeyError):
theIndex._checkFileIndex()
# Wrong Types
# ===========
# Wrong Type for 'level'
theIndex._fileIndex = {
"53b69b83cdafc": {
"T000001": {
"level": "XX",
"title": "My Novel",
"layout": "DOCUMENT",
"cCount": 72,
"wCount": 15,
"pCount": 2,
"synopsis": "text",
}
}
}
with pytest.raises(ValueError):
theIndex._checkFileIndex()
# Wrong Type for 'title'
theIndex._fileIndex = {
"53b69b83cdafc": {
"T000001": {
"level": "H1",
"title": 12345678,
"layout": "DOCUMENT",
"cCount": 72,
"wCount": 15,
"pCount": 2,
"synopsis": "text",
}
}
}
with pytest.raises(ValueError):
theIndex._checkFileIndex()
# Wrong Type for 'layout'
theIndex._fileIndex = {
"53b69b83cdafc": {
"T000001": {
"level": "H1",
"title": "My Novel",
"layout": "INVALID",
"cCount": 72,
"wCount": 15,
"pCount": 2,
"synopsis": "text",
}
}
}
with pytest.raises(ValueError):
theIndex._checkFileIndex()
# Wrong Type for 'cCount'
theIndex._fileIndex = {
"53b69b83cdafc": {
"T000001": {
"level": "H1",
"title": "My Novel",
"layout": "DOCUMENT",
"cCount": "72",
"wCount": 15,
"pCount": 2,
"synopsis": "text",
}
}
}
with pytest.raises(ValueError):
theIndex._checkFileIndex()
# Wrong Type for 'wCount'
theIndex._fileIndex = {
"53b69b83cdafc": {
"T000001": {
"level": "H1",
"title": "My Novel",
"layout": "DOCUMENT",
"cCount": 72,
"wCount": "15",
"pCount": 2,
"synopsis": "text",
}
}
}
with pytest.raises(ValueError):
theIndex._checkFileIndex()
# Wrong Type for 'pCount'
theIndex._fileIndex = {
"53b69b83cdafc": {
"T000001": {
"level": "H1",
"title": "My Novel",
"layout": "DOCUMENT",
"cCount": 72,
"wCount": 15,
"pCount": "2",
"synopsis": "text",
}
}
}
with pytest.raises(ValueError):
theIndex._checkFileIndex()
# Wrong Type for 'synopsis'
theIndex._fileIndex = {
"53b69b83cdafc": {
"T000001": {
"level": "H1",
"title": "My Novel",
"layout": "DOCUMENT",
"cCount": 72,
"wCount": 15,
"pCount": 2,
"synopsis": 123456,
}
}
}
with pytest.raises(ValueError):
theIndex._checkFileIndex()
# END Test testCoreIndex_CheckFileIndex
@pytest.mark.core
def testCoreIndex_CheckFileMeta(mockGUI):
"""Test the file meta checker.
"""
theProject = NWProject(mockGUI)
theIndex = NWIndex(theProject)
# Valid Index
theIndex._fileMeta = {
"53b69b83cdafc": ["H0", 72, 15, 2],
"974e400180a99": ["H0", 210, 40, 2],
}
assert theIndex._checkFileMeta() is None
# Invalid Handle
theIndex._fileMeta = {
"53b69b83cdafc": ["H0", 72, 15, 2],
"h74e400180a99": ["H0", 210, 40, 2],
}
with pytest.raises(KeyError):
theIndex._checkFileMeta()
# Wrong Length
theIndex._fileMeta = {
"53b69b83cdafc": ["H0", 72, 15, 2],
"974e400180a99": ["H0", 210, 40, 2, 8],
}
with pytest.raises(IndexError):
theIndex._checkFileMeta()
# Content of Entry 0
theIndex._fileMeta = {
"53b69b83cdafc": ["H0", 72, 15, 2],
"974e400180a99": ["XXX", 210, 40, 2],
}
with pytest.raises(ValueError):
theIndex._checkFileMeta()
# Type of Entry 1
theIndex._fileMeta = {
"53b69b83cdafc": ["H0", 72, 15, 2],
"974e400180a99": ["H0", "210", 40, 2],
}
with pytest.raises(ValueError):
theIndex._checkFileMeta()
# Type of Entry 2
theIndex._fileMeta = {
"53b69b83cdafc": ["H0", 72, 15, 2],
"974e400180a99": ["H0", 210, "40", 2],
}
with pytest.raises(ValueError):
theIndex._checkFileMeta()
# Type of Entry 3
theIndex._fileMeta = {
"53b69b83cdafc": ["H0", 72, 15, 2],
"974e400180a99": ["H0", 210, 40, "2"],
}
with pytest.raises(ValueError):
theIndex._checkFileMeta()
# END Test testCoreIndex_CheckFileMeta
@pytest.mark.core
def testCoreIndex_CountWords():
"""Test the word counter and the exclusion filers.
+2 -2
View File
@@ -47,8 +47,8 @@ def testGuiViewer_Main(qtbot, monkeypatch, nwGUI, nwLipsum):
# Rebuild the index
nwGUI.mainMenu.aRebuildIndex.activate(QAction.Trigger)
assert nwGUI.theProject.index._tagIndex != {}
assert nwGUI.theProject.index._refIndex != {}
assert nwGUI.theProject.index._tags != {}
assert nwGUI.theProject.index._items != {}
# Select a document in the project tree
nwGUI.treeView.setSelectedHandle("88243afbe5ed8")