From c790203a1dd07e4dfdf78a6a109ad35a2e284d69 Mon Sep 17 00:00:00 2001 From: Mauro Scomparin Date: Tue, 10 Jul 2018 22:26:06 +0200 Subject: [PATCH] added input message creation logic --- money/money.py | 18 +++++++++++++----- money/tests/test_money.py | 4 ++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/money/money.py b/money/money.py index 9183678..b037d04 100755 --- a/money/money.py +++ b/money/money.py @@ -15,6 +15,14 @@ DATE_FIELD_NAME = 'date' HOUR_FIELD_NAME = 'hour' DESCRIPTION_FIELD_NAME = 'description' +def create_input_message(field_name, field_format, field_default_value): + return field_name + " (" + field_format + ") [" + field_default_value + "]: " + +TYPE_MESSAGE = create_input_message(TYPE_FIELD_NAME, '+/-', '-') +DATE_MESSAGE = create_input_message(DATE_FIELD_NAME, 'DD/MM/YYYY', 'today') +HOUR_MESSAGE = create_input_message(HOUR_FIELD_NAME, 'HH:MM', 'now') +VALUE_MESSAGE = create_input_message(VALUE_FIELD_NAME, '(#####.##)', '') +DESCRIPTION_MESSAGE = create_input_message(DESCRIPTION_FIELD_NAME, '', '') def write_movement(path, m): with open(path, 'a') as f: @@ -32,7 +40,7 @@ def write_movement(path, m): def read_type(): t = 'n' while not (t == '' or t == '+' or t == '-'): - t = input('type (+/-) [-]: ') + t = input(TYPE_MESSAGE) if t == '': t = '-' elif t == '+': @@ -43,26 +51,26 @@ def read_type(): def read_value(): v = '' while v == '': - v = input('value (#####.##) []: ') + v = input(VALUE_MESSAGE) return v def read_date(): - d = input('date (DD/MM/YYYY) [today]: ') + d = input(DATE_MESSAGE) if d == '': d = strftime("%d/%m/%Y", localtime()) return d def read_hour(): - h = input('hour (HH:MM) [now]: ') + h = input(HOUR_MESSAGE) if h == '': h = strftime('%H:%M', localtime()) return h def read_description(): - d = input('description () []: ') + d = input(DESCRIPTION_MESSAGE) return d diff --git a/money/tests/test_money.py b/money/tests/test_money.py index fa1578c..b66f25b 100644 --- a/money/tests/test_money.py +++ b/money/tests/test_money.py @@ -11,6 +11,10 @@ class MoneyTest(unittest.TestCase): def test_the_whole_univers(self): self.assertTrue(True, msg='if this fails something is very wrong') + def test_create_input_message(self): + self.assertEqual(money.create_input_message( + 'f', '##', '0'), 'f (##) [0]: ') + def test_riassunto_last_movement_number(self): self.assertEqual(money.last_movement_number_message( 10), "latest 10 movements:") -- 2.25.1