def testCoreTree_Reorder(dummyGUI, dummyItems): """Test changing tree order. """ theProject = NWProject(dummyGUI) theTree = NWTree(theProject) aHandle = [] for tHandle, pHande, nwItem in dummyItems: aHandle.append(tHandle) theTree.append(tHandle, pHande, nwItem) assert len(theTree) == len(dummyItems) bHandle = aHandle.copy() bHandle[2], bHandle[3] = bHandle[3], bHandle[2] assert aHandle != bHandle assert theTree.handles() == aHandle theTree.setOrder(bHandle) assert theTree.handles() == bHandle theTree.setOrder(bHandle + ["dummy"]) assert theTree.handles() == bHandle theTree._treeOrder.append("dummy") theTree.setOrder(bHandle) assert theTree.handles() == bHandle
def testCoreTree_BuildTree(dummyGUI, dummyItems): """Test building a project tree from a list of items. """ theProject = NWProject(dummyGUI) theTree = NWTree(theProject) theTree.setSeed(42) assert theTree._handleSeed == 42 # Check that tree is empty (calls NWTree.__bool__) assert not theTree # Check for archive and trash folders assert theTree.trashRoot() is None assert theTree.archiveRoot() is None assert not theTree.isTrashRoot("a000000000003") aHandles = [] for tHandle, pHande, nwItem in dummyItems: aHandles.append(tHandle) assert theTree.append(tHandle, pHande, nwItem) assert theTree._treeChanged # Check that tree is not empty (calls __bool__) assert theTree # Check the number of elements (calls __len__) assert len(theTree) == len(dummyItems) # Check that we have the correct handles assert theTree.handles() == aHandles # Check by iterator (calls __iter__, __next__ and __getitem__) for theItem, theHandle in zip(theTree, aHandles): assert theItem.itemHandle == theHandle # Check that we have the correct archive and trash folders assert theTree.trashRoot() == "a000000000003" assert theTree.archiveRoot() == "a000000000002" assert theTree.isTrashRoot("a000000000003") # Try to add another trash folder itemT = NWItem(theProject) itemT.itemName = "Trash" itemT.itemType = nwItemType.TRASH itemT.itemClass = nwItemClass.TRASH itemT.isExpanded = False assert not theTree.append("1234567890abc", None, itemT) assert len(theTree) == len(dummyItems) # Generate handle automatically itemT = NWItem(theProject) itemT.itemName = "New File" itemT.itemType = nwItemType.FILE itemT.itemClass = nwItemClass.NOVEL itemT.itemLayout = nwItemLayout.SCENE assert theTree.append(None, None, itemT) assert len(theTree) == len(dummyItems) + 1 theList = theTree.handles() assert theList[-1] == "73475cb40a568" # Try to add existing handle assert not theTree.append("73475cb40a568", None, itemT) assert len(theTree) == len(dummyItems) + 1 # Delete a non-existing item del theTree["dummy"] assert len(theTree) == len(dummyItems) + 1 # Delete the last item del theTree["73475cb40a568"] assert len(theTree) == len(dummyItems) assert "73475cb40a568" not in theTree # Delete the Novel, Archive and Trash folders del theTree["a000000000001"] assert len(theTree) == len(dummyItems) - 1 assert "a000000000001" not in theTree del theTree["a000000000002"] assert len(theTree) == len(dummyItems) - 2 assert "a000000000002" not in theTree assert theTree.archiveRoot() is None del theTree["a000000000003"] assert len(theTree) == len(dummyItems) - 3 assert "a000000000003" not in theTree assert theTree.trashRoot() is None