"""
Tests for wittrans

SPDX-FileCopyrightText: 2024 Jiri Grönroos <jiri.gronroos@iki.fi>

SPDX-License-Identifier: LGPL-3.0-or-later
"""

from unittest.mock import MagicMock

import pytest


# https://docs.pytest.org/en/stable/reference/fixtures.html#conftest-py-sharing-fixtures-across-multiple-files
# Mock for rich print function - shared fixture across test modules
@pytest.fixture
def mock_rprint(monkeypatch):
    printed_messages = []

    def mock_print(message):
        printed_messages.append(message)

    monkeypatch.setattr("wittrans.search.rprint", mock_print)
    return printed_messages


@pytest.fixture
def mock_pool():
    """
    Create a mock Pool that executes functions sequentially without multiprocessing.
    """

    def mock_imap(func, args_list):
        results = []
        for args in args_list:
            results.append(func(args))
        return iter(results)

    pool = MagicMock()
    pool.__enter__ = MagicMock(return_value=pool)
    pool.__exit__ = MagicMock(return_value=None)
    pool.imap = mock_imap

    return pool
