Skip to content

Commit dd4c898

Browse files
committed
format
1 parent 1432d4f commit dd4c898

2 files changed

Lines changed: 60 additions & 31 deletions

File tree

src/mail_sovereignty/analyze.py

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ def _yellow(t: str) -> str:
4545
return _c("33", t)
4646

4747

48-
4948
# ---------------------------------------------------------------------------
5049
# Formatting helpers
5150
# ---------------------------------------------------------------------------
@@ -325,7 +324,7 @@ def report_gateways(munis: dict[str, Any]) -> None:
325324

326325
print(
327326
f" Municipalities with gateway: "
328-
f"{_bold(str(len(with_gw)))} / {total} ({len(with_gw)/total*100:.1f}%)"
327+
f"{_bold(str(len(with_gw)))} / {total} ({len(with_gw) / total * 100:.1f}%)"
329328
)
330329

331330
# Per-gateway counts
@@ -338,11 +337,7 @@ def report_gateways(munis: dict[str, Any]) -> None:
338337

339338
# Provider distribution with/without gateway
340339
print("\n Provider distribution:\n")
341-
print(
342-
f" {'Provider':<16}"
343-
f" {'With GW':>8} {'%':>6}"
344-
f" {'No GW':>8} {'%':>6}"
345-
)
340+
print(f" {'Provider':<16} {'With GW':>8} {'%':>6} {'No GW':>8} {'%':>6}")
346341
_sep()
347342
for prov in _PROVIDERS_ORDERED:
348343
cnt_w = sum(1 for m in with_gw.values() if m["provider"] == prov)
@@ -379,11 +374,8 @@ def report_domain_sharing(munis: dict[str, Any]) -> None:
379374
_sep()
380375
for domain, ms in shared_sorted:
381376
names = ", ".join(m["name"] for m in ms[:4])
382-
suffix = f", +{len(ms)-4}" if len(ms) > 4 else ""
383-
print(
384-
f" {domain:<30} {len(ms):>5} {ms[0]['provider']:<14} "
385-
f"{names}{suffix}"
386-
)
377+
suffix = f", +{len(ms) - 4}" if len(ms) > 4 else ""
378+
print(f" {domain:<30} {len(ms):>5} {ms[0]['provider']:<14} {names}{suffix}")
387379

388380

389381
# ---------------------------------------------------------------------------
@@ -395,11 +387,7 @@ def report_low_confidence(munis: dict[str, Any]) -> None:
395387
_header("LOW-CONFIDENCE / REVIEW CANDIDATES")
396388

397389
# Low confidence
398-
low = [
399-
m
400-
for m in munis.values()
401-
if m["classification_confidence"] < 60
402-
]
390+
low = [m for m in munis.values() if m["classification_confidence"] < 60]
403391
low.sort(key=lambda m: m["classification_confidence"])
404392

405393
print(f" Municipalities with confidence < 60%: {_red(str(len(low)))}")
@@ -440,10 +428,7 @@ def report_low_confidence(munis: dict[str, Any]) -> None:
440428
if conflicts:
441429
conflicts.sort(key=lambda x: len(x[2]), reverse=True)
442430
print()
443-
print(
444-
f" {'BFS':>5} {'Name':<28} {'Winner':<14} "
445-
f"{'Conflict':>14} Signals"
446-
)
431+
print(f" {'BFS':>5} {'Name':<28} {'Winner':<14} {'Conflict':>14} Signals")
447432
_sep()
448433
for m, other, kinds in conflicts[:20]:
449434
print(

tests/test_analyze.py

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,24 @@
3434
"category": "us-cloud",
3535
"classification_confidence": 95.0,
3636
"classification_signals": [
37-
{"kind": "mx", "provider": "microsoft", "weight": 0.2, "detail": "mx match"},
38-
{"kind": "spf", "provider": "microsoft", "weight": 0.2, "detail": "spf match"},
39-
{"kind": "autodiscover", "provider": "microsoft", "weight": 0.08, "detail": "ad match"},
37+
{
38+
"kind": "mx",
39+
"provider": "microsoft",
40+
"weight": 0.2,
41+
"detail": "mx match",
42+
},
43+
{
44+
"kind": "spf",
45+
"provider": "microsoft",
46+
"weight": 0.2,
47+
"detail": "spf match",
48+
},
49+
{
50+
"kind": "autodiscover",
51+
"provider": "microsoft",
52+
"weight": 0.08,
53+
"detail": "ad match",
54+
},
4055
],
4156
"mx": ["mail.protection.outlook.com"],
4257
"spf": "v=spf1 include:spf.protection.outlook.com -all",
@@ -51,8 +66,18 @@
5166
"category": "swiss-based",
5267
"classification_confidence": 90.0,
5368
"classification_signals": [
54-
{"kind": "mx", "provider": "independent", "weight": 0.2, "detail": "mx match"},
55-
{"kind": "spf", "provider": "independent", "weight": 0.2, "detail": "spf match"},
69+
{
70+
"kind": "mx",
71+
"provider": "independent",
72+
"weight": 0.2,
73+
"detail": "mx match",
74+
},
75+
{
76+
"kind": "spf",
77+
"provider": "independent",
78+
"weight": 0.2,
79+
"detail": "spf match",
80+
},
5681
],
5782
"mx": ["mail.bern.ch"],
5883
"spf": "v=spf1 a mx -all",
@@ -67,7 +92,12 @@
6792
"category": "swiss-based",
6893
"classification_confidence": 50.0,
6994
"classification_signals": [
70-
{"kind": "spf", "provider": "infomaniak", "weight": 0.2, "detail": "spf match"},
95+
{
96+
"kind": "spf",
97+
"provider": "infomaniak",
98+
"weight": 0.2,
99+
"detail": "spf match",
100+
},
71101
],
72102
"mx": ["mxpool.infomaniak.com"],
73103
"spf": "v=spf1 include:spf.infomaniak.ch -all",
@@ -82,8 +112,18 @@
82112
"category": "swiss-based",
83113
"classification_confidence": 55.0,
84114
"classification_signals": [
85-
{"kind": "spf", "provider": "infomaniak", "weight": 0.2, "detail": "spf match"},
86-
{"kind": "mx", "provider": "microsoft", "weight": 0.2, "detail": "mx conflict"},
115+
{
116+
"kind": "spf",
117+
"provider": "infomaniak",
118+
"weight": 0.2,
119+
"detail": "spf match",
120+
},
121+
{
122+
"kind": "mx",
123+
"provider": "microsoft",
124+
"weight": 0.2,
125+
"detail": "mx conflict",
126+
},
87127
],
88128
"mx": ["mxpool.infomaniak.com"],
89129
"spf": "v=spf1 include:spf.infomaniak.ch -all",
@@ -201,7 +241,9 @@ def test_report_low_confidence(capsys: pytest.CaptureFixture[str]) -> None:
201241
assert "Conflicting primary" in out
202242

203243

204-
def test_report_low_confidence_shows_conflicts(capsys: pytest.CaptureFixture[str]) -> None:
244+
def test_report_low_confidence_shows_conflicts(
245+
capsys: pytest.CaptureFixture[str],
246+
) -> None:
205247
report_low_confidence(_MUNIS)
206248
out = capsys.readouterr().out
207249
# muni 4 has mx pointing to microsoft but winner is infomaniak
@@ -235,7 +277,9 @@ def test_main(capsys: pytest.CaptureFixture[str], tmp_path: Path) -> None:
235277
# ---------------------------------------------------------------------------
236278

237279

238-
def test_no_color_env(capsys: pytest.CaptureFixture[str], monkeypatch: pytest.MonkeyPatch) -> None:
280+
def test_no_color_env(
281+
capsys: pytest.CaptureFixture[str], monkeypatch: pytest.MonkeyPatch
282+
) -> None:
239283
"""When NO_COLOR is set, output must not contain ANSI escape codes."""
240284
monkeypatch.setenv("NO_COLOR", "1")
241285
# Re-import to pick up env var change -- instead just test the _c helper

0 commit comments

Comments
 (0)