def test_chart_tools_linear(self, mock_warn): base_args = dict( title="title", xlabel="xlabel", ylabel="ylabel", legend="top_left", xscale="linear", yscale="linear", xgrid=True, ygrid=True, width=800, height=600, filename=False, server=False, notebook=False ) expected = [ [PanTool, WheelZoomTool, BoxZoomTool, PreviewSaveTool, ResizeTool, ResetTool], [], [ResizeTool, PanTool, BoxZoomTool, ResetTool, LassoSelectTool], ] scenarios = zip( [True, False, "resize,pan,box_zoom,reset,lasso_select"], expected ) self.check_tools_scenario(base_args, scenarios) self.check_tools_scenario(base_args, scenarios, categorical=True) msg_repeat = "LassoSelectTool are being repeated" expected_tools = [ResizeTool, PanTool, BoxZoomTool, ResetTool, LassoSelectTool, LassoSelectTool] mock_warn.reset_mock() # Finally check repeated tools base_args['tools'] = "resize,pan,box_zoom,reset,lasso_select,lasso_select" chart = Chart(**base_args) chart.x_range = FactorRange() chart.tools = [] chart.create_tools(chart._options.tools) self.compare_tools(chart.tools, expected_tools) mock_warn.assert_any_call(msg_repeat)
def test_chart_tools_linear(self, mock_warn): base_args = dict( title="title", xlabel="xlabel", ylabel="ylabel", legend="top_left", xscale="linear", yscale="linear", xgrid=True, ygrid=True, width=800, height=600, ) expected = [ [PanTool, WheelZoomTool, BoxZoomTool, PreviewSaveTool, ResizeTool, ResetTool, HelpTool], [], [ResizeTool, PanTool, BoxZoomTool, ResetTool, LassoSelectTool], ] scenarios = zip( [True, False, "resize,pan,box_zoom,reset,lasso_select"], expected ) self.check_tools_scenario(base_args, scenarios) self.check_tools_scenario(base_args, scenarios, categorical=True) msg_repeat = "LassoSelectTool are being repeated" expected_tools = [ResizeTool, PanTool, BoxZoomTool, ResetTool, LassoSelectTool, LassoSelectTool] mock_warn.reset_mock() # Finally check removing tools base_args['tools'] = "resize,pan,box_zoom,reset,lasso_select,lasso_select" chart = Chart(**base_args) chart.x_range = FactorRange() self.compare_tools(chart.tools, expected_tools) mock_warn.assert_any_call(msg_repeat)
def test_chart_tools_linear(self, mock_warn): base_args = dict(title="title", xlabel="xlabel", ylabel="ylabel", legend="top_left", xscale="linear", yscale="linear", xgrid=True, ygrid=True, width=800, height=600, filename=False, server=False, notebook=False) expected = [ [ PanTool, WheelZoomTool, BoxZoomTool, PreviewSaveTool, ResizeTool, ResetTool ], [], [ResizeTool, PanTool, BoxZoomTool, ResetTool, LassoSelectTool], ] scenarios = zip( [True, False, "resize,pan,box_zoom,reset,lasso_select"], expected) self.check_tools_scenario(base_args, scenarios) # need to change the expected tools because categorical scales # automatically removes pan and zoom tools expected = [ [PreviewSaveTool, ResizeTool, ResetTool], [], [ResizeTool, ResetTool, LassoSelectTool], ] scenarios = zip( [True, False, "resize,pan,box_zoom,reset,lasso_select"], expected) self.check_tools_scenario(base_args, scenarios, categorical=True) msg_repeat = "LassoSelectTool are being repeated" msg_removed = "categorical plots do not support pan and zoom operations.\n" \ "Removing tool(s): pan, box_zoom" expected_tools = [ ResizeTool, ResetTool, LassoSelectTool, LassoSelectTool ] mock_warn.reset_mock() # Finally check repeated tools base_args[ 'tools'] = "resize,pan,box_zoom,reset,lasso_select,lasso_select" chart = Chart(**base_args) chart.x_range = FactorRange() chart.tools = [] chart.create_tools(chart._options.tools) self.compare_tools(chart.tools, expected_tools) mock_warn.assert_any_call(msg_repeat) mock_warn.assert_any_call(msg_removed)
def check_tools_scenario(self, base_args, scenarios, categorical=False): for tools, expected_tools in scenarios: base_args['tools'] = tools chart = Chart(**base_args) if categorical: chart.x_range = FactorRange() chart.tools = [] chart.create_tools(chart._options.tools) self.compare_tools(chart.tools, expected_tools) chart = Chart(**base_args) chart.y_range = FactorRange() chart.tools = [] chart.create_tools(chart._options.tools) self.compare_tools(chart.tools, expected_tools) else: self.compare_tools(chart.tools, expected_tools)