Rebuild index when opdating project (#1235)
This commit is contained in:
@@ -90,7 +90,7 @@ def testCoreIndex_LoadSave(monkeypatch, prjLipsum, mockGUI, tstPaths):
|
||||
assert theIndex._tagsIndex._tags == {}
|
||||
assert theIndex._itemIndex._items == {}
|
||||
|
||||
# No folder for sloading
|
||||
# No folder for loading
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr("novelwriter.core.storage.NWStorage.getMetaFile", lambda *a: None)
|
||||
assert theIndex.loadIndex() is False
|
||||
@@ -108,6 +108,13 @@ def testCoreIndex_LoadSave(monkeypatch, prjLipsum, mockGUI, tstPaths):
|
||||
assert str(theIndex._tagsIndex.packData()) == tagIndex
|
||||
assert str(theIndex._itemIndex.packData()) == itemsIndex
|
||||
|
||||
# Rebuild index
|
||||
theIndex.clearIndex()
|
||||
theIndex.rebuildIndex()
|
||||
|
||||
assert str(theIndex._tagsIndex.packData()) == tagIndex
|
||||
assert str(theIndex._itemIndex.packData()) == itemsIndex
|
||||
|
||||
# Check File
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile)
|
||||
|
||||
@@ -230,7 +230,7 @@ def testCoreProject_Open(monkeypatch, caplog, mockGUI, fncPath, mockRnd):
|
||||
assert "The file format of your project is about to be" in mockGUI.lastQuestion[1]
|
||||
mockGUI.askResponse = True
|
||||
|
||||
# Won't convert legacy file
|
||||
# Won't open project from newer version
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr(ProjectXMLReader, "hexVersion", property(lambda *a: 0x99999999))
|
||||
mockGUI.askResponse = False
|
||||
@@ -245,6 +245,18 @@ def testCoreProject_Open(monkeypatch, caplog, mockGUI, fncPath, mockRnd):
|
||||
|
||||
assert theProject.closeProject()
|
||||
|
||||
# Trigger an index rebuild
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr(ProjectXMLReader, "state", property(lambda *a: XMLReadState.WAS_LEGACY))
|
||||
mp.setattr("novelwriter.core.index.NWIndex.loadIndex", lambda *a: True)
|
||||
mockGUI.askResponse = True
|
||||
theProject.index._indexBroken = True
|
||||
assert theProject.openProject(fncPath) is True
|
||||
assert "The file format of your project is about to be" in mockGUI.lastQuestion[1]
|
||||
assert theProject.index._indexBroken is False
|
||||
|
||||
assert theProject.closeProject()
|
||||
|
||||
# END Test testCoreProject_Open
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user