Simplify the class variables of the tree class

This commit is contained in:
Veronica Berglyd Olsen
2023-08-20 21:36:33 +02:00
parent 0b4cfd0037
commit ed3e4bca6c
8 changed files with 81 additions and 88 deletions
+3 -3
View File
@@ -290,7 +290,7 @@ def testCoreTools_DocDuplicator(mockGUI, fncPath, tstPaths, mockRnd):
assert list(dup.duplicate([C.hSceneDoc])) == [
("0000000000010", C.hSceneDoc), # The Scene
]
assert theProject.tree._treeOrder == [
assert theProject.tree._order == [
C.hNovelRoot, C.hPlotRoot, C.hCharRoot, C.hWorldRoot,
C.hTitlePage, C.hChapterDir, C.hChapterDoc, C.hSceneDoc,
"0000000000010",
@@ -311,7 +311,7 @@ def testCoreTools_DocDuplicator(mockGUI, fncPath, tstPaths, mockRnd):
("0000000000012", None), # The Chapter
("0000000000013", None), # The Scene
]
assert theProject.tree._treeOrder == [
assert theProject.tree._order == [
C.hNovelRoot, C.hPlotRoot, C.hCharRoot, C.hWorldRoot,
C.hTitlePage, C.hChapterDir, C.hChapterDoc, C.hSceneDoc,
"0000000000010",
@@ -342,7 +342,7 @@ def testCoreTools_DocDuplicator(mockGUI, fncPath, tstPaths, mockRnd):
("0000000000017", None), # The Chapter
("0000000000018", None), # The Scene
]
assert theProject.tree._treeOrder == [
assert theProject.tree._order == [
C.hNovelRoot, C.hPlotRoot, C.hCharRoot, C.hWorldRoot,
C.hTitlePage, C.hChapterDir, C.hChapterDoc, C.hSceneDoc,
"0000000000010",
+2 -2
View File
@@ -421,8 +421,8 @@ def testCoreDocBuild_Custom(mockGUI, fncPath: Path):
# Add an invalid item to the project
nHandle = "0123456789def"
project.tree._treeOrder.append(nHandle)
project.tree._projTree[nHandle] = None # type: ignore
project.tree._order.append(nHandle)
project.tree._tree[nHandle] = None # type: ignore
docBuild.queueAll()
assert len(docBuild) == 8
+3 -3
View File
@@ -727,7 +727,7 @@ def testCoreIndex_ExtractData(mockGUI, fncPath, mockRnd):
]
# Add a fake handle to the tree and check that it's ignored
theProject.tree._treeOrder.append("0000000000000")
theProject.tree._order.append("0000000000000")
assert [(h, t) for h, t, _ in theIndex._itemIndex.iterNovelStructure(skipExcl=False)] == [
(C.hTitlePage, "T0001"),
(C.hChapterDoc, "T0001"),
@@ -738,7 +738,7 @@ def testCoreIndex_ExtractData(mockGUI, fncPath, mockRnd):
(sHandle, "T0001"),
(tHandle, "T0001"),
]
theProject.tree._treeOrder.remove("0000000000000")
theProject.tree._order.remove("0000000000000")
# Extract stats
assert theIndex.getNovelWordCount(skipExcl=False) == 43
@@ -1077,7 +1077,7 @@ def testCoreIndex_ItemIndex(mockGUI, fncPath, mockRnd):
assert nStruct[0][0] == uHandle
# Inject garbage into tree
theProject.tree._treeOrder.append("stuff")
theProject.tree._order.append("stuff")
nStruct = list(itemIndex.iterNovelStructure())
assert len(nStruct) == 4
assert nStruct[0][0] == nHandle
+1 -1
View File
@@ -328,7 +328,7 @@ def testCoreProject_AccessItems(mockGUI, fncPath, mockRnd):
assert theProject.tree.handles() == newOrder
# Add a non-existing item
theProject.tree._treeOrder.append(C.hInvalid)
theProject.tree._order.append(C.hInvalid)
# Add an item with a non-existent parent
nHandle = theProject.newFile("Test File", C.hChapterDir)
+9 -9
View File
@@ -127,7 +127,7 @@ def testCoreTree_BuildTree(mockGUI, mockItems):
assert theTree.append(nwItem) is True
assert theTree.updateItemData(nwItem.itemHandle) is True
assert theTree._treeChanged is True
assert theTree._changed is True
# Check that tree is not empty (calls __bool__)
assert bool(theTree) is True
@@ -413,9 +413,9 @@ def testCoreTree_Methods(mockGUI, mockItems):
assert roots[3][0] == "a000000000004"
# Add a fake item to root and check that it can handle it
theTree._treeRoots["0000000000000"] = NWItem(theProject, "0000000000000")
theTree._roots["0000000000000"] = NWItem(theProject, "0000000000000")
assert theTree.findRoot(nwItemClass.WORLD) is None
del theTree._treeRoots["0000000000000"]
del theTree._roots["0000000000000"]
# Get item path
assert theTree.getItemPath("stuff") == []
@@ -456,13 +456,13 @@ def testCoreTree_MakeHandles(mockGUI):
random.seed(42)
tHandle = theTree._makeHandle()
assert tHandle == handles[0]
theTree._projTree[handles[0]] = None # type: ignore
theTree._tree[handles[0]] = None # type: ignore
# Add the next in line to the project to force duplicate
theTree._projTree[handles[1]] = None # type: ignore
theTree._tree[handles[1]] = None # type: ignore
tHandle = theTree._makeHandle()
assert tHandle == handles[2]
theTree._projTree[handles[2]] = None # type: ignore
theTree._tree[handles[2]] = None # type: ignore
# Reset the seed to force collissions, which should still end up
# returning the next handle in the sequence
@@ -483,7 +483,7 @@ def testCoreTree_Stats(mockGUI, mockItems):
theTree.append(nwItem)
assert len(theTree) == len(mockItems)
theTree._treeOrder.append("stuff")
theTree._order.append("stuff")
# Count Words
novelWords, noteWords = theTree.sumWords()
@@ -520,7 +520,7 @@ def testCoreTree_Reorder(caplog, mockGUI, mockItems):
assert "Handle 'stuff' in new tree order is not in old order" in caplog.text
caplog.clear()
theTree._treeOrder.append("stuff")
theTree._order.append("stuff")
theTree.setOrder(bHandle)
assert theTree.handles() == bHandle
assert "Handle 'stuff' in old tree order is not in new order" in caplog.text
@@ -539,7 +539,7 @@ def testCoreTree_ToCFile(monkeypatch, fncPath, mockGUI, mockItems):
theTree.updateItemData(nwItem.itemHandle)
assert len(theTree) == len(mockItems)
theTree._treeOrder.append("stuff")
theTree._order.append("stuff")
def mockIsFile(fileName):
"""Return True for items that are files in novelWriter and
+4 -4
View File
@@ -203,8 +203,8 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd):
assert nwGUI.closeProject()
assert len(SHARED.project.tree) == 0
assert len(SHARED.project.tree._treeOrder) == 0
assert len(SHARED.project.tree._treeRoots) == 0
assert len(SHARED.project.tree._order) == 0
assert len(SHARED.project.tree._roots) == 0
assert SHARED.project.tree.trashRoot() is None
assert SHARED.project.data.name == ""
assert SHARED.project.data.title == ""
@@ -223,8 +223,8 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd):
# Check that we loaded the data
assert len(SHARED.project.tree) == 8
assert len(SHARED.project.tree._treeOrder) == 8
assert len(SHARED.project.tree._treeRoots) == 4
assert len(SHARED.project.tree._order) == 8
assert len(SHARED.project.tree._roots) == 4
assert SHARED.project.tree.trashRoot() is None
assert SHARED.project.data.name == "New Project"
assert SHARED.project.data.title == "New Novel"
+5 -5
View File
@@ -260,19 +260,19 @@ def testGuiProjTree_MoveItems(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
# ===========
projView.setSelectedHandle(C.hNovelRoot)
assert SHARED.project.tree._treeOrder.index(C.hNovelRoot) == 0
assert SHARED.project.tree._order.index(C.hNovelRoot) == 0
# Move novel folder up
assert projTree.moveTreeItem(-1) is False
assert SHARED.project.tree._treeOrder.index(C.hNovelRoot) == 0
assert SHARED.project.tree._order.index(C.hNovelRoot) == 0
# Move novel folder down
assert projTree.moveTreeItem(1) is True
assert SHARED.project.tree._treeOrder.index(C.hNovelRoot) == 1
assert SHARED.project.tree._order.index(C.hNovelRoot) == 1
# Move novel folder up again
assert projTree.moveTreeItem(-1) is True
assert SHARED.project.tree._treeOrder.index(C.hNovelRoot) == 0
assert SHARED.project.tree._order.index(C.hNovelRoot) == 0
# Clean up
# qtbot.stop()
@@ -881,7 +881,7 @@ def testGuiProjTree_Duplicate(qtbot, monkeypatch, nwGUI: GuiMain, projPath, mock
assert len(SHARED.project.tree) == 21
# Check tree order that all items are next to eachother
assert SHARED.project.tree._treeOrder == [
assert SHARED.project.tree._order == [
C.hNovelRoot, C.hTitlePage, "0000000000010", C.hChapterDir, C.hChapterDoc, C.hSceneDoc,
"0000000000011", "0000000000012", "0000000000013", "0000000000014", "0000000000015",
"0000000000016", "0000000000017", "0000000000018", "0000000000019", "000000000001a",