Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various unit tests #1153

Merged
merged 2 commits into from
Feb 27, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 114 additions & 2 deletions tests/testplotinstantiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from holoviews.plotting.bokeh.callbacks import Callback
from bokeh.models import (
Div, ColumnDataSource, FactorRange, Range1d, Row, Column,
ToolbarBox, Spacer
ToolbarBox, Spacer, FixedTicker, FuncTickFormatter
)
from bokeh.models.mappers import (LinearColorMapper, LogColorMapper,
CategoricalColorMapper)
Expand Down Expand Up @@ -228,6 +228,22 @@ def teardown(self):
Callback._comm_type = comms.JupyterCommJS
mpl_renderer.comms['default'] = self.default_comm

def test_overlay_legend(self):
overlay = Curve(range(10), label='A') * Curve(range(10), label='B')
plot = bokeh_renderer.get_plot(overlay)
legend_labels = [l.label['value'] for l in plot.state.legend[0].items]
self.assertEqual(legend_labels, ['A', 'B'])

def test_overlay_update_sources(self):
hmap = HoloMap({i: (Curve(np.arange(i), label='A') *
Curve(np.arange(i)*2, label='B'))
for i in range(10, 13)})
plot = bokeh_renderer.get_plot(hmap)
plot.update((12,))
subplot1, subplot2 = plot.subplots.values()
self.assertEqual(subplot1.handles['source'].data['y'], np.arange(12))
self.assertEqual(subplot2.handles['source'].data['y'], np.arange(12)*2)

def test_batched_plot(self):
overlay = NdOverlay({i: Points(np.arange(i)) for i in range(1, 100)})
plot = bokeh_renderer.get_plot(overlay)
Expand Down Expand Up @@ -744,7 +760,103 @@ def test_layout_instantiate_subplots_transposed(self):
positions = [(0, 0), (0, 1), (1, 0), (1, 1), (2, 0), (2, 1), (3, 0), (3, 1)]
self.assertEqual(sorted(plot.subplots.keys()), positions)


def test_element_show_frame_disabled(self):
curve = Curve(range(10))(plot=dict(show_frame=False))
plot = bokeh_renderer.get_plot(curve).state
self.assertEqual(plot.outline_line_alpha, 0)

def test_overlay_show_frame_disabled(self):
overlay = (Curve(range(10)) * Curve(range(10)))(plot=dict(show_frame=False))
plot = bokeh_renderer.get_plot(overlay).state
self.assertEqual(plot.outline_line_alpha, 0)

def test_element_no_xaxis(self):
curve = Curve(range(10))(plot=dict(xaxis=None))
plot = bokeh_renderer.get_plot(curve).state
self.assertFalse(plot.xaxis[0].visible)

def test_element_no_yaxis(self):
curve = Curve(range(10))(plot=dict(yaxis=None))
plot = bokeh_renderer.get_plot(curve).state
self.assertFalse(plot.yaxis[0].visible)

def test_element_no_xaxis(self):
curve = Curve(range(10))(plot=dict(xaxis=None))
plot = bokeh_renderer.get_plot(curve).state
self.assertFalse(plot.xaxis[0].visible)

def test_element_no_yaxis(self):
curve = Curve(range(10))(plot=dict(yaxis=None))
plot = bokeh_renderer.get_plot(curve).state
self.assertFalse(plot.yaxis[0].visible)

def test_overlay_no_xaxis(self):
overlay = (Curve(range(10)) * Curve(range(10)))(plot=dict(xaxis=None))
plot = bokeh_renderer.get_plot(overlay).state
self.assertFalse(plot.xaxis[0].visible)

def test_overlay_no_yaxis(self):
overlay = (Curve(range(10)) * Curve(range(10)))(plot=dict(yaxis=None))
plot = bokeh_renderer.get_plot(overlay).state
self.assertFalse(plot.yaxis[0].visible)

def test_element_xrotation(self):
curve = Curve(range(10))(plot=dict(xrotation=90))
plot = bokeh_renderer.get_plot(curve).state
self.assertEqual(plot.xaxis[0].major_label_orientation, np.pi/2)

def test_element_yrotation(self):
curve = Curve(range(10))(plot=dict(yrotation=90))
plot = bokeh_renderer.get_plot(curve).state
self.assertEqual(plot.yaxis[0].major_label_orientation, np.pi/2)

def test_overlay_xrotation(self):
overlay = (Curve(range(10)) * Curve(range(10)))(plot=dict(xrotation=90))
plot = bokeh_renderer.get_plot(overlay).state
self.assertEqual(plot.xaxis[0].major_label_orientation, np.pi/2)

def test_overlay_yrotation(self):
overlay = (Curve(range(10)) * Curve(range(10)))(plot=dict(yrotation=90))
plot = bokeh_renderer.get_plot(overlay).state
self.assertEqual(plot.yaxis[0].major_label_orientation, np.pi/2)

def test_element_xticks_list(self):
curve = Curve(range(10))(plot=dict(xticks=[0, 5, 10]))
plot = bokeh_renderer.get_plot(curve).state
self.assertIsInstance(plot.xaxis[0].ticker, FixedTicker)
self.assertEqual(plot.xaxis[0].ticker.ticks, [0, 5, 10])

def test_element_yticks_list(self):
curve = Curve(range(10))(plot=dict(yticks=[0, 5, 10]))
plot = bokeh_renderer.get_plot(curve).state
self.assertIsInstance(plot.yaxis[0].ticker, FixedTicker)
self.assertEqual(plot.yaxis[0].ticker.ticks, [0, 5, 10])

def test_overlay_xticks_list(self):
overlay = (Curve(range(10)) * Curve(range(10)))(plot=dict(xticks=[0, 5, 10]))
plot = bokeh_renderer.get_plot(overlay).state
self.assertIsInstance(plot.xaxis[0].ticker, FixedTicker)
self.assertEqual(plot.xaxis[0].ticker.ticks, [0, 5, 10])

def test_overlay_yticks_list(self):
overlay = (Curve(range(10)) * Curve(range(10)))(plot=dict(yticks=[0, 5, 10]))
plot = bokeh_renderer.get_plot(overlay).state
self.assertIsInstance(plot.yaxis[0].ticker, FixedTicker)
self.assertEqual(plot.yaxis[0].ticker.ticks, [0, 5, 10])

def test_element_formatter_xaxis(self):
def formatter(x):
return '%s' % x
curve = Curve(range(10), kdims=[Dimension('x', value_format=formatter)])
plot = bokeh_renderer.get_plot(curve).state
self.assertIsInstance(plot.xaxis[0].formatter, FuncTickFormatter)

def test_element_formatter_yaxis(self):
def formatter(x):
return '%s' % x
curve = Curve(range(10), vdims=[Dimension('y', value_format=formatter)])
plot = bokeh_renderer.get_plot(curve).state
self.assertIsInstance(plot.yaxis[0].formatter, FuncTickFormatter)


class TestPlotlyPlotInstantiation(ComparisonTestCase):
Expand Down