예제 #1
0
    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)
예제 #2
0
    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
예제 #3
0
 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")
예제 #4
0
    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
예제 #5
0
    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)
예제 #6
0
 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)
예제 #7
0
    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"])
예제 #8
0
    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'
예제 #9
0
    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"
예제 #10
0
    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)
예제 #11
0
    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
예제 #12
0
    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
예제 #13
0
 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)
예제 #14
0
 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
예제 #15
0
def p():
    return bpf.figure()
예제 #16
0
 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
예제 #17
0
 def test_grid(self) -> None:
     p = bpf.figure()
     p.circle([1, 2, 3], [1, 2, 3])
     assert len(p.grid) == 2
예제 #18
0
 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
예제 #19
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
예제 #20
0
 def test_grid(self):
     p = bpf.figure()
     p.circle([1, 2, 3], [1, 2, 3])
     assert len(p.grid) == 2
예제 #21
0
 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)
예제 #22
0
 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
예제 #23
0
 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
예제 #24
0
 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"
예제 #25
0
 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'
예제 #26
0
 def test_title_kwarg_no_warning(self, recwarn):
     bpf.figure(title="title")
     assert len(recwarn) == 0
예제 #27
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'
예제 #28
0
 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'
예제 #29
0
 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"
예제 #30
0
 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'
예제 #31
0
 def test_title_kwarg_no_warning(self, recwarn) -> None:
     bpf.figure(title="title")
     assert len(recwarn) == 0
예제 #32
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)
예제 #33
0
def p():
    return bpf.figure()
예제 #34
0
 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)
예제 #35
0
 def test_width_height(self) -> None:
     p = bpf.figure(width=100, height=120)
     assert p.width == 100
     assert p.height == 120
예제 #36
0
 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