From cc8fc3873429584afc067e50c90cb9dae44847ac Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Thu, 6 May 2021 21:58:35 +0200 Subject: [PATCH] Update the handle generator test --- tests/test_core/test_core_tree.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tests/test_core/test_core_tree.py b/tests/test_core/test_core_tree.py index 803e88c4..c2d15ed7 100644 --- a/tests/test_core/test_core_tree.py +++ b/tests/test_core/test_core_tree.py @@ -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