# tests/conftest.py import os from pathlib import Path from unittest.mock import MagicMock import pytest from exchangelib import Message from logwatcher.config import FIXTURE_PATH from logwatcher.logging_config import setup_logging # original log directory ORIGINAL_LOG_DIR = FIXTURE_PATH / "original_logs" # valid log directory VALID_LOG_DIR = FIXTURE_PATH / "valid_logs" # invalid_log_directory INVALID_LOG_DIR = FIXTURE_PATH / "invalid_logs" # define temp directory only for testing os.environ["PYTEST_DEBUG_TEMPROOT"] = str(Path("output/test").absolute()) @pytest.fixture def tmp_log_file(tmp_path): return tmp_path / "logwatcher_test.log" @pytest.fixture(autouse=True) def tmp_setup_logging(tmp_log_file): """Redirige les logs vers un dossier temporaire pendant les tests.""" setup_logging(file_path=tmp_log_file) @pytest.fixture(name="original_log_dir") def original_log_dir_fixture() -> Path: """ All real log files provided by N2 technicians. Used for integration tests: these files contain both valid lines and lines to be ignored (system logs, empty lines, directory headers). """ return FIXTURE_PATH / "original_logs" @pytest.fixture(name="valid_log_dir") def valid_log_dir_fixture() -> Path: """ All valid log files provided by N2 technicians. Used for integration tests: these files contain both relevant and irrelevant logs for N2 technicians. """ return FIXTURE_PATH / "valid_logs" @pytest.fixture(name="invalid_log_dir") def invalid_log_dir_fixture() -> Path: """ All invalid log files created for testing only. Used for integration tests of parsing. """ return FIXTURE_PATH / "invalid_logs" @pytest.fixture(scope="package") def make_mock_account(): """A fake Account with a msg_folder_root returning a fake Logs folder.""" def _make_mock_account( messages: list[Message] | None = None, analyzed_folder: MagicMock | None = None ): account = MagicMock() logs_folder = account.msg_folder_root.__truediv__.return_value logs_folder.all.return_value = messages or [] logs_folder.glob.return_value = [analyzed_folder] if analyzed_folder else [] return account return _make_mock_account