File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -86,7 +86,7 @@ def format_block_value(val, precision):
86
86
assert small_number_threshold < big_number_threshold
87
87
88
88
# No precision specified = do not format.
89
- if precision is None or precision < 0 :
89
+ if precision is None or not isinstance ( precision , int ) or precision < 0 :
90
90
return u"{}" .format (val )
91
91
try :
92
92
float_val = float (val )
Original file line number Diff line number Diff line change @@ -516,12 +516,30 @@ def test_GIVEN_a_block_with_a_number_that_does_not_fit_in_a_float_WHEN_formatted
516
516
517
517
self .assertEqual (format_block_value (value , 3 ), expected_formatted_value )
518
518
519
+ def test_GIVEN_arbitrary_object_as_precision_WHEN_formatting_THEN_original_value_returned_unchanged (self ):
520
+ precision = object ()
521
+ value = "12.345"
522
+
523
+ self .assertEqual (format_block_value (value , precision ), value )
524
+
519
525
def test_GIVEN_negative_precision_WHEN_formatting_THEN_original_value_returned_unchanged (self ):
520
526
precision = - 57
521
527
value = "12.345"
522
528
523
529
self .assertEqual (format_block_value (value , precision ), value )
524
530
531
+ def test_GIVEN_nonsense_precision_WHEN_formatting_THEN_original_value_returned_unchanged (self ):
532
+ precision = "this is clearly not a valid precision"
533
+ value = "12.345"
534
+
535
+ self .assertEqual (format_block_value (value , precision ), value )
536
+
537
+ def test_GIVEN_nonsense_precision_containing_unicode_WHEN_formatting_THEN_original_value_returned_unchanged (self ):
538
+ precision = u"ƀ Ɓ Ƃ ƃ Ƅ ƅ Ɔ Ƈ ƈ Ɖ Ɗ Ƌ ƌ ƍ Ǝ Ə Ɛ Ƒ ƒ Ɠ Ɣ ƕ Ɩ Ɨ Ƙ ƙ ƚ ƛ Ɯ Ɲ ƞ Ɵ Ơ ơ Ƣ ƣ Ƥ ƥ Ʀ Ƨ ƨ Ʃ ƪ ƫ Ƭ ƭ Ʈ"
539
+ value = "12.345"
540
+
541
+ self .assertEqual (format_block_value (value , precision ), value )
542
+
525
543
526
544
if __name__ == '__main__' :
527
545
unittest .main ()
You can’t perform that action at this time.
0 commit comments