44
55from validator_collection import checkers
66
7- from highcharts_core .options .tooltips import Tooltip as cls
7+ from highcharts_core .options .tooltips import (Tooltip as cls ,
8+ DiagramTooltip as cls2 )
89from highcharts_core .utility_classes .javascript_functions import CallbackFunction
910from highcharts_core import errors
1011from tests .fixtures import input_files , check_input_file , to_camelCase , to_js_dict , \
@@ -144,4 +145,140 @@ def test_bug130_tooltip_serialization():
144145 assert obj .format == '{point.name}: {point.y}'
145146
146147 result = obj .to_js_literal ()
147- assert "'{point.name}: {point.y}'" in result or '"{point.name}: {point.y}"' in result
148+ assert "'{point.name}: {point.y}'" in result or '"{point.name}: {point.y}"' in result
149+
150+ #### DIAGRAM TOOLTIP TESTS
151+
152+ STANDARD_PARAMS_2 = [
153+ ({}, None ),
154+ ({
155+ 'node_format' : 'format string' ,
156+ 'node_formatter' : """function() { return true; }""" ,
157+ }, None ),
158+ (
159+ {
160+ "animation" : True ,
161+ "background_color" : "#ccc" ,
162+ "border_color" : "#999" ,
163+ "border_radius" : 4 ,
164+ "border_width" : 1 ,
165+ "class_name" : "some-class-name" ,
166+ "cluster_format" : "format string" ,
167+ "date_time_label_formats" : {
168+ "day" : "test" ,
169+ "hour" : "test" ,
170+ "millisecond" : "test" ,
171+ "minute" : "test" ,
172+ "month" : "test" ,
173+ "second" : "test" ,
174+ "week" : "test" ,
175+ "year" : "test" ,
176+ },
177+ "distance" : 12 ,
178+ "enabled" : True ,
179+ "follow_pointer" : True ,
180+ "follow_touch_move" : True ,
181+ "footer_format" : "format string" ,
182+ "formatter" : """function() { return true; }""" ,
183+ "header_format" : "format string" ,
184+ "header_shape" : "circle" ,
185+ "hide_delay" : 3 ,
186+ "null_format" : "format string" ,
187+ "null_formatter" : """function() { return true; }""" ,
188+ "outside" : False ,
189+ "padding" : 6 ,
190+ "point_format" : "format string" ,
191+ "point_formatter" : """function() { return true; }""" ,
192+ "positioner" : """function() { return true; }""" ,
193+ "shadow" : False ,
194+ "shape" : "rect" ,
195+ "shared" : False ,
196+ "snap" : 4 ,
197+ "split" : False ,
198+ "stick_on_contact" : True ,
199+ "style" : "style string goes here" ,
200+ "use_html" : False ,
201+ "value_decimals" : 2 ,
202+ "value_prefix" : "$" ,
203+ "value_suffix" : " USD" ,
204+ "x_date_format" : "format string" ,
205+ },
206+ None ,
207+ ),
208+ (
209+ {
210+ "formatter" : CallbackFunction .from_js_literal ("""function () {
211+ // The first returned item is the header, subsequent items are the
212+ // points
213+ return ['<b>' + this.x + '</b>'].concat(
214+ this.points ?
215+ this.points.map(function (point) {
216+ return point.series.name + ': ' + point.y + 'm';
217+ }) : []
218+ );
219+ }""" ),
220+ "split" : True ,
221+ },
222+ None ,
223+ ),
224+ (
225+ {
226+ "formatter" : """function () {
227+ // The first returned item is the header, subsequent items are the
228+ // points
229+ return ['<b>' + this.x + '</b>'].concat(
230+ this.points ?
231+ this.points.map(function (point) {
232+ return point.series.name + ': ' + point.y + 'm';
233+ }) : []
234+ );
235+ }""" ,
236+ "split" : True ,
237+ },
238+ None ,
239+ ),
240+ ({"format" : "{point.name} {point.y}" }, None ),
241+ ({"border_width" : "not-a-number" }, (ValueError , TypeError )),
242+ ]
243+
244+
245+ @pytest .mark .parametrize ('kwargs, error' , STANDARD_PARAMS_2 )
246+ def test_DiagramTooltip__init__ (kwargs , error ):
247+ Class__init__ (cls2 , kwargs , error )
248+
249+
250+ @pytest .mark .parametrize ('kwargs, error' , STANDARD_PARAMS_2 )
251+ def test_DiagramTooltip__to_untrimmed_dict (kwargs , error ):
252+ Class__to_untrimmed_dict (cls2 , kwargs , error )
253+
254+
255+ @pytest .mark .parametrize ('kwargs, error' , STANDARD_PARAMS_2 )
256+ def test_DiagramTooltip_from_dict (kwargs , error ):
257+ Class_from_dict (cls2 , kwargs , error )
258+
259+
260+ @pytest .mark .parametrize ('kwargs, error' , STANDARD_PARAMS_2 )
261+ def test_DiagramTooltip_to_dict (kwargs , error ):
262+ Class_to_dict (cls2 , kwargs , error )
263+
264+
265+ @pytest .mark .parametrize ('filename, as_file, error' , [
266+ ('tooltips/01.js' , False , None ),
267+ ('tooltips/02.js' , False , None ),
268+ ('tooltips/03-diagram.js' , False , None ),
269+ ('tooltips/04-diagram.js' , False , None ),
270+
271+ ('tooltips/error-01.js' , False , (TypeError , ValueError )),
272+ ('tooltips/error-02.js' , False , errors .HighchartsParseError ),
273+
274+ ('tooltips/01.js' , True , None ),
275+ ('tooltips/02.js' , True , None ),
276+ ('tooltips/03-diagram.js' , True , None ),
277+ ('tooltips/04-diagram.js' , False , None ),
278+
279+ ('tooltips/error-01.js' , True , (TypeError , ValueError )),
280+ ('tooltips/error-02.js' , True , errors .HighchartsParseError ),
281+ ])
282+ def test_DiagramTooltip_from_js_literal (input_files , filename , as_file , error ):
283+ Class_from_js_literal (cls2 , input_files , filename , as_file , error )
284+
0 commit comments