return str.format(value)
+def format_movement(movement):
+ return '|{0: >10}|{1: <10}|{2: <5}|{3: <18}|'.format(
+ movement[VALUE_FIELD_NAME][:10],
+ movement[DATE_FIELD_NAME][:10],
+ movement[HOUR_FIELD_NAME][:5],
+ movement[DESCRIPTION_FIELD_NAME][:18])
+
+
def write_latest_movements(data_file, conf):
movements = load_file(data_file)
ordered_movements = sort_movements(movements)
print(last_movement_number_message(conf[LAST_MOVEMENT_NUMBER]))
for i in range(conf[LAST_MOVEMENT_NUMBER]):
if i < len(ordered_movements):
- print(ordered_movements[i])
+ formatted_movement = format_movement(ordered_movements[i])
+ print(formatted_movement)
self.assertEqual(money.last_movement_number_message(
10), "latest 10 movements:")
+ def test_format_movement(self):
+ self.assertEqual('| -100.00|18/04/2017|00:01|testings stuffffff|',
+ money.format_movement({
+ money.VALUE_FIELD_NAME: '-100.00',
+ money.DATE_FIELD_NAME: '18/04/2017',
+ money.HOUR_FIELD_NAME: '00:01',
+ money.DESCRIPTION_FIELD_NAME: 'testings stuffffff stuffff',
+ }))
+
def test_write_movement_to_stream(self):
test_str = io.StringIO()
m = {
}
money.write_movement_to_stream(test_str, m)
test_str.seek(0)
- self.assertEqual('-100;18/04/2017;00:01;testings\n', test_str.readline(), 'wrong string read')
+ self.assertEqual('-100;18/04/2017;00:01;testings\n',
+ test_str.readline(), 'wrong string read')
def test_load_movements_from_stream(self):
test_str = io.StringIO()