Merge branch 'dev' into item_layouts
This commit is contained in:
@@ -26,7 +26,8 @@ import pytest
|
||||
from nw.common import (
|
||||
checkString, checkBool, checkInt, colRange, formatInt, transferCase,
|
||||
fuzzyTime, checkHandle, formatTimeStamp, formatTime, hexToInt,
|
||||
makeFileNameSafe
|
||||
makeFileNameSafe, isHandle, isTitleTag, isItemClass, isItemType,
|
||||
isItemLayout
|
||||
)
|
||||
from tools import cmpList
|
||||
|
||||
@@ -88,6 +89,95 @@ def testBaseCommon_CheckHandle():
|
||||
|
||||
# END Test testBaseCommon_CheckHandle
|
||||
|
||||
@pytest.mark.base
|
||||
def testBaseCommon_IsHandle():
|
||||
"""Test the isHandle function.
|
||||
"""
|
||||
assert isHandle("47666c91c7ccf")
|
||||
|
||||
assert not isHandle("47666C91C7CCF")
|
||||
assert not isHandle("h7666c91c7ccf")
|
||||
assert not isHandle("None")
|
||||
assert not isHandle(None)
|
||||
assert not isHandle("STUFF")
|
||||
|
||||
# END Test testBaseCommon_IsHandle
|
||||
|
||||
@pytest.mark.base
|
||||
def testBaseCommon_IsTitleTag():
|
||||
"""Test the isItemClass function.
|
||||
"""
|
||||
assert isTitleTag("T123456")
|
||||
|
||||
assert not isTitleTag("t123456")
|
||||
assert not isTitleTag("S123456")
|
||||
assert not isTitleTag("T12345A")
|
||||
assert not isTitleTag("T1234567")
|
||||
|
||||
assert not isTitleTag("None")
|
||||
assert not isTitleTag(None)
|
||||
assert not isTitleTag("STUFF")
|
||||
|
||||
# END Test testBaseCommon_IsTitleTag
|
||||
|
||||
@pytest.mark.base
|
||||
def testBaseCommon_IsItemClass():
|
||||
"""Test the isItemClass function.
|
||||
"""
|
||||
assert isItemClass("NO_CLASS")
|
||||
assert isItemClass("NOVEL")
|
||||
assert isItemClass("PLOT")
|
||||
assert isItemClass("CHARACTER")
|
||||
assert isItemClass("WORLD")
|
||||
assert isItemClass("TIMELINE")
|
||||
assert isItemClass("OBJECT")
|
||||
assert isItemClass("ENTITY")
|
||||
assert isItemClass("CUSTOM")
|
||||
assert isItemClass("ARCHIVE")
|
||||
assert isItemClass("TRASH")
|
||||
|
||||
assert not isItemClass("None")
|
||||
assert not isItemClass(None)
|
||||
assert not isItemClass("STUFF")
|
||||
|
||||
# END Test testBaseCommon_IsItemClass
|
||||
|
||||
@pytest.mark.base
|
||||
def testBaseCommon_IsItemType():
|
||||
"""Test the isItemType function.
|
||||
"""
|
||||
assert isItemType("NO_TYPE")
|
||||
assert isItemType("ROOT")
|
||||
assert isItemType("FOLDER")
|
||||
assert isItemType("FILE")
|
||||
assert isItemType("TRASH")
|
||||
|
||||
assert not isItemType("None")
|
||||
assert not isItemType(None)
|
||||
assert not isItemType("STUFF")
|
||||
|
||||
# END Test testBaseCommon_IsItemType
|
||||
|
||||
@pytest.mark.base
|
||||
def testBaseCommon_IsItemLayout():
|
||||
"""Test the isItemLayout function.
|
||||
"""
|
||||
assert isItemLayout("NO_LAYOUT")
|
||||
assert isItemLayout("TITLE")
|
||||
assert isItemLayout("BOOK")
|
||||
assert isItemLayout("PAGE")
|
||||
assert isItemLayout("PARTITION")
|
||||
assert isItemLayout("UNNUMBERED")
|
||||
assert isItemLayout("CHAPTER")
|
||||
assert isItemLayout("SCENE")
|
||||
assert isItemLayout("NOTE")
|
||||
|
||||
assert not isItemLayout("None")
|
||||
assert not isItemLayout(None)
|
||||
assert not isItemLayout("STUFF")
|
||||
|
||||
# END Test testBaseCommon_IsItemLayout
|
||||
|
||||
@pytest.mark.base
|
||||
def testBaseCommon_HexToInt():
|
||||
"""Test the hexToInt function.
|
||||
|
||||
@@ -115,38 +115,7 @@ def testCoreIndex_LoadSave(monkeypatch, nwLipsum, dummyGUI, outDir, refDir):
|
||||
|
||||
# Break the index and check that we notice
|
||||
assert not theIndex.indexBroken
|
||||
theIndex._tagIndex["Bod"].append("Stuff") # No longer len() == 4
|
||||
theIndex.checkIndex()
|
||||
assert theIndex.indexBroken
|
||||
|
||||
assert theIndex.loadIndex()
|
||||
assert not theIndex.indexBroken
|
||||
theIndex._refIndex["fb609cd8319dc"]["T000001"]["tags"].append("Stuff") # No longer len() == 3
|
||||
theIndex.checkIndex()
|
||||
assert theIndex.indexBroken
|
||||
|
||||
assert theIndex.loadIndex()
|
||||
assert not theIndex.indexBroken
|
||||
theIndex._novelIndex["7a992350f3eb6"]["T000001"]["Stuff"] = "" # No longer len(keys()) == 8
|
||||
theIndex.checkIndex()
|
||||
assert theIndex.indexBroken
|
||||
|
||||
assert theIndex.loadIndex()
|
||||
assert not theIndex.indexBroken
|
||||
theIndex._noteIndex["4c4f28287af27"]["T000001"]["Stuff"] = "" # No longer len(keys()) == 8
|
||||
theIndex.checkIndex()
|
||||
assert theIndex.indexBroken
|
||||
|
||||
assert theIndex.loadIndex()
|
||||
assert not theIndex.indexBroken
|
||||
theIndex._textCounts["7a992350f3eb6"].append("Stuff") # No longer len() == 3
|
||||
theIndex.checkIndex()
|
||||
assert theIndex.indexBroken
|
||||
|
||||
# Make the try/except trigger as well
|
||||
assert theIndex.loadIndex()
|
||||
assert not theIndex.indexBroken
|
||||
theIndex._refIndex["fb609cd8319dc"]["T000001"] = {"tagssss": []} # Wrong key name
|
||||
theIndex._tagIndex["Bod"].append("Stuff")
|
||||
theIndex.checkIndex()
|
||||
assert theIndex.indexBroken
|
||||
|
||||
@@ -676,3 +645,503 @@ def testCoreIndex_ExtractData(nwMinimal, dummyGUI):
|
||||
assert theProject.closeProject()
|
||||
|
||||
# END Test testCoreIndex_ExtractData
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreIndex_CheckTagIndex(dummyGUI):
|
||||
"""Test the tag index checker.
|
||||
"""
|
||||
theProject = NWProject(dummyGUI)
|
||||
theIndex = NWIndex(theProject, dummyGUI)
|
||||
|
||||
# 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(dummyGUI):
|
||||
"""Test the reference index checker.
|
||||
"""
|
||||
theProject = NWProject(dummyGUI)
|
||||
theIndex = NWIndex(theProject, dummyGUI)
|
||||
|
||||
# Valid Index
|
||||
theIndex._refIndex = {
|
||||
"6a2d6d5f4f401": {
|
||||
"T000000": {"tags": [], "updated": 1611922868},
|
||||
"T000001": {"tags": [
|
||||
[3, "@pov", "Jane"], [4, "@location", "Earth"]
|
||||
], "updated": 1611922868}
|
||||
}
|
||||
}
|
||||
assert theIndex._checkRefIndex() is None
|
||||
|
||||
# Invalid Handle
|
||||
theIndex._refIndex = {
|
||||
"Ha2d6d5f4f401": {
|
||||
"T000000": {"tags": [], "updated": 1611922868},
|
||||
"T000001": {"tags": [
|
||||
[3, "@pov", "Jane"], [4, "@location", "Earth"]
|
||||
], "updated": 1611922868}
|
||||
}
|
||||
}
|
||||
with pytest.raises(KeyError):
|
||||
theIndex._checkRefIndex()
|
||||
|
||||
# Invalid Title
|
||||
theIndex._refIndex = {
|
||||
"6a2d6d5f4f401": {
|
||||
"T000000": {"tags": [], "updated": 1611922868},
|
||||
"INVALID": {"tags": [
|
||||
[3, "@pov", "Jane"], [4, "@location", "Earth"]
|
||||
], "updated": 1611922868}
|
||||
}
|
||||
}
|
||||
with pytest.raises(KeyError):
|
||||
theIndex._checkRefIndex()
|
||||
|
||||
# Missing 'tags'
|
||||
theIndex._refIndex = {
|
||||
"6a2d6d5f4f401": {
|
||||
"T000000": {"tags": [], "updated": 1611922868},
|
||||
"T000001": {"updated": 1611922868}
|
||||
}
|
||||
}
|
||||
with pytest.raises(KeyError):
|
||||
theIndex._checkRefIndex()
|
||||
|
||||
# Wrong Length of 'tags'
|
||||
theIndex._refIndex = {
|
||||
"6a2d6d5f4f401": {
|
||||
"T000000": {"tags": [], "updated": 1611922868},
|
||||
"T000001": {"tags": [
|
||||
[3, "@pov", "Jane"], [4, "@location", "Earth", "Stuff"]
|
||||
], "updated": 1611922868}
|
||||
}
|
||||
}
|
||||
with pytest.raises(IndexError):
|
||||
theIndex._checkRefIndex()
|
||||
|
||||
# Wrong Type of 'tags' Entry 0
|
||||
theIndex._refIndex = {
|
||||
"6a2d6d5f4f401": {
|
||||
"T000000": {"tags": [], "updated": 1611922868},
|
||||
"T000001": {"tags": [
|
||||
[3, "@pov", "Jane"], ["4", "@location", "Earth"]
|
||||
], "updated": 1611922868}
|
||||
}
|
||||
}
|
||||
with pytest.raises(ValueError):
|
||||
theIndex._checkRefIndex()
|
||||
|
||||
# Wrong Type of 'tags' Entry 1
|
||||
theIndex._refIndex = {
|
||||
"6a2d6d5f4f401": {
|
||||
"T000000": {"tags": [], "updated": 1611922868},
|
||||
"T000001": {"tags": [
|
||||
[3, "@pov", "Jane"], [4, "@stuff", "Earth"]
|
||||
], "updated": 1611922868}
|
||||
}
|
||||
}
|
||||
with pytest.raises(ValueError):
|
||||
theIndex._checkRefIndex()
|
||||
|
||||
# Wrong Type of 'tags' Entry 1
|
||||
theIndex._refIndex = {
|
||||
"6a2d6d5f4f401": {
|
||||
"T000000": {"tags": [], "updated": 1611922868},
|
||||
"T000001": {"tags": [
|
||||
[3, "@pov", "Jane"], [4, "@location", 123456]
|
||||
], "updated": 1611922868}
|
||||
}
|
||||
}
|
||||
with pytest.raises(ValueError):
|
||||
theIndex._checkRefIndex()
|
||||
|
||||
# Missing 'updated'
|
||||
theIndex._refIndex = {
|
||||
"6a2d6d5f4f401": {
|
||||
"T000000": {"tags": [], "updated": 1611922868},
|
||||
"T000001": {"tags": []}
|
||||
}
|
||||
}
|
||||
with pytest.raises(KeyError):
|
||||
theIndex._checkRefIndex()
|
||||
|
||||
# Wrong Type of 'updated' Entry 1
|
||||
theIndex._refIndex = {
|
||||
"6a2d6d5f4f401": {
|
||||
"T000000": {"tags": [], "updated": 1611922868},
|
||||
"T000001": {"tags": [], "updated": "1611922868"}
|
||||
}
|
||||
}
|
||||
with pytest.raises(ValueError):
|
||||
theIndex._checkRefIndex()
|
||||
|
||||
# END Test testCoreIndex_CheckRefIndex
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreIndex_CheckNovelNoteIndex(dummyGUI):
|
||||
"""Test the novel and note index checkers.
|
||||
"""
|
||||
theProject = NWProject(dummyGUI)
|
||||
theIndex = NWIndex(theProject, dummyGUI)
|
||||
|
||||
# Valid Index
|
||||
theIndex._novelIndex = {
|
||||
"53b69b83cdafc": {
|
||||
"T000001": {
|
||||
"level": "H1", "title": "My Novel", "layout": "TITLE", "synopsis": "text",
|
||||
"cCount": 72, "wCount": 15, "pCount": 2, "updated": 1611922868
|
||||
}
|
||||
}
|
||||
}
|
||||
theIndex._noteIndex = theIndex._novelIndex.copy()
|
||||
assert theIndex._checkNovelNoteIndex("novelIndex") is None
|
||||
assert theIndex._checkNovelNoteIndex("noteIndex") is None
|
||||
with pytest.raises(IndexError):
|
||||
theIndex._checkNovelNoteIndex("notAnIndex")
|
||||
|
||||
# Invalid Handle
|
||||
theIndex._novelIndex = {
|
||||
"H3b69b83cdafc": {
|
||||
"T000001": {
|
||||
"level": "H1", "title": "My Novel", "layout": "TITLE", "synopsis": "text",
|
||||
"cCount": 72, "wCount": 15, "pCount": 2, "updated": 1611922868
|
||||
}
|
||||
}
|
||||
}
|
||||
with pytest.raises(KeyError):
|
||||
theIndex._checkNovelNoteIndex("novelIndex")
|
||||
|
||||
# Invalid Title
|
||||
theIndex._novelIndex = {
|
||||
"53b69b83cdafc": {
|
||||
"INVALID": {
|
||||
"level": "H1", "title": "My Novel", "layout": "TITLE", "synopsis": "text",
|
||||
"cCount": 72, "wCount": 15, "pCount": 2, "updated": 1611922868
|
||||
}
|
||||
}
|
||||
}
|
||||
with pytest.raises(KeyError):
|
||||
theIndex._checkNovelNoteIndex("novelIndex")
|
||||
|
||||
# Wrong Length
|
||||
theIndex._novelIndex = {
|
||||
"53b69b83cdafc": {
|
||||
"T000001": {
|
||||
"level": "H1", "title": "My Novel", "layout": "TITLE", "synopsis": "text",
|
||||
"cCount": 72, "wCount": 15, "pCount": 2, "updated": 1611922868, "stuff": None
|
||||
}
|
||||
}
|
||||
}
|
||||
with pytest.raises(IndexError):
|
||||
theIndex._checkNovelNoteIndex("novelIndex")
|
||||
|
||||
# Missing Keys
|
||||
# ============
|
||||
|
||||
# Missing 'level'
|
||||
theIndex._novelIndex = {
|
||||
"53b69b83cdafc": {
|
||||
"T000001": {
|
||||
"stuff": "H1", "title": "My Novel", "layout": "TITLE", "synopsis": "text",
|
||||
"cCount": 72, "wCount": 15, "pCount": 2, "updated": 1611922868
|
||||
}
|
||||
}
|
||||
}
|
||||
with pytest.raises(KeyError):
|
||||
theIndex._checkNovelNoteIndex("novelIndex")
|
||||
|
||||
# Missing 'title'
|
||||
theIndex._novelIndex = {
|
||||
"53b69b83cdafc": {
|
||||
"T000001": {
|
||||
"level": "H1", "stuff": "My Novel", "layout": "TITLE", "synopsis": "text",
|
||||
"cCount": 72, "wCount": 15, "pCount": 2, "updated": 1611922868
|
||||
}
|
||||
}
|
||||
}
|
||||
with pytest.raises(KeyError):
|
||||
theIndex._checkNovelNoteIndex("novelIndex")
|
||||
|
||||
# Missing 'layout'
|
||||
theIndex._novelIndex = {
|
||||
"53b69b83cdafc": {
|
||||
"T000001": {
|
||||
"level": "H1", "title": "My Novel", "stuff": "TITLE", "synopsis": "text",
|
||||
"cCount": 72, "wCount": 15, "pCount": 2, "updated": 1611922868
|
||||
}
|
||||
}
|
||||
}
|
||||
with pytest.raises(KeyError):
|
||||
theIndex._checkNovelNoteIndex("novelIndex")
|
||||
|
||||
# Missing 'synopsis'
|
||||
theIndex._novelIndex = {
|
||||
"53b69b83cdafc": {
|
||||
"T000001": {
|
||||
"level": "H1", "title": "My Novel", "layout": "TITLE", "stuff": "text",
|
||||
"cCount": 72, "wCount": 15, "pCount": 2, "updated": 1611922868
|
||||
}
|
||||
}
|
||||
}
|
||||
with pytest.raises(KeyError):
|
||||
theIndex._checkNovelNoteIndex("novelIndex")
|
||||
|
||||
# Missing 'cCount'
|
||||
theIndex._novelIndex = {
|
||||
"53b69b83cdafc": {
|
||||
"T000001": {
|
||||
"level": "H1", "title": "My Novel", "layout": "TITLE", "synopsis": "text",
|
||||
"stuff": 72, "wCount": 15, "pCount": 2, "updated": 1611922868
|
||||
}
|
||||
}
|
||||
}
|
||||
with pytest.raises(KeyError):
|
||||
theIndex._checkNovelNoteIndex("novelIndex")
|
||||
|
||||
# Missing 'wCount'
|
||||
theIndex._novelIndex = {
|
||||
"53b69b83cdafc": {
|
||||
"T000001": {
|
||||
"level": "H1", "title": "My Novel", "layout": "TITLE", "synopsis": "text",
|
||||
"cCount": 72, "stuff": 15, "pCount": 2, "updated": 1611922868
|
||||
}
|
||||
}
|
||||
}
|
||||
with pytest.raises(KeyError):
|
||||
theIndex._checkNovelNoteIndex("novelIndex")
|
||||
|
||||
# Missing 'pCount'
|
||||
theIndex._novelIndex = {
|
||||
"53b69b83cdafc": {
|
||||
"T000001": {
|
||||
"level": "H1", "title": "My Novel", "layout": "TITLE", "synopsis": "text",
|
||||
"cCount": 72, "wCount": 15, "stuff": 2, "updated": 1611922868
|
||||
}
|
||||
}
|
||||
}
|
||||
with pytest.raises(KeyError):
|
||||
theIndex._checkNovelNoteIndex("novelIndex")
|
||||
|
||||
# Missing 'updated'
|
||||
theIndex._novelIndex = {
|
||||
"53b69b83cdafc": {
|
||||
"T000001": {
|
||||
"level": "H1", "title": "My Novel", "layout": "TITLE", "synopsis": "text",
|
||||
"cCount": 72, "wCount": 15, "pCount": 2, "stuff": 1611922868
|
||||
}
|
||||
}
|
||||
}
|
||||
with pytest.raises(KeyError):
|
||||
theIndex._checkNovelNoteIndex("novelIndex")
|
||||
|
||||
# Wrong Types
|
||||
# ===========
|
||||
|
||||
# Wrong Type for 'level'
|
||||
theIndex._novelIndex = {
|
||||
"53b69b83cdafc": {
|
||||
"T000001": {
|
||||
"level": "XX", "title": "My Novel", "layout": "TITLE", "synopsis": "text",
|
||||
"cCount": 72, "wCount": 15, "pCount": 2, "updated": 1611922868
|
||||
}
|
||||
}
|
||||
}
|
||||
with pytest.raises(ValueError):
|
||||
theIndex._checkNovelNoteIndex("novelIndex")
|
||||
|
||||
# Wrong Type for 'title'
|
||||
theIndex._novelIndex = {
|
||||
"53b69b83cdafc": {
|
||||
"T000001": {
|
||||
"level": "H1", "title": 12345678, "layout": "TITLE", "synopsis": "text",
|
||||
"cCount": 72, "wCount": 15, "pCount": 2, "updated": 1611922868
|
||||
}
|
||||
}
|
||||
}
|
||||
with pytest.raises(ValueError):
|
||||
theIndex._checkNovelNoteIndex("novelIndex")
|
||||
|
||||
# Wrong Type for 'layout'
|
||||
theIndex._novelIndex = {
|
||||
"53b69b83cdafc": {
|
||||
"T000001": {
|
||||
"level": "H1", "title": "My Novel", "layout": "INVALID", "synopsis": "text",
|
||||
"cCount": 72, "wCount": 15, "pCount": 2, "updated": 1611922868
|
||||
}
|
||||
}
|
||||
}
|
||||
with pytest.raises(ValueError):
|
||||
theIndex._checkNovelNoteIndex("novelIndex")
|
||||
|
||||
# Wrong Type for 'synopsis'
|
||||
theIndex._novelIndex = {
|
||||
"53b69b83cdafc": {
|
||||
"T000001": {
|
||||
"level": "H1", "title": "My Novel", "layout": "TITLE", "synopsis": 123456,
|
||||
"cCount": 72, "wCount": 15, "pCount": 2, "updated": 1611922868
|
||||
}
|
||||
}
|
||||
}
|
||||
with pytest.raises(ValueError):
|
||||
theIndex._checkNovelNoteIndex("novelIndex")
|
||||
|
||||
# Wrong Type for 'cCount'
|
||||
theIndex._novelIndex = {
|
||||
"53b69b83cdafc": {
|
||||
"T000001": {
|
||||
"level": "H1", "title": "My Novel", "layout": "TITLE", "synopsis": "text",
|
||||
"cCount": "72", "wCount": 15, "pCount": 2, "updated": 1611922868
|
||||
}
|
||||
}
|
||||
}
|
||||
with pytest.raises(ValueError):
|
||||
theIndex._checkNovelNoteIndex("novelIndex")
|
||||
|
||||
# Wrong Type for 'wCount'
|
||||
theIndex._novelIndex = {
|
||||
"53b69b83cdafc": {
|
||||
"T000001": {
|
||||
"level": "H1", "title": "My Novel", "layout": "TITLE", "synopsis": "text",
|
||||
"cCount": 72, "wCount": "15", "pCount": 2, "updated": 1611922868
|
||||
}
|
||||
}
|
||||
}
|
||||
with pytest.raises(ValueError):
|
||||
theIndex._checkNovelNoteIndex("novelIndex")
|
||||
|
||||
# Wrong Type for 'pCount'
|
||||
theIndex._novelIndex = {
|
||||
"53b69b83cdafc": {
|
||||
"T000001": {
|
||||
"level": "H1", "title": "My Novel", "layout": "TITLE", "synopsis": "text",
|
||||
"cCount": 72, "wCount": 15, "pCount": "2", "updated": 1611922868
|
||||
}
|
||||
}
|
||||
}
|
||||
with pytest.raises(ValueError):
|
||||
theIndex._checkNovelNoteIndex("novelIndex")
|
||||
|
||||
# Wrong Type for 'updated'
|
||||
theIndex._novelIndex = {
|
||||
"53b69b83cdafc": {
|
||||
"T000001": {
|
||||
"level": "H1", "title": "My Novel", "layout": "TITLE", "synopsis": "text",
|
||||
"cCount": 72, "wCount": 15, "pCount": 2, "updated": "1611922868"
|
||||
}
|
||||
}
|
||||
}
|
||||
with pytest.raises(ValueError):
|
||||
theIndex._checkNovelNoteIndex("novelIndex")
|
||||
|
||||
# END Test testCoreIndex_CheckNovelNoteIndex
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreIndex_CheckTextCounts(dummyGUI):
|
||||
"""Test the text counts checker.
|
||||
"""
|
||||
theProject = NWProject(dummyGUI)
|
||||
theIndex = NWIndex(theProject, dummyGUI)
|
||||
|
||||
# Valid Index
|
||||
theIndex._textCounts = {
|
||||
"53b69b83cdafc": [72, 15, 2],
|
||||
"974e400180a99": [210, 40, 2],
|
||||
}
|
||||
assert theIndex._checkTextCounts() is None
|
||||
|
||||
# Invalid Handle
|
||||
theIndex._textCounts = {
|
||||
"53b69b83cdafc": [72, 15, 2],
|
||||
"h74e400180a99": [210, 40, 2],
|
||||
}
|
||||
with pytest.raises(KeyError):
|
||||
theIndex._checkTextCounts()
|
||||
|
||||
# Wrong Length
|
||||
theIndex._textCounts = {
|
||||
"53b69b83cdafc": [72, 15, 2],
|
||||
"974e400180a99": [210, 40, 2, 8],
|
||||
}
|
||||
with pytest.raises(IndexError):
|
||||
theIndex._checkTextCounts()
|
||||
|
||||
# Type of Entry 0
|
||||
theIndex._textCounts = {
|
||||
"53b69b83cdafc": [72, 15, 2],
|
||||
"974e400180a99": ["210", 40, 2],
|
||||
}
|
||||
with pytest.raises(ValueError):
|
||||
theIndex._checkTextCounts()
|
||||
|
||||
# Type of Entry 1
|
||||
theIndex._textCounts = {
|
||||
"53b69b83cdafc": [72, 15, 2],
|
||||
"974e400180a99": [210, "40", 2],
|
||||
}
|
||||
with pytest.raises(ValueError):
|
||||
theIndex._checkTextCounts()
|
||||
|
||||
# Type of Entry 2
|
||||
theIndex._textCounts = {
|
||||
"53b69b83cdafc": [72, 15, 2],
|
||||
"974e400180a99": [210, 40, "2"],
|
||||
}
|
||||
with pytest.raises(ValueError):
|
||||
theIndex._checkTextCounts()
|
||||
|
||||
# END Test testCoreIndex_CheckTextCounts
|
||||
|
||||
Reference in New Issue
Block a user