From 821833df8ec17c4d638cf6dbfdfe26f76ee21e5b Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sat, 23 Apr 2022 17:05:29 +0200 Subject: [PATCH] Fix tests and drop unused function from NWTree class --- novelwriter/core/tree.py | 24 ------------------- .../guiEditor_Main_Final_nwProject.nwx | 4 ++-- tests/test_base/test_base_common.py | 16 ++++++++++++- tests/test_core/test_core_item.py | 6 +++-- tests/test_core/test_core_tree.py | 12 +++------- 5 files changed, 24 insertions(+), 38 deletions(-) diff --git a/novelwriter/core/tree.py b/novelwriter/core/tree.py index eb349bf8..ee57e0db 100644 --- a/novelwriter/core/tree.py +++ b/novelwriter/core/tree.py @@ -351,30 +351,6 @@ class NWTree(): return True - ## - # Getters - ## - - def countTypes(self): - """Count the number of files, folders and roots in the project. - """ - nRoot = 0 - nFolder = 0 - nFile = 0 - - for tHandle in self._treeOrder: - tItem = self.__getitem__(tHandle) - if tItem is None: - continue - elif tItem.itemType == nwItemType.ROOT: - nRoot += 1 - elif tItem.itemType == nwItemType.FOLDER: - nFolder += 1 - elif tItem.itemType == nwItemType.FILE: - nFile += 1 - - return nRoot, nFolder, nFile - ## # Meta Methods ## diff --git a/tests/reference/guiEditor_Main_Final_nwProject.nwx b/tests/reference/guiEditor_Main_Final_nwProject.nwx index 61abe4f3..e29290ca 100644 --- a/tests/reference/guiEditor_Main_Final_nwProject.nwx +++ b/tests/reference/guiEditor_Main_Final_nwProject.nwx @@ -1,5 +1,5 @@ - + New Project @@ -84,7 +84,7 @@ New Note - + Trash diff --git a/tests/test_base/test_base_common.py b/tests/test_base/test_base_common.py index d7ad4119..0ce153b4 100644 --- a/tests/test_base/test_base_common.py +++ b/tests/test_base/test_base_common.py @@ -161,6 +161,7 @@ def testBaseCommon_IsItemClass(): assert isItemClass("ARCHIVE") is True assert isItemClass("TRASH") is True + # Invalid assert isItemClass("None") is False assert isItemClass(None) is False assert isItemClass("STUFF") is False @@ -176,8 +177,11 @@ def testBaseCommon_IsItemType(): assert isItemType("ROOT") is True assert isItemType("FOLDER") is True assert isItemType("FILE") is True - assert isItemType("TRASH") is True + # Deprecated Type + assert isItemType("TRASH") is False + + # Invalid assert isItemType("None") is False assert isItemType(None) is False assert isItemType("STUFF") is False @@ -193,6 +197,16 @@ def testBaseCommon_IsItemLayout(): assert isItemLayout("DOCUMENT") is True assert isItemLayout("NOTE") is True + # Deprecated Layouts + assert isItemLayout("TITLE") is False + assert isItemLayout("PAGE") is False + assert isItemLayout("BOOK") is False + assert isItemLayout("PARTITION") is False + assert isItemLayout("UNNUMBERED") is False + assert isItemLayout("CHAPTER") is False + assert isItemLayout("SCENE") is False + + # Invalid assert isItemLayout("None") is False assert isItemLayout(None) is False assert isItemLayout("STUFF") is False diff --git a/tests/test_core/test_core_item.py b/tests/test_core/test_core_item.py index dec95cd7..fbc0ded3 100644 --- a/tests/test_core/test_core_item.py +++ b/tests/test_core/test_core_item.py @@ -283,8 +283,6 @@ def testCoreItem_TypeSetter(mockGUI): assert theItem.itemType == nwItemType.FOLDER theItem.setType("FILE") assert theItem.itemType == nwItemType.FILE - theItem.setType("TRASH") - assert theItem.itemType == nwItemType.TRASH # Alternative theItem.setType(nwItemType.ROOT) @@ -712,4 +710,8 @@ def testCoreItem_ConvertFromFmt13(mockGUI): assert theItem.itemType == nwItemType.FILE assert theItem.itemLayout == nwItemLayout.DOCUMENT + # Deprecated Type + theItem.setType("TRASH") + assert theItem.itemType == nwItemType.ROOT + # END Test testCoreItem_ConvertFromFmt13 diff --git a/tests/test_core/test_core_tree.py b/tests/test_core/test_core_tree.py index e8734936..5c05f679 100644 --- a/tests/test_core/test_core_tree.py +++ b/tests/test_core/test_core_tree.py @@ -76,7 +76,7 @@ def mockItems(mockGUI, mockRnd): itemF = NWItem(theProject) itemF._name = "Trash" - itemF._type = nwItemType.TRASH + itemF._type = nwItemType.ROOT itemF._class = nwItemClass.TRASH itemF._expanded = False @@ -172,7 +172,7 @@ def testCoreTree_BuildTree(mockGUI, mockItems): # Try to add another trash folder itemT = NWItem(theProject) itemT._name = "Trash" - itemT._type = nwItemType.TRASH + itemT._type = nwItemType.ROOT itemT._class = nwItemClass.TRASH itemT._expanded = False @@ -353,12 +353,6 @@ def testCoreTree_Stats(mockGUI, mockItems): assert novelWords == 550 assert noteWords == 400 - # Count types - nRoot, nFolder, nFile = theTree.countTypes() - assert nRoot == 3 - assert nFolder == 1 - assert nFile == 3 - # END Test testCoreTree_Stats @@ -429,7 +423,7 @@ def testCoreTree_XMLPackUnpack(mockGUI, mockItems): b'Outtakes' - b'Trash' b'