Handle ZeroDivisionError
This commit is contained in:
parent
7ebe3b61c0
commit
a03714364c
|
@ -67,3 +67,6 @@ class GetBootstrapedPercentTest(TestCase):
|
||||||
value = get_bootstraped_percent(-10, 100)
|
value = get_bootstraped_percent(-10, 100)
|
||||||
self.assertIn(value, self.BS_WIDTH)
|
self.assertIn(value, self.BS_WIDTH)
|
||||||
self.assertEqual(value, 0)
|
self.assertEqual(value, 0)
|
||||||
|
|
||||||
|
def test_invalid_total_is_zero(self):
|
||||||
|
value = get_bootstraped_percent(25, 0)
|
||||||
|
|
|
@ -4,8 +4,11 @@ def get_bootstraped_percent(value, total):
|
||||||
|
|
||||||
Useful to set progress bar width using CSS classes (e.g. w-25)
|
Useful to set progress bar width using CSS classes (e.g. w-25)
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
|
percent = value / total
|
||||||
|
except ZeroDivisionError:
|
||||||
|
return 0
|
||||||
|
|
||||||
percent = value / total
|
|
||||||
bootstraped = round(percent * 4) * 100 // 4
|
bootstraped = round(percent * 4) * 100 // 4
|
||||||
|
|
||||||
# handle min and max boundaries
|
# handle min and max boundaries
|
||||||
|
|
Loading…
Reference in New Issue