<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> import unittest <EOL> from mock import patch <EOL> import pytest <EOL> import numpy as np <EOL> from bokeh . charts import Chart , defaults <EOL> from bokeh . models import ( <EOL> ColumnDataSource , Grid , GlyphRenderer , LinearAxis , Range1d , Ticker ) <EOL> from bokeh . models . ranges import FactorRange <EOL> from bokeh . models . tools import ( <EOL> BoxZoomTool , HelpTool , LassoSelectTool , PanTool , PreviewSaveTool , ResetTool , <EOL> ResizeTool , WheelZoomTool ) <EOL> class TestChart ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . source = ColumnDataSource ( ) <EOL> self . xdr = Range1d ( ) <EOL> self . ydr = Range1d ( ) <EOL> self . glyph = GlyphRenderer ( ) <EOL> self . _groups = [ self . glyph ] * <NUM_LIT:3> <EOL> self . chart = Chart ( <EOL> title = "<STR_LIT:title>" , xlabel = "<STR_LIT>" , ylabel = "<STR_LIT>" , <EOL> legend = "<STR_LIT>" , xscale = "<STR_LIT>" , yscale = "<STR_LIT>" , <EOL> width = <NUM_LIT> , height = <NUM_LIT> , tools = True , <EOL> responsive = True , <EOL> xgrid = True , ygrid = False <EOL> ) <EOL> def test_title ( self ) : <EOL> self . chart . title = "<STR_LIT>" <EOL> self . assertEqual ( self . chart . title , "<STR_LIT>" ) <EOL> def test_responsive ( self ) : <EOL> self . assertEqual ( self . chart . responsive , True ) <EOL> def check_chart_elements ( self , expected_tools ) : <EOL> self . assertIsInstance ( self . chart . left [ <NUM_LIT:0> ] , LinearAxis ) <EOL> self . assertIsInstance ( self . chart . renderers [ <NUM_LIT:0> ] , LinearAxis ) <EOL> self . assertIsInstance ( self . chart . below [ <NUM_LIT:0> ] , LinearAxis ) <EOL> self . assertIsInstance ( self . chart . renderers [ <NUM_LIT:1> ] , LinearAxis ) <EOL> self . assertIsInstance ( self . chart . renderers [ <NUM_LIT:2> ] , Grid ) <EOL> self . assertIsInstance ( self . chart . renderers [ <NUM_LIT:3> ] , Grid ) <EOL> for i , type_ in enumerate ( expected_tools ) : <EOL> self . assertIsInstance ( self . chart . tools [ i ] , type_ ) <EOL> def test_ranges ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . chart . x_range , None ) <EOL> self . assertEqual ( self . chart . y_range , None ) <EOL> def test_axis_requires_range ( self ) : <EOL> with pytest . raises ( ValueError ) : <EOL> self . chart . make_axis ( "<STR_LIT:x>" , "<STR_LIT:left>" , "<STR_LIT>" , "<STR_LIT:foo>" ) <EOL> def test_make_axis ( self ) : <EOL> self . chart . add_ranges ( '<STR_LIT:x>' , Range1d ( ) ) <EOL> axis = self . chart . make_axis ( "<STR_LIT:x>" , "<STR_LIT:left>" , "<STR_LIT>" , "<STR_LIT:foo>" ) <EOL> self . assertEqual ( axis . location , "<STR_LIT>" ) <EOL> self . assertEqual ( axis . axis_label , "<STR_LIT:foo>" ) <EOL> axis = self . chart . make_axis ( "<STR_LIT:x>" , "<STR_LIT:left>" , "<STR_LIT>" , "<STR_LIT:bar>" ) <EOL> self . assertEqual ( axis . location , "<STR_LIT>" ) <EOL> self . assertEqual ( axis . axis_label , "<STR_LIT:bar>" ) <EOL> self . assertEqual ( axis . major_label_orientation , np . pi / <NUM_LIT:4> ) <EOL> axis = self . chart . make_axis ( "<STR_LIT:x>" , "<STR_LIT:left>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . assertEqual ( axis . location , "<STR_LIT>" ) <EOL> self . assertEqual ( axis . axis_label , "<STR_LIT>" ) <EOL> def test_make_grid ( self ) : <EOL> self . chart . add_ranges ( '<STR_LIT:x>' , Range1d ( ) ) <EOL> axis = self . chart . make_axis ( "<STR_LIT:x>" , "<STR_LIT:left>" , "<STR_LIT>" , "<STR_LIT:foo>" ) <EOL> grid = self . chart . make_grid ( <NUM_LIT:0> , axis . ticker ) <EOL> self . assertEqual ( grid . dimension , <NUM_LIT:0> ) <EOL> self . assertIsInstance ( grid . ticker , Ticker ) <EOL> def check_tools_scenario ( self , base_args , scenarios , categorical = False ) : <EOL> for tools , expected_tools in scenarios : <EOL> base_args [ '<STR_LIT>' ] = tools <EOL> chart = Chart ( ** base_args ) <EOL> self . compare_tools ( chart . tools , expected_tools ) <EOL> def compare_tools ( self , tools , expected_tools ) : <EOL> self . assertEqual ( len ( tools ) , len ( expected_tools ) ) <EOL> for i , _type in enumerate ( expected_tools ) : <EOL> self . assertIsInstance ( tools [ i ] , _type ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_chart_tools_linear ( self , mock_warn ) : <EOL> base_args = dict ( <EOL> title = "<STR_LIT:title>" , xlabel = "<STR_LIT>" , ylabel = "<STR_LIT>" , <EOL> legend = "<STR_LIT>" , xscale = "<STR_LIT>" , yscale = "<STR_LIT>" , xgrid = True , ygrid = True , <EOL> width = <NUM_LIT> , height = <NUM_LIT> , <EOL> ) <EOL> expected = [ <EOL> [ PanTool , WheelZoomTool , BoxZoomTool , PreviewSaveTool , ResizeTool , ResetTool , HelpTool ] , <EOL> [ ] , <EOL> [ ResizeTool , PanTool , BoxZoomTool , ResetTool , LassoSelectTool ] , <EOL> ] <EOL> scenarios = zip ( <EOL> [ True , False , "<STR_LIT>" ] , expected <EOL> ) <EOL> self . check_tools_scenario ( base_args , scenarios ) <EOL> self . check_tools_scenario ( base_args , scenarios , categorical = True ) <EOL> msg_repeat = "<STR_LIT>" <EOL> expected_tools = [ ResizeTool , PanTool , BoxZoomTool , ResetTool , LassoSelectTool , LassoSelectTool ] <EOL> mock_warn . reset_mock ( ) <EOL> base_args [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> chart = Chart ( ** base_args ) <EOL> chart . x_range = FactorRange ( ) <EOL> self . compare_tools ( chart . tools , expected_tools ) <EOL> mock_warn . assert_any_call ( msg_repeat ) <EOL> def test_chart_id ( ) : <EOL> chart = Chart ( id = '<STR_LIT>' , title = "<STR_LIT:title>" ) <EOL> assert chart . _id == '<STR_LIT>' <EOL> def test_defaults ( ) : <EOL> c1 = Chart ( ) <EOL> defaults . plot_height = <NUM_LIT:1000> <EOL> defaults . plot_width = <NUM_LIT:1000> <EOL> defaults . tools = False <EOL> c2 = Chart ( ) <EOL> c3 = Chart ( ) <EOL> assert c1 . plot_height == <NUM_LIT> <EOL> assert c2 . plot_height == c3 . plot_height == <NUM_LIT:1000> <EOL> assert c1 . plot_width == <NUM_LIT> <EOL> assert c2 . plot_width == c3 . plot_width == <NUM_LIT:1000> <EOL> assert c1 . tools <EOL> assert c2 . tools == c3 . tools == [ ] <EOL> def test_charts_theme_validation ( ) : <EOL> from bokeh . plotting import figure <EOL> p = figure ( ) <EOL> with pytest . raises ( ValueError ) : <EOL> defaults . apply ( p ) <EOL> def test_bar_chart_below_visibility ( ) : <EOL> from bokeh . charts import Bar <EOL> df = dict ( types = [ '<STR_LIT:foo>' , '<STR_LIT:bar>' ] , counts = [ <NUM_LIT:3> , <NUM_LIT:2> ] ) <EOL> p = Bar ( df , values = '<STR_LIT>' ) <EOL> p . below [ <NUM_LIT:0> ] . visible <EOL> df = dict ( types = [ '<STR_LIT:foo>' ] , counts = [ <NUM_LIT:3> ] ) <EOL> p = Bar ( df , values = '<STR_LIT>' , label = '<STR_LIT>' ) <EOL> assert p . below [ <NUM_LIT:0> ] . visible <EOL> df = dict ( types = [ '<STR_LIT:foo>' ] , counts = [ <NUM_LIT:3> ] ) <EOL> p = Bar ( df , values = '<STR_LIT>' ) <EOL> assert not p . below [ <NUM_LIT:0> ] . visible </s>
