File: conftest.py

package info (click to toggle)
python-gios 6.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 272 kB
  • sloc: python: 774; sh: 7; makefile: 2
file content (117 lines) | stat: -rw-r--r-- 3,513 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
"""Set up some common test helper things."""

import json
from collections.abc import AsyncGenerator, Generator
from pathlib import Path
from typing import Any

import aiohttp
import pytest
import pytest_asyncio
from aioresponses import aioresponses
from syrupy.assertion import SnapshotAssertion
from syrupy.extensions.amber import AmberSnapshotExtension
from syrupy.location import PyTestLocation

BASE = "tests/fixtures/"


@pytest_asyncio.fixture
async def session() -> AsyncGenerator[aiohttp.ClientSession]:
    """Return a mock ClientSession."""
    session = aiohttp.ClientSession()
    yield session
    await session.close()


@pytest.fixture
def session_mock() -> Generator[aioresponses]:
    """Create a reusable aioresponses mock."""
    with aioresponses() as mock:
        yield mock


@pytest.fixture
def stations() -> list[dict[str, Any]]:
    """Return stations data from the fixture file."""
    with Path.open(Path(f"{BASE}stations.json"), encoding="utf-8") as file:
        return json.load(file)


@pytest.fixture
def station() -> list[dict[str, Any]]:
    """Return the station data from the fixture file."""
    with Path.open(Path(f"{BASE}station.json"), encoding="utf-8") as file:
        return json.load(file)


@pytest.fixture
def indexes() -> dict[str, Any]:
    """Return indexes data from the fixture file."""
    with Path.open(Path(f"{BASE}indexes.json"), encoding="utf-8") as file:
        return json.load(file)


@pytest.fixture
def sensor_3759() -> dict[str, Any]:
    """Return sensor 3759 data from the fixture file."""
    with Path.open(Path(f"{BASE}sensor_3759.json"), encoding="utf-8") as file:
        return json.load(file)


@pytest.fixture
def sensor_3760() -> dict[str, Any]:
    """Return sensor 3760 data from the fixture file."""
    with Path.open(Path(f"{BASE}sensor_3760.json"), encoding="utf-8") as file:
        return json.load(file)


@pytest.fixture
def sensor_3761() -> dict[str, Any]:
    """Return sensor 3761 data from the fixture file."""
    with Path.open(Path(f"{BASE}sensor_3761.json"), encoding="utf-8") as file:
        return json.load(file)


@pytest.fixture
def sensor_3762() -> dict[str, Any]:
    """Return sensor 3762 data from the fixture file."""
    with Path.open(Path(f"{BASE}sensor_3762.json"), encoding="utf-8") as file:
        return json.load(file)


@pytest.fixture
def sensor_3764() -> dict[str, Any]:
    """Return sensor 3764 data from the fixture file."""
    with Path.open(Path(f"{BASE}sensor_3764.json"), encoding="utf-8") as file:
        return json.load(file)


@pytest.fixture
def sensor_3765() -> dict[str, Any]:
    """Return sensor 3765 data from the fixture file."""
    with Path.open(Path(f"{BASE}sensor_3765.json"), encoding="utf-8") as file:
        return json.load(file)


@pytest.fixture
def sensor_14688() -> dict[str, Any]:
    """Return sensor 14688 data from the fixture file."""
    with Path.open(Path(f"{BASE}sensor_14688.json"), encoding="utf-8") as file:
        return json.load(file)


@pytest.fixture
def snapshot(snapshot: SnapshotAssertion) -> SnapshotAssertion:
    """Return snapshot assertion fixture."""
    return snapshot.use_extension(SnapshotExtension)


class SnapshotExtension(AmberSnapshotExtension):
    """Extension for Syrupy."""

    @classmethod
    def dirname(cls, *, test_location: PyTestLocation) -> str:
        """Return the directory for the snapshot files."""
        test_dir = Path(test_location.filepath).parent
        return str(test_dir.joinpath("snapshots"))