Update index check and test

This commit is contained in:
Veronica K. B. Olsen
2021-01-29 20:43:04 +01:00
parent 9486749345
commit b7766946d8
2 changed files with 85 additions and 21 deletions
+19 -4
View File
@@ -220,12 +220,9 @@ class NWIndex():
self._checkNovelNoteIndex("novelIndex")
self._checkNovelNoteIndex("noteIndex")
self._checkTextCounts()
self._checkFirstTitles()
self.indexBroken = False
for tHandle in self._firstTitle:
if len(self._firstTitle[tHandle]) != 2:
self.indexBroken = True
except Exception:
logger.error("Error while checking index")
nw.logException()
@@ -897,4 +894,22 @@ class NWIndex():
return
def _checkFirstTitles(self):
"""Scan the first titles index for errors.
Waring: This function raises exceptions.
"""
for tHandle in self._firstTitle:
if not isHandle(tHandle):
raise KeyError("firstTitle key is not a handle")
tEntry = self._firstTitle[tHandle]
if len(tEntry) != 2:
raise IndexError("firstTitle[a] expected 2 values")
if not tEntry[0] in self.H_VALID:
raise ValueError("firstTitle[a][0] is not a header level")
if not isTitleTag(tEntry[1]):
raise ValueError("firstTitle[a][1] is not a title tag")
return
# END Class NWIndex