def test_log_axis(self): p = bpf.figure(x_axis_type='log') p.circle([1, 2, 3], [1, 2, 3]) assert isinstance(p.x_scale, LogScale) p = bpf.figure(y_axis_type='log') p.circle([1, 2, 3], [1, 2, 3]) assert isinstance(p.y_scale, LogScale)
def test_basic(self): p = bpf.figure() q = bpf.figure() q.circle([1, 2, 3], [1, 2, 3]) assert p != q r = bpf.figure() assert p != r assert q != r
def test_render_level(self, marker): p = bpf.figure() func = getattr(p, marker) r = func([1, 2, 3], [1, 2, 3], level="underlay") assert r.level == "underlay" with pytest.raises(ValueError): p.circle([1, 2, 3], [1, 2, 3], level="bad_input")
def test_axis(self): p = bpf.figure() p.circle([1, 2, 3], [1, 2, 3]) assert len(p.axis) == 2 expected = set(p.axis) ax = LinearAxis() expected.add(ax) p.above.append(ax) assert set(p.axis) == expected ax2 = LinearAxis() expected.add(ax2) p.below.append(ax2) assert set(p.axis) == expected ax3 = LinearAxis() expected.add(ax3) p.left.append(ax3) assert set(p.axis) == expected ax4 = LinearAxis() expected.add(ax4) p.right.append(ax4) assert set(p.axis) == expected
def test_tools(self): TOOLS = "pan,box_zoom,reset,lasso_select" fig = bpf.figure(tools=TOOLS) expected = [PanTool, BoxZoomTool, ResetTool, LassoSelectTool] assert len(fig.tools) == len(expected) for i, _type in enumerate(expected): assert isinstance(fig.tools[i], _type)
def test_fill_color_input(self, color, marker): p = bpf.figure() func = getattr(p, marker) r = func([1, 2, 3], [1, 2, 3], fill_color=color) assert r.glyph.fill_color == color # rgb should always be an integer by the time it is added to property for v in r.glyph.fill_color[0:3]: assert isinstance(v, int)
def test_glyph_method_errors_on_sequence_literals_with_source(self): p = bpf.figure() source = ColumnDataSource({'x': [1, 2, 3], 'y': [2, 3, 4]}) with pytest.raises(RuntimeError, match=r"Expected y to reference fields in the supplied data source."): p.circle(x='x', y=[1,2,3], source=source) with pytest.raises(RuntimeError, match=r"Expected y and line_color to reference fields in the supplied data source."): p.circle(x='x', y=[1,2,3], line_color=["red", "green", "blue"], source=source) with pytest.raises(RuntimeError) as e: p.circle(x='x', y=[1,2,3], color=["red", "green", "blue"], source=source) m = re.search (r"Expected y, (.+) and (.+) to reference fields in the supplied data source.", str(e.value)) assert m is not None assert set(m.groups()) == set(["fill_color", "line_color"])
def test_plot_fill_props(self): p = bpf.figure(background_fill_color='red', background_fill_alpha=0.5, border_fill_color='blue', border_fill_alpha=0.8) assert p.background_fill_color == 'red' assert p.background_fill_alpha == 0.5 assert p.border_fill_color == 'blue' assert p.border_fill_alpha == 0.8 p.background_fill_color = 'green' p.border_fill_color = 'yellow' assert p.background_fill_color == 'green' assert p.border_fill_color == 'yellow'
def test_returns_renderers(self): fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries'] years = ["2015", "2016", "2017"] colors = ["#c9d9d3", "#718dbf", "#e84d60"] data = {'fruits' : fruits, '2015' : [2, 1, 4, 3, 2, 4], '2016' : [5, 3, 4, 2, 4, 6], '2017' : [3, 2, 4, 4, 5, 3]} source = ColumnDataSource(data=data) p = bpf.figure() renderers = p.vbar_stack(years, x='fruits', width=0.9, color=colors, source=source, legend=[value(x) for x in years], name=years) assert len(renderers) == 3 assert renderers[0].name == "2015" assert renderers[1].name == "2016" assert renderers[2].name == "2017"
def test_width_height(self): p = bpf.figure(width=100, height=120) assert p.plot_width == 100 assert p.plot_height == 120 p = bpf.figure(plot_width=100, plot_height=120) assert p.plot_width == 100 assert p.plot_height == 120 with pytest.raises(ValueError): bpf.figure(plot_width=100, width=120) with pytest.raises(ValueError): bpf.figure(plot_height=100, height=120)
def test_yaxis(self): p = bpf.figure() p.circle([1, 2, 3], [1, 2, 3]) assert len(p.yaxis) == 1 expected = set(p.yaxis) ax = LinearAxis() expected.add(ax) p.right.append(ax) assert set(p.yaxis) == expected ax2 = LinearAxis() expected.add(ax2) p.right.append(ax2) assert set(p.yaxis) == expected p.above.append(LinearAxis()) assert set(p.yaxis) == expected p.below.append(LinearAxis()) assert set(p.yaxis) == expected
def test_mixed_inputs(self, marker): p = bpf.figure() rgb = (100, 0, 0) rgb_other = (0, 100, 0) alpha1 = 0.5 alpha2 = 0.75 func = getattr(p, marker) # color/line_color r = func([1, 2, 3], [1, 2, 3], color=rgb, line_color=rgb_other) assert r.glyph.fill_color == rgb assert r.glyph.line_color == rgb_other # color/fill_color r = func([1, 2, 3], [1, 2, 3], color=rgb, fill_color=rgb_other) assert r.glyph.line_color == rgb assert r.glyph.fill_color == rgb_other # alpha/line_alpha r = func([1, 2, 3], [1, 2, 3], color=rgb, alpha=alpha1, line_alpha=alpha2) assert r.glyph.line_alpha == alpha2 assert r.glyph.fill_alpha == alpha1
def test_columnsource_auto_conversion_from_dict(self) -> None: p = bpf.figure() dct = {'x': [1, 2, 3], 'y': [2, 3, 4]} p.circle(x='x', y='y', source=dct)
def test_ygrid(self) -> None: p = bpf.figure() p.circle([1, 2, 3], [1, 2, 3]) assert len(p.ygrid) == 1 assert p.ygrid[0].dimension == 1
def p(): return bpf.figure()
def test_circle_with_radius(self): p = bpf.figure() r = p.scatter([1, 2, 3], [1, 2, 3], marker="circle", radius=0.2) assert isinstance(r.glyph, Circle) assert r.glyph.radius == 0.2
def test_grid(self) -> None: p = bpf.figure() p.circle([1, 2, 3], [1, 2, 3]) assert len(p.grid) == 2
def test_xgrid(self): p = bpf.figure() p.circle([1, 2, 3], [1, 2, 3]) assert len(p.xgrid) == 1 assert p.xgrid[0].dimension == 0
def test_marker_value(self, marker): p = bpf.figure() r = p.scatter([1, 2, 3], [1, 2, 3], marker=marker) assert isinstance(r.glyph, Scatter) assert r.glyph.marker == marker
def test_grid(self): p = bpf.figure() p.circle([1, 2, 3], [1, 2, 3]) assert len(p.grid) == 2
def test_columnsource_auto_conversion_from_pandas(self, pd) -> None: p = bpf.figure() df = pd.DataFrame({'x': [1, 2, 3], 'y': [2, 3, 4]}) p.circle(x='x', y='y', source=df)
def test_ygrid(self): p = bpf.figure() p.circle([1, 2, 3], [1, 2, 3]) assert len(p.ygrid) == 1 assert p.ygrid[0].dimension == 1
def test_marker_value(self, marker) -> None: p = bpf.figure() r = p.scatter([1, 2, 3], [1, 2, 3], marker=marker) assert isinstance(r.glyph, Scatter) assert r.glyph.marker == marker
def test_marker_column(self) -> None: p = bpf.figure() data = dict(x=[1, 2, 3], y=[1, 2, 3], foo=["hex", "square", "circle"]) r = p.scatter('x', 'y', marker='foo', source=data) assert isinstance(r.glyph, Scatter) assert r.glyph.marker == "foo"
def test_title_should_accept_string(self) -> None: plot = bpf.figure(title='Great Title 2') plot.line([1, 2, 3], [1, 2, 3]) assert plot.title.text == 'Great Title 2'
def test_title_kwarg_no_warning(self, recwarn): bpf.figure(title="title") assert len(recwarn) == 0
def test_title_should_accept_Title(self) -> None: title = Title(text='Great Title') plot = bpf.figure(title=title) plot.line([1, 2, 3], [1, 2, 3]) assert plot.title.text == 'Great Title'
def test_title_should_accept_Title(self): title = Title(text='Great Title') plot = bpf.figure(title=title) plot.line([1, 2, 3], [1, 2, 3]) assert plot.title.text == 'Great Title'
def test_marker_column(self): p = bpf.figure() data = dict(x=[1, 2, 3], y=[1, 2, 3], foo=["hex", "square", "circle"]) r = p.scatter('x', 'y', marker='foo', source=data) assert isinstance(r.glyph, Scatter) assert r.glyph.marker == "foo"
def test_title_should_accept_string(self): plot = bpf.figure(title='Great Title 2') plot.line([1, 2, 3], [1, 2, 3]) assert plot.title.text == 'Great Title 2'
def test_title_kwarg_no_warning(self, recwarn) -> None: bpf.figure(title="title") assert len(recwarn) == 0
def test_columnsource_auto_conversion_from_dict(self): p = bpf.figure() dct = {'x': [1, 2, 3], 'y': [2, 3, 4]} p.circle(x='x', y='y', source=dct)
def p(): return bpf.figure()
def test_columnsource_auto_conversion_from_pandas(self, pd): p = bpf.figure() df = pd.DataFrame({'x': [1, 2, 3], 'y': [2, 3, 4]}) p.circle(x='x', y='y', source=df)
def test_width_height(self) -> None: p = bpf.figure(width=100, height=120) assert p.width == 100 assert p.height == 120
def test_circle_with_radius(self) -> None: p = bpf.figure() r = p.scatter([1, 2, 3], [1, 2, 3], marker="circle", radius=0.2) assert isinstance(r.glyph, Circle) assert r.glyph.radius == 0.2