Skip to content

Commit

Permalink
Merge pull request #1153 from ioam/various_unit_tests
Browse files Browse the repository at this point in the history
Various unit tests
  • Loading branch information
jlstevens authored Feb 27, 2017
2 parents e09d665 + 69874aa commit be6cf79
Showing 1 changed file with 114 additions and 2 deletions.
116 changes: 114 additions & 2 deletions tests/testplotinstantiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,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 @@ -243,6 +243,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 @@ -807,7 +823,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

0 comments on commit be6cf79

Please sign in to comment.