diff --git a/README.md b/README.md index 948f12b..0ae4748 100644 --- a/README.md +++ b/README.md @@ -104,9 +104,19 @@ Follow these steps before running the compaction test suite: ```bash gcloud emulators firestore start --host-port=localhost:8153 ``` + In the therminal where execute the test: + ```bash + export FIRESTORE_EMULATOR_HOST=localhost:8153 + ``` 3. Execute the tests with `pytest` through `uv`: ```bash uv run pytest tests/test_compaction.py -v ``` If any step fails, double-check that the tools are installed and available on your `PATH` before trying again. + +### Filter emojis +Execute the tests with `pytest` command: +```bash +uv run pytest tests/test_governance_emojis.py +``` diff --git a/tests/test_governance_emojis.py b/tests/test_governance_emojis.py new file mode 100644 index 0000000..fa433fe --- /dev/null +++ b/tests/test_governance_emojis.py @@ -0,0 +1,69 @@ +"""Unit tests for the emoji filtering regex.""" + +from __future__ import annotations + +import os +from pathlib import Path + +import pytest + + +os.environ.setdefault("CONFIG_YAML", str(Path(__file__).resolve().parents[1] / "config.yaml")) + +from va_agent.governance import GovernancePlugin + + +def _make_plugin() -> GovernancePlugin: + plugin = object.__new__(GovernancePlugin) + plugin._combined_pattern = plugin._get_combined_pattern() + return plugin + + +@pytest.fixture() +def plugin() -> GovernancePlugin: + return _make_plugin() + + +@pytest.mark.parametrize( + ("original", "expected_clean", "expected_removed"), + [ + ("Hola πŸ”ͺ mundo", "Hola mundo", ["πŸ”ͺ"]), + ("No πŸ”ͺπŸ’€πŸš¬ permitidos", "No permitidos", ["πŸ”ͺ", "πŸ’€", "🚬"]), + ("Dedo πŸ–• grosero", "Dedo grosero", ["πŸ–•"]), + ("Dedo πŸ–•πŸΎ grosero", "Dedo grosero", ["πŸ–•πŸΎ"]), + ("Todo Amor: πŸ‘©β€β€οΈβ€πŸ‘¨ | πŸ‘©β€β€οΈβ€πŸ‘© | πŸ§‘β€β€οΈβ€πŸ§‘ | πŸ‘¨β€β€οΈβ€πŸ‘¨ | πŸ‘©β€β€οΈβ€πŸ’‹β€πŸ‘¨ | πŸ‘©β€β€οΈβ€πŸ’‹β€πŸ‘© | πŸ§‘β€β€οΈβ€πŸ’‹β€πŸ§‘ | πŸ‘¨β€β€οΈβ€πŸ’‹β€πŸ‘¨", "Todo Amor: | | | | | | |", ["πŸ‘©β€β€οΈβ€πŸ‘¨", "πŸ‘©β€β€οΈβ€πŸ‘©", "πŸ§‘β€β€οΈβ€πŸ§‘", "πŸ‘¨β€β€οΈβ€πŸ‘¨", "πŸ‘©β€β€οΈβ€πŸ’‹β€πŸ‘¨", "πŸ‘©β€β€οΈβ€πŸ’‹β€πŸ‘©", "πŸ§‘β€β€οΈβ€πŸ’‹β€πŸ§‘", "πŸ‘¨β€β€οΈβ€πŸ’‹β€πŸ‘¨"]), + ("Amor πŸ‘©πŸ½β€β€οΈβ€πŸ‘¨πŸ» bicolor", "Amor bicolor", ["πŸ‘©πŸ½β€β€οΈβ€πŸ‘¨πŸ»"]), + ("Beso πŸ‘©πŸ»β€β€οΈβ€πŸ’‹β€πŸ‘©πŸΏ bicolor gay", "Beso bicolor gay", ["πŸ‘©πŸ»β€β€οΈβ€πŸ’‹β€πŸ‘©πŸΏ"]), + ("Emoji compuesto permitido πŸ‘¨πŸ½β€πŸ’»", "Emoji compuesto permitido πŸ‘¨πŸ½β€πŸ’»", []), + ], +) +def test_remove_emojis_blocks_forbidden_sequences( + plugin: GovernancePlugin, + original: str, + expected_clean: str, + expected_removed: list[str], +) -> None: + cleaned, removed = plugin._remove_emojis(original) + + assert cleaned == expected_clean + assert removed == expected_removed + + +def test_remove_emojis_preserves_allowed_people_with_skin_tones( + plugin: GovernancePlugin, +) -> None: + original = "Persona πŸ‘©πŸ½ hola" + + cleaned, removed = plugin._remove_emojis(original) + + assert cleaned == original + assert removed == [] + + +def test_remove_emojis_trims_whitespace_after_removal( + plugin: GovernancePlugin, +) -> None: + cleaned, removed = plugin._remove_emojis(" πŸ”ͺHolaπŸ”ͺ ") + + assert cleaned == "Hola" + assert removed == ["πŸ”ͺ", "πŸ”ͺ"]