tests/test_hygiene.py — Desktop Mail Assistant
From version 0.1.0 of Desktop Mail Assistant, shown publicly by its creator. 3.0 KiB · SHA-256 e4a12e1110a1cb3cef4e3030717a5c5669390b0bef746abcd01d7c1b1cad519a.
#!/usr/bin/env python3
"""Reject private identifiers and malformed publication signatures.
By Zero Width Lab (zerowidthlab.com)
"""
from __future__ import annotations
import ast
import re
import unittest
import unicodedata
from pathlib import Path
__author__ = "Zero Width Lab"
ROOT = Path(__file__).resolve().parents[1]
SIGNATURE = "By Zero Width Lab (zerowidthlab.com)"
class HygieneTests(unittest.TestCase):
def test_shipped_text(self):
files = [path for path in ROOT.rglob("*") if path.is_file()
and ".git" not in path.parts and "dist" not in path.parts
and "__pycache__" not in path.parts and path.suffix in {".md", ".py", ".json", ".txt"}]
self.assertTrue(files)
for path in files:
with self.subTest(path=path.relative_to(ROOT)):
content = path.read_text(encoding="utf-8")
if path.suffix == ".md":
self.assertEqual(content.rstrip().splitlines()[-1], SIGNATURE)
if path.suffix == ".py":
self.assertIn(SIGNATURE, content.split("\n", 8)[0:8])
self.assertIn('__author__ = "Zero Width Lab"', content)
self.assertIsNone(re.search(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}", content))
self.assertIsNone(re.search(r"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}", content))
self.assertIsNone(re.search(r"[A-Za-z0-9.-]+\.onmicrosoft\.com", content, re.I))
self.assertNotIn("/" + "Users/", content)
self.assertNotIn("/" + "home/", content)
for character in content:
self.assertFalse(unicodedata.category(character) == "Cf")
for name in ("Open" + "AI", "Anthro" + "pic", "Chat" + "G" + "PT", "Gemi" + "ni",
"Clau" + "de", "Code" + "x", "Copi" + "lot", "Son" + "net", "Op" + "us"):
self.assertNotIn(name.casefold(), content.casefold())
self.assertIsNone(re.search(r"\b" + "G" + "PT" + r"\b", content))
if path.suffix == ".py":
for node in ast.walk(ast.parse(content)):
if isinstance(node, ast.Call):
name = node.func.id if isinstance(node.func, ast.Name) else node.func.attr if isinstance(node.func, ast.Attribute) else ""
self.assertNotIn(name, ("ev" + "al", "ex" + "ec", "com" + "pile", "sys" + "tem"))
self.assertFalse(any(keyword.arg == "shell" and isinstance(keyword.value, ast.Constant) and keyword.value.value is True for keyword in node.keywords))
if isinstance(node, (ast.Import, ast.ImportFrom)):
modules = [alias.name for alias in node.names] if isinstance(node, ast.Import) else [node.module or ""]
self.assertFalse(any(module.split(".")[0] in ("pick" + "le", "cty" + "pes") for module in modules))
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.