@@ -118,14 +118,16 @@ def test_raises_on_bad_indexed_underscore_property(some_fig):
118
118
"""
119
119
Bad property path:
120
120
data[0].line_colr
121
- ^^^^""" ,
121
+ ^^^^
122
+ Did you mean "color"?""" ,
122
123
)
123
124
assert (
124
125
(
125
126
e .args [0 ].find (
126
127
"""Bad property path:
127
128
data[0].line_colr
128
- ^^^^"""
129
+ ^^^^
130
+ Did you mean "color"?"""
129
131
)
130
132
>= 0
131
133
)
@@ -168,7 +170,8 @@ def test_raises_on_bad_indexed_underscore_property(some_fig):
168
170
e .args [0 ].find (
169
171
"""Bad property path:
170
172
line_colr
171
- ^^^^"""
173
+ ^^^^
174
+ Did you mean "color"?"""
172
175
)
173
176
>= 0
174
177
)
@@ -189,7 +192,8 @@ def test_raises_on_bad_indexed_underscore_property(some_fig):
189
192
"""
190
193
Bad property path:
191
194
txt
192
- ^^^""" ,
195
+ ^^^
196
+ Did you mean "text"?""" ,
193
197
)
194
198
assert raised
195
199
@@ -206,7 +210,8 @@ def test_raises_on_bad_indexed_underscore_property(some_fig):
206
210
"""
207
211
Bad property path:
208
212
layout_title_txt
209
- ^^^""" ,
213
+ ^^^
214
+ Did you mean "text"?""" ,
210
215
)
211
216
# also remove the invalid Figure property string added by the Figure constructor
212
217
e_substr = error_substr (
@@ -219,7 +224,8 @@ def test_raises_on_bad_indexed_underscore_property(some_fig):
219
224
e .args [0 ].find (
220
225
"""Bad property path:
221
226
layout_title_txt
222
- ^^^"""
227
+ ^^^
228
+ Did you mean "text"?""" ,
223
229
)
224
230
>= 0
225
231
)
@@ -239,7 +245,8 @@ def test_raises_on_bad_indexed_underscore_property(some_fig):
239
245
"""
240
246
Bad property path:
241
247
ltaxis
242
- ^^^^^^""" ,
248
+ ^^^^^^
249
+ Did you mean "lataxis"?""" ,
243
250
)
244
251
assert raised
245
252
@@ -253,14 +260,16 @@ def test_raises_on_bad_indexed_underscore_property(some_fig):
253
260
"""
254
261
Bad property path:
255
262
geo_ltaxis_showgrid
256
- ^^^^^^""" ,
263
+ ^^^^^^
264
+ Did you mean "lataxis"?""" ,
257
265
)
258
266
assert (
259
267
(
260
268
e .args [0 ].find (
261
269
"""Bad property path:
262
270
geo_ltaxis_showgrid
263
- ^^^^^^"""
271
+ ^^^^^^
272
+ Did you mean "lataxis"?"""
264
273
)
265
274
>= 0
266
275
)
@@ -458,6 +467,10 @@ def check_error_string(call, exception, correct_str, subs):
458
467
msg = e .args [0 ]
459
468
for pat , rep in subs :
460
469
msg = msg .replace (pat , rep , 1 )
470
+ print ("MSG" )
471
+ print (msg )
472
+ print ("CORRECT" )
473
+ print (correct_str )
461
474
assert msg == correct_str
462
475
assert raised
463
476
@@ -473,23 +486,38 @@ def _raise_bad_property_path_real():
473
486
correct_err_str = form_error_string (
474
487
_raise_bad_property_path_form ,
475
488
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
+ ],
477
498
)
478
499
check_error_string (_raise_bad_property_path_real , ValueError , correct_err_str , [])
479
500
480
501
481
502
def test_trailing_underscore_errors (some_fig ):
482
503
# get error string but alter it to form the final expected string
483
504
def _raise_bad_property_path_form ():
484
- some_fig .update_layout (title_bogus = "hi" )
505
+ some_fig .update_layout (title_text_bogus = "hi" )
485
506
486
507
def _raise_bad_property_path_real ():
487
508
some_fig .update_layout (title_text_ = "hi" )
488
509
489
510
correct_err_str = form_error_string (
490
511
_raise_bad_property_path_form ,
491
512
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
+ ],
493
521
)
494
522
# no need to replace ^^^^^ because bogus and text_ are same length
495
523
check_error_string (_raise_bad_property_path_real , ValueError , correct_err_str , [])
@@ -498,15 +526,19 @@ def _raise_bad_property_path_real():
498
526
def test_embedded_underscore_errors (some_fig ):
499
527
# get error string but alter it to form the final expected string
500
528
def _raise_bad_property_path_form ():
501
- some_fig .update_layout (title_bogus_family = "hi" )
529
+ some_fig .update_layout (title_font_bogusey = "hi" )
502
530
503
531
def _raise_bad_property_path_real ():
504
532
some_fig .update_layout (title_font__family = "hi" )
505
533
506
534
correct_err_str = form_error_string (
507
535
_raise_bad_property_path_form ,
508
536
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
+ ],
510
542
)
511
543
# no need to replace ^^^^^ because bogus and font_ are same length
512
544
check_error_string (_raise_bad_property_path_real , ValueError , correct_err_str , [])
@@ -523,7 +555,12 @@ def _raise_bad_property_path_real():
523
555
correct_err_str = form_error_string (
524
556
_raise_bad_property_path_form ,
525
557
ValueError ,
526
- [("bogus" , "_" ), ("bogus" , "_" ), ("^^^^^" , "^" )],
558
+ [
559
+ ("bogus" , "_" ),
560
+ ("bogus" , "_" ),
561
+ ("^^^^^" , "^" ),
562
+ ('Did you mean "boxgap"' , 'Did you mean "geo"' ),
563
+ ],
527
564
)
528
565
check_error_string (_raise_bad_property_path_real , ValueError , correct_err_str , [])
529
566
@@ -539,7 +576,12 @@ def _raise_bad_property_path_real():
539
576
correct_err_str = form_error_string (
540
577
_raise_bad_property_path_form ,
541
578
ValueError ,
542
- [("bogus" , "__" ), ("bogus" , "__" ), ("^^^^^" , "^^" )],
579
+ [
580
+ ("bogus" , "__" ),
581
+ ("bogus" , "__" ),
582
+ ("^^^^^" , "^^" ),
583
+ ('Did you mean "boxgap"' , 'Did you mean "geo"' ),
584
+ ],
543
585
)
544
586
check_error_string (_raise_bad_property_path_real , ValueError , correct_err_str , [])
545
587
@@ -557,7 +599,7 @@ def _raise_bad_property_path_real():
557
599
correct_err_str = form_error_string (
558
600
_raise_bad_property_path_form ,
559
601
ValueError ,
560
- [("bogus" , "_ " ), ("bogus" , "_font" ), ("^^^^^" , "^" )],
602
+ [("bogus" , "_font " ), ("bogus" , "_font" ), ("^^^^^" , "^^^^ ^" )],
561
603
)
562
604
check_error_string (_raise_bad_property_path_real , ValueError , correct_err_str , [])
563
605
@@ -567,15 +609,22 @@ def test_trailing_underscore_errors_dots_and_subscripts(some_fig):
567
609
some_fig .add_annotation (text = "hi" )
568
610
569
611
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"
571
613
572
614
def _raise_bad_property_path_real ():
573
615
some_fig ["layout.annotations[0].font_family_" ] = "hi"
574
616
575
617
correct_err_str = form_error_string (
576
618
_raise_bad_property_path_form ,
577
619
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
+ ],
579
628
)
580
629
check_error_string (_raise_bad_property_path_real , ValueError , correct_err_str , [])
581
630
@@ -585,14 +634,18 @@ def test_repeated_underscore_errors_dots_and_subscripts(some_fig):
585
634
some_fig .add_annotation (text = "hi" )
586
635
587
636
def _raise_bad_property_path_form ():
588
- some_fig ["layout.annotations[0].bogus_family " ] = "hi"
637
+ some_fig ["layout.annotations[0].font_bogusey " ] = "hi"
589
638
590
639
def _raise_bad_property_path_real ():
591
640
some_fig ["layout.annotations[0].font__family" ] = "hi"
592
641
593
642
correct_err_str = form_error_string (
594
643
_raise_bad_property_path_form ,
595
644
ValueError ,
596
- [("bogus" , "font_" ), ("bogus" , "font_" )],
645
+ [
646
+ ("bogusey" , "_family" ),
647
+ ("bogusey" , "_family" ),
648
+ ('Did you mean "size"?' , 'Did you mean "family"?' ),
649
+ ],
597
650
)
598
651
check_error_string (_raise_bad_property_path_real , ValueError , correct_err_str , [])
0 commit comments