From b17075fc867b35bc24a90a755ec0491fac16cbec Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Mon, 23 Oct 2017 01:17:29 +0100 Subject: [PATCH] Added test for custom Stream.hashkey --- tests/testdynamic.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) 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):