From 0757d8cf578c3e5de2b59be11d5dcb6dab616c43 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 | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/testdynamic.py b/tests/testdynamic.py index 0fca392422..02a725a83d 100644 --- a/tests/testdynamic.py +++ b/tests/testdynamic.py @@ -1,3 +1,4 @@ +import uuid from collections import deque import time @@ -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):