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." - name: "Popov" category: npc summary: "Popov is an allied NPC." - name: "Jesters" aliases: - "Jester" category: faction summary: "The Jesters are a faction." - name: "Svend" category: pc summary: "Svend is a player character." - name: "Godfrey" category: npc summary: "Godfrey is an NPC." - name: "Lyra" category: npc summary: "Lyra is an NPC." - name: "Loviator" category: deity summary: "Loviator is a deity." """ ) return ProtectedVocabulary.from_glossary(glossary) def test_protection_blocks_replacing_protected_term(): vocabulary = _vocabulary() assert ( vocabulary.violation_reason("Hrank moves.", "Frank moves.") == "correction changes protected glossary term usage" ) def test_protection_blocks_replacing_possessive_protected_term(): vocabulary = _vocabulary() assert vocabulary.violation_reason("Popov's exhausted.", "Pawpaw's exhausted.") is not None def test_protection_blocks_lowercasing_protected_term(): vocabulary = _vocabulary() assert ( vocabulary.violation_reason("Hrank moves.", "hrank moves.") == "correction changes protected glossary term capitalization" ) def test_protection_blocks_noncanonical_uppercase_protected_term(): vocabulary = _vocabulary() assert vocabulary.violation_reason("Popov moves.", "POPOV 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_unchanged_noncanonical_protected_term(): vocabulary = _vocabulary() assert vocabulary.violation_reason("jesters advance.", "jesters advance.") is None def test_protection_allows_correction_toward_protected_term(): vocabulary = _vocabulary() assert vocabulary.violation_reason("Pawpaw moves.", "Popov moves.") is None assert vocabulary.violation_reason("gestures", "Jesters") is None assert vocabulary.violation_reason("rank", "Hrank") is None assert vocabulary.violation_reason("spend", "Svend") is None def test_protection_allows_possessive_correction_toward_protected_term(): vocabulary = _vocabulary() assert vocabulary.violation_reason("Pawpaw's exhausted.", "Popov's exhausted.") is None def test_protection_blocks_noncanonical_introduced_protected_term(): vocabulary = _vocabulary() assert ( vocabulary.violation_reason("gestures", "jesters") == "correction changes protected glossary term capitalization" ) assert ( vocabulary.violation_reason("rank", "hrank") == "correction changes protected glossary term capitalization" ) assert ( vocabulary.violation_reason("spend", "svend") == "correction changes protected glossary term capitalization" ) def test_protection_blocks_changed_noncanonical_variant(): vocabulary = _vocabulary() assert ( vocabulary.violation_reason("jesters advance.", "JESTERS advance.") == "correction changes protected glossary term capitalization" ) def test_protection_allows_inferred_name_plural(): vocabulary = _vocabulary() assert vocabulary.violation_reason("Godfrey's", "Godfreys") is None def test_protection_allows_inferred_alias_plural(): vocabulary = _vocabulary() assert vocabulary.violation_reason("gesture", "Jesters") is None def test_protection_allows_explicit_plural(): glossary = parse_glossary_yaml( """ glossary: - name: "Mox" plural: "Moxen" category: faction summary: "The Mox are a faction." """ ) vocabulary = ProtectedVocabulary.from_glossary(glossary) assert vocabulary.violation_reason("Mox's", "Moxen") is None assert ( vocabulary.violation_reason("Mox's", "moxen") == "correction changes protected glossary term capitalization" ) def test_protection_allows_punctuation_around_protected_term(): vocabulary = _vocabulary() assert vocabulary.violation_reason("Popov, moves.", "Popov. Moves.") is None def test_protection_allows_quote_wrapping_sentence_with_unchanged_lowercase_protected_term(): vocabulary = _vocabulary() before = ( "When you say that, Popov will say, when I was in that room with the jesters, " "I just knew that Godfrey and Lyra came directly from Loviator herself." ) after = ( 'When you say that, Popov will say, "When I was in that room with the jesters, ' 'I just knew that Godfrey and Lyra came directly from Loviator herself."' ) assert vocabulary.violation_reason(before, after) 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 def test_protection_blocks_removing_preexisting_protected_occurrence(): vocabulary = _vocabulary() assert ( vocabulary.violation_reason("Jesters flank the Jesters.", "Jesters flank the gestures.") == "correction changes protected glossary term usage" )