exported actual_value_message method
authorMauro Scomparin <scompo@gmail.com>
Tue, 10 Jul 2018 19:56:51 +0000 (21:56 +0200)
committerMauro Scomparin <scompo@gmail.com>
Tue, 10 Jul 2018 19:56:51 +0000 (21:56 +0200)
money/money.py
money/tests/test_money.py

index 292aeb4bfc93f62c7f9a10e743ef5d5f6d3fc397..db67368653ebde490895b6af9f9dc17c6d369c8f 100755 (executable)
@@ -15,6 +15,7 @@ DATE_FIELD_NAME = 'date'
 HOUR_FIELD_NAME = 'hour'
 DESCRIPTION_FIELD_NAME = 'description'
 
+
 def write_movement(path, m):
     with open(path, 'a') as f:
         f.write(m[TYPE_FIELD_NAME] + m[VALUE_FIELD_NAME])
@@ -180,9 +181,15 @@ def sort_movements(movements):
 def default_configuration():
     return {DATA_FILE_NAME: 'movements.dat', LAST_MOVEMENT_NUMBER: 5}
 
+
 def last_movement_number_message(n):
     return 'latest {} movements:'.format(n)
 
+
+def actual_value_message(value):
+    return 'actual value: {}'.format(str(value))
+
+
 def write_latest_movements(data_file, conf):
     movements = load_file(data_file)
     ordered_movements = sort_movements(movements)
@@ -196,7 +203,7 @@ def write_latest_movements(data_file, conf):
             total_incomes = total_incomes + movement_value
         else:
             total_expenses = total_expenses + movement_value
-    print('actual value:', str(actual_value))
+    print(actual_value_message(actual_value))
     print('total incomes:', str(total_incomes))
     print('total expenses:', str(total_expenses))
     print(last_movement_number_message(conf[LAST_MOVEMENT_NUMBER]))
index a49bdf7655af1cf6712fbdc7fae26c5fc6999bcf..a402cc855e2d5c810f28a3778ba188cc178dd456 100644 (file)
@@ -1,6 +1,7 @@
 import unittest
 import tempfile
 import json
+from decimal import *
 from os.path import expanduser
 from money import money
 
@@ -14,6 +15,10 @@ class MoneyTest(unittest.TestCase):
         self.assertEqual(money.last_movement_number_message(
             10), "latest 10 movements:")
 
+    def test_actual_value_message(self):
+        self.assertEqual(money.actual_value_message(
+            Decimal(10.00)), "actual value: 10")
+
     def test_config_file_name(self):
         self.assertEqual(money.CONFIG_FILE_NAME, 'money.conf')