From: Mauro Scomparin Date: Thu, 5 Jul 2018 21:31:15 +0000 (+0200) Subject: added last movement number handling from configuration X-Git-Url: https://git.scompo.it/?a=commitdiff_plain;h=2001f2607ee9c47af043b55c2af01e6c6ecdd1cc;p=money.git added last movement number handling from configuration --- diff --git a/money/money.py b/money/money.py index ba0e081..a61dabf 100755 --- a/money/money.py +++ b/money/money.py @@ -5,6 +5,7 @@ from decimal import * import json DATA_FILE_NAME = 'dataFile' +LAST_MOVEMENT_NUMBER = 'latestMovementsNumber' CONFIG_FILE_NAME = 'money-config.json' CONFIG_FILE_LOCATION = expanduser('~') + CONFIG_FILE_NAME @@ -124,7 +125,7 @@ def riassunto_dati(): else: resulting_config = default_config file_dati = get_file_dati(resulting_config) - riassunto(file_dati) + riassunto(file_dati, resulting_config) def override_default_configuration(default_conf, other_conf): @@ -132,6 +133,8 @@ def override_default_configuration(default_conf, other_conf): if other_conf: if DATA_FILE_NAME in other_conf: result_conf[DATA_FILE_NAME] = other_conf[DATA_FILE_NAME] + if LAST_MOVEMENT_NUMBER in other_conf: + result_conf[LAST_MOVEMENT_NUMBER] = other_conf[LAST_MOVEMENT_NUMBER] return result_conf @@ -170,10 +173,10 @@ def ordina(dati): def default_configuration(): - return {DATA_FILE_NAME: 'movimenti.dat'} + return {DATA_FILE_NAME: 'movimenti.dat', LAST_MOVEMENT_NUMBER: 5} -def riassunto(file_dati): +def riassunto(file_dati, conf): dati = carica_file(file_dati) dati_ordinati = ordina(dati) val_attuale = Decimal('0') @@ -190,6 +193,6 @@ def riassunto(file_dati): print('guadagni complessivi:', str(guadagni_tot)) print('spese complessive:', str(spese_tot)) print('ultimi 5 movimenti:') - for i in range(5): + for i in range(conf[LAST_MOVEMENT_NUMBER]): if i < len(dati_ordinati): print(dati_ordinati[i]) diff --git a/money/tests/test_money.py b/money/tests/test_money.py index 30f7b10..30756e6 100644 --- a/money/tests/test_money.py +++ b/money/tests/test_money.py @@ -21,6 +21,8 @@ class MoneyTest(unittest.TestCase): conf = money.default_configuration() self.assertTrue(money.DATA_FILE_NAME in conf) self.assertEqual(conf[money.DATA_FILE_NAME], 'movimenti.dat') + self.assertTrue(money.LAST_MOVEMENT_NUMBER in conf) + self.assertEqual(conf[money.LAST_MOVEMENT_NUMBER], 5) def test_file_exists(self): with tempfile.TemporaryFile() as fp: @@ -28,10 +30,12 @@ class MoneyTest(unittest.TestCase): def test_override_default_configuration(self): def_conf = money.default_configuration() - new_conf = {money.DATA_FILE_NAME: 'new-file.dat'} + new_conf = {money.DATA_FILE_NAME: 'new-file.dat', money.LAST_MOVEMENT_NUMBER : 10} res = money.override_default_configuration(def_conf, new_conf) self.assertTrue(money.DATA_FILE_NAME in res) self.assertEqual(res[money.DATA_FILE_NAME], 'new-file.dat') + self.assertTrue(money.LAST_MOVEMENT_NUMBER in res) + self.assertEqual(res[money.LAST_MOVEMENT_NUMBER], 10) def test_ordina_ore(self): date = [