Files
watermarks-remover/tests/test_clean_text.py
T
guillaume 759fd33acf Release v0.0.1: multi-vendor AI marks skill and cleaners
Rename remove-claude-marks to remove-ai-marks, add container metadata
support (SVG/PDF/DOCX/ODT/HTML/MD), Layer B rewrite hook, unified file
CLI, and multi-vendor documentation for the first public release.
2026-08-11 13:30:25 -07:00

67 lines
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Tests for Layer A text Unicode scrub."""
from __future__ import annotations
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
SCRIPTS = ROOT / "skills" / "remove-ai-marks" / "scripts"
sys.path.insert(0, str(SCRIPTS))
from text_unicode import clean_text, inspect_text # noqa: E402
def test_strips_zero_width_and_soft_hyphen():
raw = "Hello\u200bWorld\u00ad!"
cleaned, stats = clean_text(raw)
assert cleaned == "HelloWorld!"
assert stats["removed_count"] >= 2
def test_normalizes_exotic_spaces():
raw = "a\u2003b\u3000c" # em space, ideographic space
cleaned, stats = clean_text(raw)
assert cleaned == "a b c"
assert stats["replaced_count"] >= 2
def test_inspect_finds_zwsp():
report = inspect_text("x\u200by")
assert report.suspicious_total >= 1
kinds = {h.kind for h in report.hits}
assert "zwj_family" in kinds or "strip" in kinds
def test_inspect_tag_chars():
# Language tag character U+E0041 (TAG LATIN CAPITAL LETTER A)
raw = "hi" + chr(0xE0041) + "there"
report = inspect_text(raw)
assert report.suspicious_total >= 1
assert any(h.kind == "tag_chars" for h in report.hits)
cleaned, stats = clean_text(raw)
assert chr(0xE0041) not in cleaned
assert stats["removed_count"] >= 1
def test_inspect_bidi():
raw = "ab\u202eef" # RLO
report = inspect_text(raw)
assert any(h.kind == "bidi" for h in report.hits)
cleaned, _ = clean_text(raw)
assert "\u202e" not in cleaned
def test_clean_preserves_normal_text():
raw = "Normal ASCII and café — fine."
cleaned, stats = clean_text(raw)
assert cleaned == raw
assert stats["removed_count"] == 0
def test_aggressive_confusable():
# Cyrillic 'а' (U+0430) looks like Latin 'a'
raw = "p\u0430y" # p + cyrillic a + y
cleaned, _ = clean_text(raw, aggressive_homoglyphs=True)
assert cleaned == "pay"