import json
DATA_FILE_NAME = 'dataFile'
+LAST_MOVEMENT_NUMBER = 'latestMovementsNumber'
CONFIG_FILE_NAME = 'money-config.json'
CONFIG_FILE_LOCATION = expanduser('~') + CONFIG_FILE_NAME
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):
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
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')
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])
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:
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 = [