# pylint: disable=missing-docstring,redefined-outer-name
import os
import tempfile
from collections.abc import Mapping, MutableMapping
from pathlib import Path
from unittest import mock

from unittest_fixtures import FixtureContext, Fixtures, fixture


@fixture()
def environ(
    _fixtures: Fixtures, *, environ: Mapping[str, str] | None = None
) -> FixtureContext[MutableMapping[str, str]]:
    environ = environ or {}

    with mock.patch.dict(os.environ, clear=True):
        os.environ.update(environ)
        yield os.environ


@fixture()
def tmpdir(_fixtures: Fixtures) -> FixtureContext[Path]:
    with tempfile.TemporaryDirectory() as tempdir:
        yield Path(tempdir)
