Skip to content

Commit 3a872fa

Browse files
committed
fix test properly, don't just delete it
1 parent 9a0305a commit 3a872fa

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

block_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def format_block_value(val, precision):
8686
assert small_number_threshold < big_number_threshold
8787

8888
# 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:
9090
return u"{}".format(val)
9191
try:
9292
float_val = float(val)

tests/test_block_utils.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,12 +516,30 @@ def test_GIVEN_a_block_with_a_number_that_does_not_fit_in_a_float_WHEN_formatted
516516

517517
self.assertEqual(format_block_value(value, 3), expected_formatted_value)
518518

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+
519525
def test_GIVEN_negative_precision_WHEN_formatting_THEN_original_value_returned_unchanged(self):
520526
precision = -57
521527
value = "12.345"
522528

523529
self.assertEqual(format_block_value(value, precision), value)
524530

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+
525543

526544
if __name__ == '__main__':
527545
unittest.main()

0 commit comments

Comments
 (0)