dnd5-scripts/generate_npc/tests/test_regions.py

46 lines
1.6 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.

import sys
from pathlib import Path
# Добавляем родительскую папку в sys.path для импорта
scripts_path = Path(__file__).resolve().parent.parent
if str(scripts_path) not in sys.path:
sys.path.insert(0, str(scripts_path))
from regions import match_location
# ----------------------------------------------- Тесты Fuzzy Matcher ------------------------------------------------------------
def test_match_exact():
"""
Проверяет точное совпадение локации.
"""
assert match_location("Toril", "Waterdeep") == "Waterdeep"
assert match_location("Toril", "Neverwinter") == "Neverwinter"
def test_match_fuzzy():
"""
Проверяет коррекцию опечаток (fuzzy matching).
"""
assert match_location("Toril", "Watterdeep") == "Waterdeep"
assert match_location("Toril", "Neverwintar") == "Neverwinter"
assert match_location("Toril", "baldur gate") == "Baldur's Gate"
def test_match_unknown_world():
"""
Проверяет поведение при передаче неизвестного мира.
"""
assert match_location("Unknown", "Waterdeep") == "Waterdeep"
def test_match_no_correction_needed():
"""
Проверяет поведение для локаций, которых нет в словаре.
"""
assert match_location("Toril", "Some Random City") == "Some Random City"
if __name__ == "__main__":
test_match_exact()
test_match_fuzzy()
test_match_unknown_world()
test_match_no_correction_needed()
print("Все тесты match_location успешно пройдены!")