From d7f2e60293dac7895689af6272d3b177574b33fc Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Tue, 15 Aug 2017 13:27:07 +0100 Subject: [PATCH] Correctly register empty sources (#1806) --- holoviews/streams.py | 2 +- tests/teststreams.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/holoviews/streams.py b/holoviews/streams.py index 8978d6886c..86a86372d3 100644 --- a/holoviews/streams.py +++ b/holoviews/streams.py @@ -184,7 +184,7 @@ def __init__(self, rename={}, source=None, subscribers=[], linked=False, self._metadata = {} super(Stream, self).__init__(**params) - if source: + if source is not None: self.registry[id(source)].append(self) diff --git a/tests/teststreams.py b/tests/teststreams.py index 90068cfc1d..a907d1f50e 100644 --- a/tests/teststreams.py +++ b/tests/teststreams.py @@ -1,7 +1,10 @@ """ Unit test of the streams system """ +from collections import defaultdict + import param +from holoviews.element import Points from holoviews.element.comparison import ComparisonTestCase from holoviews.streams import * # noqa (Test all available streams) @@ -226,6 +229,22 @@ def test_batch_subscribers(self): self.assertEqual(subscriber2.call_count, 1) +class TestStreamSource(ComparisonTestCase): + + def tearDown(self): + Stream.registry = defaultdict(list) + + def test_source_registry(self): + points = Points([(0, 0)]) + positionX = PointerX(source=points) + self.assertIn(id(points), Stream.registry) + + def test_source_registry_empty_element(self): + points = Points([]) + positionX = PointerX(source=points) + self.assertIn(id(points), Stream.registry) + + class TestParameterRenaming(ComparisonTestCase): def test_simple_rename_constructor(self):