Skip to content

Commit

Permalink
Use syrupy for model testing (#830)
Browse files Browse the repository at this point in the history
* Update dependencies: bump Poetry to 1.8.4 and add Syrupy 4.7.2

* Add snapshot tests for Device and SmartBridge models
  • Loading branch information
klaasnicolaas authored Nov 11, 2024
1 parent bb51888 commit 102e392
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 17 deletions.
18 changes: 16 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ yarl = ">=1.6.0"
Changelog = "https://github.com/klaasnicolaas/python-gridnet/releases"

[tool.poetry.group.dev.dependencies]
ruff = "0.7.3"
aresponses = "3.0.0"
codespell = "2.3.0"
covdefaults = "2.3.0"
coverage = {version = "7.6.4", extras = ["toml"]}
mypy = "1.13.0"
pre-commit = "4.0.1"
Expand All @@ -47,8 +47,9 @@ pylint = "3.3.1"
pytest = "8.3.3"
pytest-asyncio = "0.24.0"
pytest-cov = "6.0.0"
ruff = "0.7.3"
syrupy = "4.7.2"
yamllint = "1.35.1"
covdefaults = "2.3.0"

[tool.coverage.run]
plugins = ["covdefaults"]
Expand Down
7 changes: 7 additions & 0 deletions tests/__snapshots__/test_models.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# serializer version: 1
# name: test_device
Device(n2g_id='84df:0c11:9999:3795', model='SBWF3102', batch='SBP-HMX-210318', firmware='1.6.16', hardware=1, manufacturer='NET2GRID')
# ---
# name: test_smartbridge
SmartBridge(power_flow=338, energy_consumption_total=17762.1, energy_production_total=21214.6)
# ---
24 changes: 11 additions & 13 deletions tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
"""Test the models."""

from aresponses import ResponsesMockServer
from syrupy.assertion import SnapshotAssertion

from gridnet import Device, GridNet, SmartBridge

from . import load_fixtures


async def test_device(aresponses: ResponsesMockServer, gridnet_client: GridNet) -> None:
async def test_device(
aresponses: ResponsesMockServer,
snapshot: SnapshotAssertion,
gridnet_client: GridNet,
) -> None:
"""Test request from the device - Device object."""
aresponses.add(
"127.0.0.1",
Expand All @@ -19,17 +24,13 @@ async def test_device(aresponses: ResponsesMockServer, gridnet_client: GridNet)
),
)
device: Device = await gridnet_client.device()
assert device
assert device.n2g_id == "84df:0c11:9999:3795"
assert device.model == "SBWF3102"
assert device.batch == "SBP-HMX-210318"
assert device.firmware == "1.6.16"
assert device.hardware == 1
assert device.manufacturer == "NET2GRID"
assert device == snapshot


async def test_smartbridge(
aresponses: ResponsesMockServer, gridnet_client: GridNet
aresponses: ResponsesMockServer,
snapshot: SnapshotAssertion,
gridnet_client: GridNet,
) -> None:
"""Test request from the device - SmartBridge object."""
aresponses.add(
Expand All @@ -42,7 +43,4 @@ async def test_smartbridge(
),
)
smartbridge: SmartBridge = await gridnet_client.smartbridge()
assert smartbridge
assert smartbridge.power_flow == 338
assert smartbridge.energy_consumption_total == 17762.1
assert smartbridge.energy_production_total == 21214.6
assert smartbridge == snapshot

0 comments on commit 102e392

Please sign in to comment.