Use the new index instead of the old
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user