added formatter
authorMauro Scomparin <scompo@gmail.com>
Tue, 17 Jul 2018 20:12:18 +0000 (22:12 +0200)
committerMauro Scomparin <scompo@gmail.com>
Tue, 17 Jul 2018 20:12:18 +0000 (22:12 +0200)
money/money.py
money/tests/test_money.py

index 2982bcba9744462bcb04606e4d1bb518ca2bece6..4cd3727e1ec7178eb975eb94488e8bf4ec69f8d7 100755 (executable)
@@ -220,6 +220,14 @@ def value_message(str, value):
     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)
@@ -239,4 +247,5 @@ def write_latest_movements(data_file, conf):
     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)
index 9ab8de25e3d9fa54c929a1a209f9595e5a209a31..909c703d7834ec2cae1941930fdc6dc0d634119e 100644 (file)
@@ -20,6 +20,15 @@ class MoneyTest(unittest.TestCase):
         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 = {
@@ -31,7 +40,8 @@ class MoneyTest(unittest.TestCase):
         }
         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()