Skip to content

Commit

Permalink
Added unit test for Bars HeatMap hover sanitization
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed May 21, 2017
1 parent b646e81 commit 910f633
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion tests/testplotinstantiation.py
Expand Up @@ -14,7 +14,7 @@
import numpy as np
from holoviews import (Dimension, Overlay, DynamicMap, Store, Dataset,
NdOverlay, GridSpace, HoloMap, Layout, Cycle,
Palette)
Palette, Element)
from holoviews.core.util import pd
from holoviews.element import (Curve, Scatter, Image, VLine, Points,
HeatMap, QuadMesh, Spikes, ErrorBars,
Expand Down Expand Up @@ -555,10 +555,39 @@ def _test_hover_info(self, element, tooltips, line_policy='nearest'):
self.assertEqual(hover[0].tooltips, tooltips)
self.assertEqual(hover[0].line_policy, line_policy)

if isinstance(element, Element):
cds = fig.select_one(dict(type=ColumnDataSource))
for label, lookup in hover[0].tooltips:
if label in element.dimensions():
self.assertIn(lookup[2:-1], cds.data)

# Ensure all the glyph renderers have a hover tool
for renderer in renderers:
self.assertTrue(any(renderer in h.renderers for h in hover))

def test_bars_hover_ensure_kdims_sanitized(self):
obj = Bars(np.random.rand(10,2), kdims=['Dim with spaces'])
obj = obj(plot={'tools': ['hover']})
self._test_hover_info(obj, [('Dim with spaces', '@{Dim_with_spaces}'), ('y', '@{y}')])

def test_bars_hover_ensure_vdims_sanitized(self):
obj = Bars(np.random.rand(10,2), vdims=['Dim with spaces'])
obj = obj(plot={'tools': ['hover']})
self._test_hover_info(obj, [('x', '@{x}'), ('Dim with spaces', '@{Dim_with_spaces}')])

def test_heatmap_hover_ensure_kdims_sanitized(self):
hm = HeatMap([(1,1,1), (2,2,0)], kdims=['x with space', 'y with $pecial symbol'])
hm = hm(plot={'tools': ['hover']})
self._test_hover_info(hm, [('x with space', '@{x_with_space}'),
('y with $pecial symbol', '@{y_with_pecial_symbol}'),
('z', '@{z}')])

def test_heatmap_hover_ensure_vdims_sanitized(self):
hm = HeatMap([(1,1,1), (2,2,0)], vdims=['z with $pace'])
hm = hm(plot={'tools': ['hover']})
self._test_hover_info(hm, [('x', '@{x}'), ('y', '@{y}'),
('z with $pace', '@{z_with_pace}')])

def test_points_overlay_datetime_hover(self):
obj = NdOverlay({i: Points((list(pd.date_range('2016-01-01', '2016-01-31')), range(31))) for i in range(5)},
kdims=['Test'])
Expand Down

0 comments on commit 910f633

Please sign in to comment.