File: conftest.py

package info (click to toggle)
python-maison 2.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 816 kB
  • sloc: python: 1,549; makefile: 9; sh: 5
file content (36 lines) | stat: -rw-r--r-- 1,084 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""Store the classes and fixtures used throughout the tests."""

from pathlib import Path
from typing import Any
from typing import Callable
from typing import Optional

import pytest


@pytest.fixture(name="create_tmp_file")
def create_tmp_file_fixture(tmp_path: Path) -> Callable[..., Path]:
    """Fixture for creating a temporary file."""

    def _create_tmp_file(content: str = "", filename: str = "file.txt") -> Path:
        tmp_file = tmp_path / filename
        tmp_file.write_text(content)
        return tmp_file

    return _create_tmp_file


@pytest.fixture
def create_pyproject_toml(create_toml: Callable[..., Path]) -> Callable[..., Path]:
    """Fixture for creating a `pyproject.toml`."""

    def _create_pyproject_toml(
        section_name: str = "foo",
        content: Optional[dict[str, Any]] = None,
        filename: str = "pyproject.toml",
    ) -> Path:
        content = content or {"bar": "baz"}
        config_dict = {"tool": {section_name: content}}
        return create_toml(filename=filename, content=config_dict)

    return _create_pyproject_toml