consolidated message printing with value_message function
authorMauro Scomparin <scompo@gmail.com>
Tue, 10 Jul 2018 20:02:43 +0000 (22:02 +0200)
committerMauro Scomparin <scompo@gmail.com>
Tue, 10 Jul 2018 20:02:43 +0000 (22:02 +0200)
money/money.py
money/tests/test_money.py

index db67368653ebde490895b6af9f9dc17c6d369c8f..91836787fd67bc961c2a372b19a86ed8fdc442bd 100755 (executable)
@@ -186,8 +186,8 @@ def last_movement_number_message(n):
     return 'latest {} movements:'.format(n)
 
 
-def actual_value_message(value):
-    return 'actual value: {}'.format(str(value))
+def value_message(str, value):
+    return str.format(value)
 
 
 def write_latest_movements(data_file, conf):
@@ -203,9 +203,9 @@ def write_latest_movements(data_file, conf):
             total_incomes = total_incomes + movement_value
         else:
             total_expenses = total_expenses + movement_value
-    print(actual_value_message(actual_value))
-    print('total incomes:', str(total_incomes))
-    print('total expenses:', str(total_expenses))
+    print(value_message('actual value: {}', actual_value))
+    print(value_message('total incomes: {}', total_incomes))
+    print(value_message('total expenses: {}', total_expenses))
     print(last_movement_number_message(conf[LAST_MOVEMENT_NUMBER]))
     for i in range(conf[LAST_MOVEMENT_NUMBER]):
         if i < len(ordered_movements):
index a402cc855e2d5c810f28a3778ba188cc178dd456..fa1578cd1a6c5a0ab8b6d192e88df817eca3b732 100644 (file)
@@ -15,9 +15,9 @@ 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_value_message(self):
+        self.assertEqual(money.value_message('blah: {}',
+                                             Decimal(10.00)), "blah: 10")
 
     def test_config_file_name(self):
         self.assertEqual(money.CONFIG_FILE_NAME, 'money.conf')