Skip to content

Commit

Permalink
Handle base being zero
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandgeider committed Nov 28, 2024
1 parent b952fb5 commit 140137b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion wger/manager/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ def round_value(
If the base is None, the value will be returned as a Decimal object.
"""
if x is None:

if x is None or base == 0:
return x

# If the result is an integer, remove the decimal part
Expand Down
5 changes: 4 additions & 1 deletion wger/manager/tests/test_dataclasses_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ def test_round_value(self):
def test_round_value2(self):
self.assertEqual(round_value(Decimal('7'), 1.25), Decimal('7.5'))

def test_round_value_no_base(self):
def test_round_value_base_none(self):
self.assertEqual(round_value(Decimal('1.33')), Decimal('1.33'))

def test_round_value_base_zero(self):
self.assertEqual(round_value(Decimal('1.33'), 0), Decimal('1.33'))

def test_round_no_value(self):
self.assertEqual(round_value(None), None)

0 comments on commit 140137b

Please sign in to comment.