Skip to content

Commit

Permalink
Remove pytest-datadir dependency (#197)
Browse files Browse the repository at this point in the history
* Use pytest-datadir instead of pytest-dataset

* Add fixture for json loading, remove dependency

* Bump version 3.3.1 → 3.3.2

---------

Co-authored-by: tr4nt0r <manni@zapto.de>
  • Loading branch information
oynqr and tr4nt0r authored Jul 14, 2024
1 parent 42ae2e4 commit b7c7630
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
1 change: 0 additions & 1 deletion requirements_test.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pytest==8.2.2
pytest-cov==5.0.0
pytest-dataset==0.3.2
pytest-xdist==3.6.1
requests-mock[fixture]==1.12.1
syrupy==4.6.1
2 changes: 1 addition & 1 deletion src/pyecotrend_ista/const.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Constants for PyEcotrendIsta."""

VERSION = "3.3.1"
VERSION = "3.3.2"

API_BASE_URL = "https://api.prod.eed.ista.com/"

Expand Down
8 changes: 8 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Fixtures for Tests."""

from http import HTTPStatus
from pathlib import Path

import pytest
from requests_mock.mocker import Mocker as RequestsMock
Expand All @@ -12,6 +13,13 @@
DEMO_EMAIL = DEMO_USER_ACCOUNT
TEST_PASSWORD = "password"

@pytest.fixture
def json_data(request) -> str:
"""Load json test data."""
file = getattr(request, "param", "test_data")
path = Path(__file__).parent / "data" / f"{file}.json"
return path.read_text(encoding="utf-8")


@pytest.fixture
def ista_client(request) -> PyEcotrendIsta:
Expand Down
12 changes: 6 additions & 6 deletions tests/test_consumptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
from pyecotrend_ista.const import API_BASE_URL


def test_get_comsumption_data(ista_client: PyEcotrendIsta, requests_mock: RequestsMock, snapshot: SnapshotAssertion, dataset) -> None:
def test_get_comsumption_data(ista_client: PyEcotrendIsta, requests_mock: RequestsMock, snapshot: SnapshotAssertion, json_data: str,) -> None:
"""Test `_set_account` method."""

requests_mock.get(f"{API_BASE_URL}consumptions", json=dataset["test_data"])
requests_mock.get(f"{API_BASE_URL}consumptions", text=json_data)

assert ista_client.get_consumption_data("26e93f1a-c828-11ea-87d0-0242ac130003") == snapshot

Expand Down Expand Up @@ -59,10 +59,10 @@ def test_get_comsumption_data_exceptions(requests_mock: RequestsMock, ista_clien
ista_client.get_consumption_data("26e93f1a-c828-11ea-87d0-0242ac130003")


def test_consum_raw(ista_client: PyEcotrendIsta, requests_mock: RequestsMock, snapshot: SnapshotAssertion, dataset) -> None:
def test_consum_raw(ista_client: PyEcotrendIsta, requests_mock: RequestsMock, snapshot: SnapshotAssertion, json_data: str) -> None:
"""Test `cunsum_raw` method."""

requests_mock.get(f"{API_BASE_URL}consumptions", json=dataset["test_data"])
requests_mock.get(f"{API_BASE_URL}consumptions", text=json_data)
result = ista_client.consum_raw(obj_uuid="26e93f1a-c828-11ea-87d0-0242ac130003")

# consum_raw returns consum_types list in random order, so we exclude it from snapshot matcher
Expand Down Expand Up @@ -112,14 +112,14 @@ def test_consum_raw_filters(
ista_client: PyEcotrendIsta,
requests_mock: RequestsMock,
snapshot: SnapshotAssertion,
dataset,
json_data: str,
select_year: list[int],
select_month: list[int],
filter_none: bool,
) -> None:
"""Test `cunsum_raw` method."""

requests_mock.get(f"{API_BASE_URL}consumptions", json=dataset["test_data"])
requests_mock.get(f"{API_BASE_URL}consumptions", text=json_data)
result = ista_client.consum_raw(
obj_uuid="26e93f1a-c828-11ea-87d0-0242ac130003",
select_year=select_year,
Expand Down

0 comments on commit b7c7630

Please sign in to comment.