Skip to content

Commit 62630eb

Browse files
committed
Merge branch 'main' into release_1.3.1
2 parents fd4d663 + b1d597e commit 62630eb

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

nw/core/tree.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def __init__(self, theProject):
7777
self._treeChanged = False # True if tree structure has changed
7878

7979
self._handleSeed = None # Used for generating handles for testing
80+
self._handleCount = 0 # A counter that is added to the handle generator
8081

8182
return
8283

@@ -515,7 +516,8 @@ def _makeHandle(self, addSeed=""):
515516
handle requests come faster than the clock resolution.
516517
"""
517518
if self._handleSeed is None:
518-
newSeed = str(time()) + addSeed
519+
newSeed = "%s_%d_%s" % (str(time()), self._handleCount, addSeed)
520+
self._handleCount += 1
519521
else:
520522
# This is used for debugging
521523
newSeed = str(self._handleSeed)

nw/guimain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,9 @@ def newProject(self, projData=None):
371371

372372
logger.info("Creating new project")
373373
if self.theProject.newProject(projData):
374+
self.hasProject = True
374375
self.rebuildTrees()
375376
self.saveProject()
376-
self.hasProject = True
377377
self.docEditor.setDictionaries()
378378
self.rebuildIndex(beQuiet=True)
379379
self.statusBar.setRefTime(self.theProject.projOpened)

tests/test_core/test_core_tree.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import pytest
2525

2626
from lxml import etree
27+
from hashlib import sha256
2728

2829
from nw.core.project import NWProject, NWItem, NWTree
2930
from nw.enum import nwItemClass, nwItemType, nwItemLayout
@@ -394,22 +395,33 @@ def testCoreTree_MakeHandles(monkeypatch, dummyGUI):
394395
tHandle = theTree._makeHandle()
395396
assert tHandle == "73475cb40a568"
396397

397-
# Add the next in line to the project to foprce duplicate
398+
# Add the next in line to the project to force duplicate
398399
theTree._projTree["44cb730c42048"] = None
399400
tHandle = theTree._makeHandle()
400401
assert tHandle == "71ee45a3c0db9"
401402

402403
# Fix the time() function and force a handle collission
403404
theTree.setSeed(None)
405+
theTree._handleCount = 0
404406
monkeypatch.setattr("nw.core.tree.time", lambda: 123.4)
405407

406408
tHandle = theTree._makeHandle()
407409
theTree._projTree[tHandle] = None
408-
assert tHandle == "5f466d7afa48b"
410+
newSeed = "123.4_0_"
411+
assert tHandle == sha256(newSeed.encode()).hexdigest()[0:13]
409412

410413
tHandle = theTree._makeHandle()
411414
theTree._projTree[tHandle] = None
412-
assert tHandle == "a79acf4c634a7"
415+
newSeed = "123.4_1_"
416+
assert tHandle == sha256(newSeed.encode()).hexdigest()[0:13]
417+
418+
# Reset the count and the handle for 0 and 1 should be duplicates
419+
# which forces the function to add the '!'
420+
theTree._handleCount = 0
421+
tHandle = theTree._makeHandle()
422+
theTree._projTree[tHandle] = None
423+
newSeed = "123.4_1_!"
424+
assert tHandle == sha256(newSeed.encode()).hexdigest()[0:13]
413425

414426
# END Test testCoreTree_MakeHandles
415427

0 commit comments

Comments
 (0)