from audita.protection import ProtectedVocabulary from audita.schemas import parse_glossary_yaml def _vocabulary(): glossary = parse_glossary_yaml( """ glossary: - name: "Hrank" aliases: - "Greenfield" category: pc summary: "Hrank Greenfield is a player character." """ ) return ProtectedVocabulary.from_glossary(glossary) def test_protection_blocks_replacing_protected_term(): vocabulary = _vocabulary() assert vocabulary.violation_reason("Hrank moves.", "Frank moves.") is not None def test_protection_blocks_lowercasing_protected_term(): vocabulary = _vocabulary() assert vocabulary.violation_reason("Hrank moves.", "hrank moves.") is not None def test_protection_allows_canonical_capitalization(): vocabulary = _vocabulary() assert vocabulary.violation_reason("hrank moves.", "Hrank moves.") is None def test_protection_allows_punctuation_around_protected_term(): vocabulary = _vocabulary() assert vocabulary.violation_reason("Hrank, moves.", "Hrank. Moves.") is None def test_protection_does_not_match_terms_inside_larger_words(): vocabulary = _vocabulary() assert vocabulary.violation_reason("The shrank spell worked.", "The shrank spell works.") is None def test_protection_applies_to_aliases(): vocabulary = _vocabulary() assert vocabulary.violation_reason("Greenfield waits.", "greenfield waits.") is not None