summaryrefslogtreecommitdiffstats
path: root/tests/unit/test_output.py
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-06-30 15:33:36 +0200
committerDanilo M. <danix@danix.xyz>2026-06-30 15:33:36 +0200
commit3a12128d12a0217a6200689465422caa65063cfb (patch)
treed5589b7c430bcda04a0bfc95f34d6f6120e071f3 /tests/unit/test_output.py
parent9c15e172eb5b50796eb050cc5704471bce09e024 (diff)
downloadfirefly-cli-3a12128d12a0217a6200689465422caa65063cfb.tar.gz
firefly-cli-3a12128d12a0217a6200689465422caa65063cfb.zip
output: decorate --human tables, color by tx type, IT datesv0.2.2
The --human transaction table now uses Italian dates (DD/MM/YYYY), a header rule line, and colors each row by transaction type (withdrawal red, deposit green, transfer cyan) when writing to a TTY. Colors are suppressed when piped; JSON output is unchanged. Bump to 0.2.2. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'tests/unit/test_output.py')
-rw-r--r--tests/unit/test_output.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/unit/test_output.py b/tests/unit/test_output.py
index c71a424..5b154d9 100644
--- a/tests/unit/test_output.py
+++ b/tests/unit/test_output.py
@@ -29,3 +29,49 @@ class TestOutput(unittest.TestCase):
out = buf.getvalue()
self.assertIn("Checking", out)
self.assertIn("id", out)
+
+ def test_emit_human_drops_nested_columns(self):
+ # dict/list-valued fields would dump unreadable blobs; they must be cut.
+ buf = io.StringIO()
+ with redirect_stdout(buf):
+ emit([{"id": "1", "name": "x", "junk": {"a": 1}, "tags": [1, 2]}],
+ human=True)
+ out = buf.getvalue()
+ self.assertIn("name", out)
+ self.assertNotIn("junk", out)
+ self.assertNotIn("tags", out)
+
+ def test_emit_human_transaction_flattens_splits(self):
+ # The useful fields live in the nested `transactions` split list, and the
+ # raw 12-decimal amount should be trimmed to 2 dp.
+ tx = {"id": "77", "transactions": [{
+ "type": "withdrawal", "date": "2026-06-28T00:00:00+02:00",
+ "amount": "7.400000000000", "currency_code": "EUR",
+ "description": "McDonald", "source_name": "BBVA",
+ "destination_name": "McDonald's", "category_name": "Food"}]}
+ buf = io.StringIO()
+ with redirect_stdout(buf):
+ emit([tx], human=True)
+ out = buf.getvalue()
+ self.assertIn("28/06/2026", out) # Italian date, no time/zone
+ self.assertIn("7.40", out) # amount trimmed to 2 dp
+ self.assertNotIn("7.400000", out)
+ self.assertIn("McDonald's", out) # destination surfaced
+ self.assertIn("Food", out)
+ self.assertNotIn("import_hash", out) # raw blob not dumped
+
+ def test_emit_color_only_on_tty(self):
+ tx = {"id": "1", "transactions": [{"type": "withdrawal",
+ "date": "2026-06-28", "amount": "1", "currency_code": "EUR",
+ "description": "x", "source_name": "a", "destination_name": "b",
+ "category_name": "c"}]}
+ plain = io.StringIO()
+ emit([tx], human=True, stream=plain)
+ self.assertNotIn("\033[", plain.getvalue()) # piped: no ANSI
+
+ class TTY(io.StringIO):
+ def isatty(self):
+ return True
+ tty = TTY()
+ emit([tx], human=True, stream=tty)
+ self.assertIn("\033[31m", tty.getvalue()) # tty: withdrawal is red