@@ -118,14 +118,16 @@ def test_raises_on_bad_indexed_underscore_property(some_fig):
118118 """
119119Bad property path:
120120data[0].line_colr
121- ^^^^""" ,
121+ ^^^^
122+ Did you mean "color"?""" ,
122123 )
123124 assert (
124125 (
125126 e .args [0 ].find (
126127 """Bad property path:
127128data[0].line_colr
128- ^^^^"""
129+ ^^^^
130+ Did you mean "color"?"""
129131 )
130132 >= 0
131133 )
@@ -168,7 +170,8 @@ def test_raises_on_bad_indexed_underscore_property(some_fig):
168170 e .args [0 ].find (
169171 """Bad property path:
170172line_colr
171- ^^^^"""
173+ ^^^^
174+ Did you mean "color"?"""
172175 )
173176 >= 0
174177 )
@@ -189,7 +192,8 @@ def test_raises_on_bad_indexed_underscore_property(some_fig):
189192 """
190193Bad property path:
191194txt
192- ^^^""" ,
195+ ^^^
196+ Did you mean "text"?""" ,
193197 )
194198 assert raised
195199
@@ -206,7 +210,8 @@ def test_raises_on_bad_indexed_underscore_property(some_fig):
206210 """
207211Bad property path:
208212layout_title_txt
209- ^^^""" ,
213+ ^^^
214+ Did you mean "text"?""" ,
210215 )
211216 # also remove the invalid Figure property string added by the Figure constructor
212217 e_substr = error_substr (
@@ -219,7 +224,8 @@ def test_raises_on_bad_indexed_underscore_property(some_fig):
219224 e .args [0 ].find (
220225 """Bad property path:
221226layout_title_txt
222- ^^^"""
227+ ^^^
228+ Did you mean "text"?""" ,
223229 )
224230 >= 0
225231 )
@@ -239,7 +245,8 @@ def test_raises_on_bad_indexed_underscore_property(some_fig):
239245 """
240246Bad property path:
241247ltaxis
242- ^^^^^^""" ,
248+ ^^^^^^
249+ Did you mean "lataxis"?""" ,
243250 )
244251 assert raised
245252
@@ -253,14 +260,16 @@ def test_raises_on_bad_indexed_underscore_property(some_fig):
253260 """
254261Bad property path:
255262geo_ltaxis_showgrid
256- ^^^^^^""" ,
263+ ^^^^^^
264+ Did you mean "lataxis"?""" ,
257265 )
258266 assert (
259267 (
260268 e .args [0 ].find (
261269 """Bad property path:
262270geo_ltaxis_showgrid
263- ^^^^^^"""
271+ ^^^^^^
272+ Did you mean "lataxis"?"""
264273 )
265274 >= 0
266275 )
@@ -458,6 +467,10 @@ def check_error_string(call, exception, correct_str, subs):
458467 msg = e .args [0 ]
459468 for pat , rep in subs :
460469 msg = msg .replace (pat , rep , 1 )
470+ print ("MSG" )
471+ print (msg )
472+ print ("CORRECT" )
473+ print (correct_str )
461474 assert msg == correct_str
462475 assert raised
463476
@@ -473,23 +486,38 @@ def _raise_bad_property_path_real():
473486 correct_err_str = form_error_string (
474487 _raise_bad_property_path_form ,
475488 ValueError ,
476- [("bogus" , "_" ), ("bogus" , "_hey_yall" ), ("^^^^^" , "^" )],
489+ # change last boxgap to geo because bogus is closest to boxgap but _hey
490+ # closest to geo, but remember that boxgap is in the list of valid keys
491+ # displayed by the error string
492+ [
493+ ("bogus" , "_hey" ),
494+ ("bogus" , "_hey_yall" ),
495+ ("^^^^^" , "^^^^" ),
496+ ('Did you mean "boxgap"' , 'Did you mean "geo"' ),
497+ ],
477498 )
478499 check_error_string (_raise_bad_property_path_real , ValueError , correct_err_str , [])
479500
480501
481502def test_trailing_underscore_errors (some_fig ):
482503 # get error string but alter it to form the final expected string
483504 def _raise_bad_property_path_form ():
484- some_fig .update_layout (title_bogus = "hi" )
505+ some_fig .update_layout (title_text_bogus = "hi" )
485506
486507 def _raise_bad_property_path_real ():
487508 some_fig .update_layout (title_text_ = "hi" )
488509
489510 correct_err_str = form_error_string (
490511 _raise_bad_property_path_form ,
491512 ValueError ,
492- [("bogus" , "text_" ), ("title_bogus" , "title_text_" )],
513+ [
514+ (
515+ "Property does not support subscripting" ,
516+ "Property does not support subscripting and path has trailing underscores" ,
517+ ),
518+ ("text_bogus" , "text_" ),
519+ ("^^^^" , "^^^^^" ),
520+ ],
493521 )
494522 # no need to replace ^^^^^ because bogus and text_ are same length
495523 check_error_string (_raise_bad_property_path_real , ValueError , correct_err_str , [])
@@ -498,15 +526,19 @@ def _raise_bad_property_path_real():
498526def test_embedded_underscore_errors (some_fig ):
499527 # get error string but alter it to form the final expected string
500528 def _raise_bad_property_path_form ():
501- some_fig .update_layout (title_bogus_family = "hi" )
529+ some_fig .update_layout (title_font_bogusey = "hi" )
502530
503531 def _raise_bad_property_path_real ():
504532 some_fig .update_layout (title_font__family = "hi" )
505533
506534 correct_err_str = form_error_string (
507535 _raise_bad_property_path_form ,
508536 ValueError ,
509- [("bogus" , "font_" ), ("title_bogus_family" , "title_font__family" )],
537+ [
538+ ("bogusey" , "_family" ),
539+ ("bogusey" , "_family" ),
540+ ('Did you mean "size"?' , 'Did you mean "family"?' ),
541+ ],
510542 )
511543 # no need to replace ^^^^^ because bogus and font_ are same length
512544 check_error_string (_raise_bad_property_path_real , ValueError , correct_err_str , [])
@@ -523,7 +555,12 @@ def _raise_bad_property_path_real():
523555 correct_err_str = form_error_string (
524556 _raise_bad_property_path_form ,
525557 ValueError ,
526- [("bogus" , "_" ), ("bogus" , "_" ), ("^^^^^" , "^" )],
558+ [
559+ ("bogus" , "_" ),
560+ ("bogus" , "_" ),
561+ ("^^^^^" , "^" ),
562+ ('Did you mean "boxgap"' , 'Did you mean "geo"' ),
563+ ],
527564 )
528565 check_error_string (_raise_bad_property_path_real , ValueError , correct_err_str , [])
529566
@@ -539,7 +576,12 @@ def _raise_bad_property_path_real():
539576 correct_err_str = form_error_string (
540577 _raise_bad_property_path_form ,
541578 ValueError ,
542- [("bogus" , "__" ), ("bogus" , "__" ), ("^^^^^" , "^^" )],
579+ [
580+ ("bogus" , "__" ),
581+ ("bogus" , "__" ),
582+ ("^^^^^" , "^^" ),
583+ ('Did you mean "boxgap"' , 'Did you mean "geo"' ),
584+ ],
543585 )
544586 check_error_string (_raise_bad_property_path_real , ValueError , correct_err_str , [])
545587
@@ -557,7 +599,7 @@ def _raise_bad_property_path_real():
557599 correct_err_str = form_error_string (
558600 _raise_bad_property_path_form ,
559601 ValueError ,
560- [("bogus" , "_ " ), ("bogus" , "_font" ), ("^^^^^" , "^" )],
602+ [("bogus" , "_font " ), ("bogus" , "_font" ), ("^^^^^" , "^^^^ ^" )],
561603 )
562604 check_error_string (_raise_bad_property_path_real , ValueError , correct_err_str , [])
563605
@@ -567,15 +609,22 @@ def test_trailing_underscore_errors_dots_and_subscripts(some_fig):
567609 some_fig .add_annotation (text = "hi" )
568610
569611 def _raise_bad_property_path_form ():
570- some_fig ["layout.annotations[0].font_bogusey " ] = "hi"
612+ some_fig ["layout.annotations[0].font_family_bogus " ] = "hi"
571613
572614 def _raise_bad_property_path_real ():
573615 some_fig ["layout.annotations[0].font_family_" ] = "hi"
574616
575617 correct_err_str = form_error_string (
576618 _raise_bad_property_path_form ,
577619 ValueError ,
578- [("bogusey" , "family_" ), ("bogusey" , "family_" )],
620+ [
621+ (
622+ "Property does not support subscripting" ,
623+ "Property does not support subscripting and path has trailing underscores" ,
624+ ),
625+ ("family_bogus" , "family_" ),
626+ ("^^^^^^" , "^^^^^^^" ),
627+ ],
579628 )
580629 check_error_string (_raise_bad_property_path_real , ValueError , correct_err_str , [])
581630
@@ -585,14 +634,18 @@ def test_repeated_underscore_errors_dots_and_subscripts(some_fig):
585634 some_fig .add_annotation (text = "hi" )
586635
587636 def _raise_bad_property_path_form ():
588- some_fig ["layout.annotations[0].bogus_family " ] = "hi"
637+ some_fig ["layout.annotations[0].font_bogusey " ] = "hi"
589638
590639 def _raise_bad_property_path_real ():
591640 some_fig ["layout.annotations[0].font__family" ] = "hi"
592641
593642 correct_err_str = form_error_string (
594643 _raise_bad_property_path_form ,
595644 ValueError ,
596- [("bogus" , "font_" ), ("bogus" , "font_" )],
645+ [
646+ ("bogusey" , "_family" ),
647+ ("bogusey" , "_family" ),
648+ ('Did you mean "size"?' , 'Did you mean "family"?' ),
649+ ],
597650 )
598651 check_error_string (_raise_bad_property_path_real , ValueError , correct_err_str , [])
0 commit comments