tests/test_hygiene.py — Mail and Files Connector
From version 0.1.0 of Mail and Files Connector, shown publicly by its creator. 3.3 KiB · SHA-256 e70d4a3a59fb03fbc8c25fd86638a7418e0f1327725babba0f47af0863c7874a.
#!/usr/bin/env python3
# By Zero Width Lab (zerowidthlab.com)
"""Public package hygiene checks."""
from __future__ import annotations
import json
from pathlib import Path
import re
import unittest
import unicodedata
__author__ = "Zero Width Lab"
ROOT = Path(__file__).resolve().parents[1]
SIGNATURE = "By Zero Width Lab (zerowidthlab.com)"
class HygieneTests(unittest.TestCase):
def sources(self) -> list[Path]:
return [path for path in ROOT.rglob("*") if path.is_file()
and not any(part in {".git", "dist", "__pycache__"} for part in path.parts)
and path.suffix in {".py", ".md", ".json", ".txt"}]
def test_public_source(self) -> None:
guid = r"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"
email = r"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}"
tenant = r"[a-zA-Z0-9-]+\.onmicrosoft\.com"
home = r"/(?:Users|home)/[^/\s]+/"
invisible = {chr(point) for point in (0x200b, 0x200c, 0x200d, 0x2060, 0xfeff)}
vendors = ("open" + "ai", "anth" + "ropic", "gemi" + "ni",
"chat" + "gpt", "clau" + "de", "co" + "dex",
"co" + "pilot", "son" + "net", "op" + "us")
token = "G" + "P" + "T"
for source in self.sources():
content = source.read_text(encoding="utf-8")
self.assertIsNone(re.search(guid, content), source.name)
self.assertIsNone(re.search(tenant, content), source.name)
self.assertIsNone(re.search(home, content), source.name)
for address in re.findall(email, content):
self.assertTrue(address.endswith("@example.com"), source.name)
self.assertFalse(any(char in content for char in invisible), source.name)
for char in content:
self.assertNotEqual(unicodedata.category(char), "Cf", source.name)
for vendor in vendors:
self.assertNotIn(vendor, content.lower(), source.name)
self.assertIsNone(re.search(r"\b" + token + r"\b", content), source.name)
if source.suffix == ".md":
self.assertEqual(content.splitlines()[-1], SIGNATURE, source.name)
if source.suffix == ".py":
self.assertIn("# " + SIGNATURE, content.splitlines()[:4], source.name)
def test_forbidden_constructs(self) -> None:
prohibited = ("ev" + "al(", "ex" + "ec(", "com" + "pile(", "os." + "system",
"pic" + "kle", "ct" + "ypes", "shell" + "=True")
for source in self.sources():
if source.suffix == ".py":
content = source.read_text(encoding="utf-8")
for construct in prohibited:
self.assertNotIn(construct, content, source.name)
def test_package_file_list(self) -> None:
spec = ROOT / "packaging/package-spec.json"
if not spec.exists():
spec = ROOT / "manifest.json"
self.assertTrue(spec.is_file(), "package spec or packaged manifest must exist")
paths = json.loads(spec.read_text(encoding="utf-8"))["files"]
for item in paths:
self.assertTrue((ROOT / item["path"]).is_file())
if item["path"].endswith(".py"):
self.assertTrue(item["executable"])
if __name__ == "__main__":
unittest.main()
License: MIT (read it).
MIT
MIT LicenseCopyright (c) 2026 Zero Width Lab
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.