mirror of
https://github.com/domainaware/parsedmarc.git
synced 2026-09-11 16:37:59 +00:00
chore: address CodeQL code-quality findings (no behavior change) (#900)
- py/empty-except: add a short comment to each of the 10 flagged
`except <Type>: pass` blocks explaining why swallowing the
exception is correct there (best-effort cleanup/close, or
intentional fall-through to the next report format).
- py/unnecessary-lambda: replace `map(lambda x: parse_email_address(x), ...)`
with `map(parse_email_address, ...)` at the 5 flagged sites in
parsedmarc/utils.py; parse_email_address takes exactly one
positional argument, so this is behavior-preserving. Ran
`ruff format` afterward, which collapsed 3 of the now-shorter
calls onto single lines.
- py/imprecise-assert: replace `assertTrue(a > b)` / `assertTrue(a >= b)`
with `assertGreater(a, b)` / `assertGreaterEqual(a, b)` at the 9
flagged test sites; none carried a custom assertion message.
- .vscode/settings.json: drop three cSpell whitelist entries that are
pure misspellings ("passsword", "httpasswd", "unparasable") and
appear nowhere else in the tracked tree, so a recurrence of the typo
they used to hide (see #888) would be caught again. The correctly
spelled "htpasswd" and "unparseable" entries are untouched.
Verified clean: ruff check, ruff format --check, pyright (0
errors/warnings), and pytest tests/ (989 tests collected and passing
before and after, GITHUB_ACTIONS=true).
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
d185bd0526
commit
77045c2df0
+7
-7
@@ -1791,7 +1791,7 @@ class Test(unittest.TestCase):
|
||||
)
|
||||
report = cast(AggregateReport, result["report"])
|
||||
rows = parsedmarc.parsed_aggregate_reports_to_csv_rows(report)
|
||||
self.assertTrue(len(rows) > 0)
|
||||
self.assertGreater(len(rows), 0)
|
||||
row = rows[0]
|
||||
self.assertIn("np", row)
|
||||
self.assertIn("testing", row)
|
||||
@@ -1986,7 +1986,7 @@ class Test(unittest.TestCase):
|
||||
)
|
||||
parsed = parsedmarc.parse_smtp_tls_report_json(report_json)
|
||||
rows = parsedmarc.parsed_smtp_tls_reports_to_csv_rows(parsed)
|
||||
self.assertTrue(len(rows) >= 2)
|
||||
self.assertGreaterEqual(len(rows), 2)
|
||||
self.assertEqual(rows[0]["organization_name"], "Org")
|
||||
self.assertEqual(rows[0]["policy_domain"], "example.com")
|
||||
|
||||
@@ -2000,7 +2000,7 @@ class Test(unittest.TestCase):
|
||||
report = cast(AggregateReport, result["report"])
|
||||
# Pass as a list
|
||||
rows = parsedmarc.parsed_aggregate_reports_to_csv_rows([report])
|
||||
self.assertTrue(len(rows) > 0)
|
||||
self.assertGreater(len(rows), 0)
|
||||
# Verify non-str/int/bool values are cleaned
|
||||
for row in rows:
|
||||
for v in row.values():
|
||||
@@ -2051,7 +2051,7 @@ class Test(unittest.TestCase):
|
||||
report = parsedmarc.parse_aggregate_report_xml(xml, offline=True)
|
||||
self.assertTrue(report["report_metadata"]["timespan_requires_normalization"])
|
||||
# Records should be split across days
|
||||
self.assertTrue(len(report["records"]) > 1)
|
||||
self.assertGreater(len(report["records"]), 1)
|
||||
total = sum(r["count"] for r in report["records"])
|
||||
self.assertEqual(total, 90)
|
||||
for r in report["records"]:
|
||||
@@ -2127,7 +2127,7 @@ class Test(unittest.TestCase):
|
||||
self.assertIsNotNone(csv_output)
|
||||
self.assertIn(",", csv_output)
|
||||
rows = parsedmarc.parsed_failure_reports_to_csv_rows(parsed_report)
|
||||
self.assertTrue(len(rows) > 0)
|
||||
self.assertGreater(len(rows), 0)
|
||||
print("Passed!")
|
||||
|
||||
def testFailureReportCsvStripsNulFromFields(self):
|
||||
@@ -2581,7 +2581,7 @@ class TestPolicyPublishedEdgeCases(unittest.TestCase):
|
||||
</feedback>"""
|
||||
report = parsedmarc.parse_aggregate_report_xml(xml, offline=True)
|
||||
# At least the valid record should be parsed
|
||||
self.assertTrue(len(report["records"]) >= 1)
|
||||
self.assertGreaterEqual(len(report["records"]), 1)
|
||||
|
||||
|
||||
class TestParseReportFile(unittest.TestCase):
|
||||
@@ -3240,7 +3240,7 @@ class TestGetDmarcReportsFromMbox(unittest.TestCase):
|
||||
path = f.name
|
||||
try:
|
||||
results = parsedmarc.get_dmarc_reports_from_mbox(path, offline=True)
|
||||
self.assertTrue(len(results["aggregate_reports"]) >= 1)
|
||||
self.assertGreaterEqual(len(results["aggregate_reports"]), 1)
|
||||
finally:
|
||||
os.remove(path)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user