/
sapertlt
/
layout_switcher
Обзор
Документация
Войти
/
sapertlt
/
layout_switcher
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
tests/test_exclusions.py
115 строк
4 KB
Andrey Nikolaev
Initial commit: project setup
14 июн 2026, 23:24
14 июн 2026, 23:24
7085ffc
Код
Авторство
О чём код?
""" Тесты менеджера исключений (ExclusionManager). """ import pytest import tempfile from pathlib import Path from layout_switcher.core.exclusions import ExclusionManager class TestExclusionManager: """Тесты для ExclusionManager — словарь слов-исключений""" @pytest.fixture def exclusion_file(self, tmp_path): """Создаёт временный файл исключений""" file_path = tmp_path / "exclusions.txt" file_path.write_text( "# Комментарий\n" "git\n" "npm\n" "sudo\n" "\n" "# Паттерны\n" "*log*\n" "*.yaml\n" ) return file_path @pytest.fixture def manager(self, exclusion_file): return ExclusionManager(exclusion_file) # --- Точное совпадение --- def test_exact_match(self, manager): assert manager.is_excluded("git") is True def test_exact_match_case_insensitive(self, manager): """Проверка регистронезависимости""" assert manager.is_excluded("GIT") is True assert manager.is_excluded("Git") is True def test_not_excluded(self, manager): assert manager.is_excluded("python") is False # --- Wildcard паттерны --- def test_wildcard_contains(self, manager): """Паттерн *log* совпадает со словами, содержащими 'log'""" assert manager.is_excluded("changelog") is True assert manager.is_excluded("logfile") is True assert manager.is_excluded("mylogger") is True def test_wildcard_extension(self, manager): """Паттерн *.yaml совпадает""" assert manager.is_excluded("config.yaml") is True assert manager.is_excluded("test.yaml") is True def test_wildcard_no_match(self, manager): assert manager.is_excluded("hello") is False # --- Добавление и удаление --- def test_add_word(self, manager): manager.add("docker") assert manager.is_excluded("docker") is True def test_remove_word(self, manager): manager.remove("git") assert manager.is_excluded("git") is False def test_remove_nonexistent(self, manager): """Удаление несуществующего слова не вызывает ошибку""" manager.remove("nonexistent") # Не должно бросить исключение # --- Список --- def test_get_all(self, manager): all_words = manager.get_all() assert "git" in all_words assert "npm" in all_words assert "*log*" in all_words # --- Сохранение и загрузка --- def test_save_and_reload(self, exclusion_file): manager = ExclusionManager(exclusion_file) manager.add("newword") manager.save() # Перезагружаем manager2 = ExclusionManager(exclusion_file) assert manager2.is_excluded("newword") is True # --- Пустой файл --- def test_empty_file(self, tmp_path): file_path = tmp_path / "empty.txt" file_path.write_text("") manager = ExclusionManager(file_path) assert manager.is_excluded("anything") is False def test_nonexistent_file(self, tmp_path): """Несуществующий файл — менеджер создаётся с пустым списком""" file_path = tmp_path / "nonexistent.txt" manager = ExclusionManager(file_path) assert manager.is_excluded("anything") is False # --- Комментарии --- def test_comments_ignored(self, manager): """Строки с # не добавляются как слова""" assert manager.is_excluded("# Комментарий") is False assert manager.is_excluded("Комментарий") is False