From 359c195419cfc64993b3e5f2d1167441fb21d688 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Sat, 16 Dec 2023 16:47:46 +0100 Subject: [PATCH] count ci accounts correctly --- chatmaild/src/chatmaild/metrics.py | 8 +++++--- chatmaild/src/chatmaild/tests/test_metrics.py | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 chatmaild/src/chatmaild/tests/test_metrics.py diff --git a/chatmaild/src/chatmaild/metrics.py b/chatmaild/src/chatmaild/metrics.py index 1d4132a..e037724 100644 --- a/chatmaild/src/chatmaild/metrics.py +++ b/chatmaild/src/chatmaild/metrics.py @@ -4,14 +4,16 @@ import time import sys -def main(): - vmail_dir = sys.argv[1] +def main(vmail_dir=None): + if vmail_dir is None: + vmail_dir = sys.argv[1] + accounts = 0 ci_accounts = 0 for path in Path(vmail_dir).iterdir(): accounts += 1 - if path.name.startswith("ci-"): + if path.name[:3] in ("ci-", "ac_"): ci_accounts += 1 timestamp = int(time.time() * 1000) diff --git a/chatmaild/src/chatmaild/tests/test_metrics.py b/chatmaild/src/chatmaild/tests/test_metrics.py new file mode 100644 index 0000000..c48c4a7 --- /dev/null +++ b/chatmaild/src/chatmaild/tests/test_metrics.py @@ -0,0 +1,16 @@ +from chatmaild.metrics import main + + +def test_main(tmp_path, capsys): + for x in ("ci-asllkj", "ac_12l3kj", "qweqwe", "ci-l1k2j31l2k3"): + tmp_path.joinpath(x).mkdir() + main(tmp_path) + out, _ = capsys.readouterr() + d = {} + for line in out.split("\n"): + if line.strip(): + name, num, _ = line.split() + d[name] = int(num) + + assert d["accounts"] == 4 + assert d["ci_accounts"] == 3