Merge branch 'main' into release_1.3.1

This commit is contained in:
Veronica K. B. Olsen
2021-05-06 22:08:11 +02:00
3 changed files with 19 additions and 5 deletions
+3 -1
View File
@@ -77,6 +77,7 @@ class NWTree():
self._treeChanged = False # True if tree structure has changed
self._handleSeed = None # Used for generating handles for testing
self._handleCount = 0 # A counter that is added to the handle generator
return
@@ -515,7 +516,8 @@ class NWTree():
handle requests come faster than the clock resolution.
"""
if self._handleSeed is None:
newSeed = str(time()) + addSeed
newSeed = "%s_%d_%s" % (str(time()), self._handleCount, addSeed)
self._handleCount += 1
else:
# This is used for debugging
newSeed = str(self._handleSeed)
+1 -1
View File
@@ -371,9 +371,9 @@ class GuiMain(QMainWindow):
logger.info("Creating new project")
if self.theProject.newProject(projData):
self.hasProject = True
self.rebuildTrees()
self.saveProject()
self.hasProject = True
self.docEditor.setDictionaries()
self.rebuildIndex(beQuiet=True)
self.statusBar.setRefTime(self.theProject.projOpened)
+15 -3
View File
@@ -24,6 +24,7 @@ import os
import pytest
from lxml import etree
from hashlib import sha256
from nw.core.project import NWProject, NWItem, NWTree
from nw.enum import nwItemClass, nwItemType, nwItemLayout
@@ -394,22 +395,33 @@ def testCoreTree_MakeHandles(monkeypatch, dummyGUI):
tHandle = theTree._makeHandle()
assert tHandle == "73475cb40a568"
# Add the next in line to the project to foprce duplicate
# Add the next in line to the project to force duplicate
theTree._projTree["44cb730c42048"] = None
tHandle = theTree._makeHandle()
assert tHandle == "71ee45a3c0db9"
# Fix the time() function and force a handle collission
theTree.setSeed(None)
theTree._handleCount = 0
monkeypatch.setattr("nw.core.tree.time", lambda: 123.4)
tHandle = theTree._makeHandle()
theTree._projTree[tHandle] = None
assert tHandle == "5f466d7afa48b"
newSeed = "123.4_0_"
assert tHandle == sha256(newSeed.encode()).hexdigest()[0:13]
tHandle = theTree._makeHandle()
theTree._projTree[tHandle] = None
assert tHandle == "a79acf4c634a7"
newSeed = "123.4_1_"
assert tHandle == sha256(newSeed.encode()).hexdigest()[0:13]
# Reset the count and the handle for 0 and 1 should be duplicates
# which forces the function to add the '!'
theTree._handleCount = 0
tHandle = theTree._makeHandle()
theTree._projTree[tHandle] = None
newSeed = "123.4_1_!"
assert tHandle == sha256(newSeed.encode()).hexdigest()[0:13]
# END Test testCoreTree_MakeHandles