From: Mauro Scomparin Date: Tue, 10 Jul 2018 19:56:51 +0000 (+0200) Subject: exported actual_value_message method X-Git-Url: https://git.scompo.it/?a=commitdiff_plain;h=b9b4dda5c3187084e6ce2236f53461107e4dc338;p=money.git exported actual_value_message method --- diff --git a/money/money.py b/money/money.py index 292aeb4..db67368 100755 --- a/money/money.py +++ b/money/money.py @@ -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])) diff --git a/money/tests/test_money.py b/money/tests/test_money.py index a49bdf7..a402cc8 100644 --- a/money/tests/test_money.py +++ b/money/tests/test_money.py @@ -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')