diff --git a/tests/testdynamic.py b/tests/testdynamic.py index 0fca392422..e40bc79cab 100644 --- a/tests/testdynamic.py +++ b/tests/testdynamic.py @@ -1,3 +1,4 @@ +import uuid from collections import deque import time @@ -449,7 +450,7 @@ def history_callback(x, history=deque(maxlen=10)): x.event(x=2) self.assertEqual(dmap[()], Curve([1, 2])) - + def test_dynamic_callable_disable_callable_memoize(self): # Disabling Callable.memoize means no memoization is applied, @@ -572,6 +573,35 @@ def history_callback(x, y, history=deque(maxlen=10)): self.assertEqual(xresets, 2) self.assertEqual(yresets, 2) + def test_dynamic_callable_stream_hashkey(self): + # Enable transient stream meaning memoization only happens when + # stream is inactive, should have sample for each call to + # stream.update + def history_callback(x, history=deque(maxlen=10)): + if x is not None: + history.append(x) + return Curve(list(history)) + + class NoMemoize(PointerX): + @property + def hashkey(self): return {'hash': uuid.uuid4().hex} + + x = NoMemoize() + dmap = DynamicMap(history_callback, kdims=[], streams=[x]) + + # Add stream subscriber mocking plot + x.add_subscriber(lambda **kwargs: dmap[()]) + + for i in range(2): + x.event(x=1) + self.assertEqual(dmap[()], Curve([1, 1, 1])) + + for i in range(2): + x.event(x=2) + + self.assertEqual(dmap[()], Curve([1, 1, 1, 2, 2, 2])) + + class TestPeriodicStreamUpdate(ComparisonTestCase):