Skip to content

Commit

Permalink
Update tests to make use of snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
DCSBL committed Nov 14, 2023
1 parent 0fa8e88 commit ddeb879
Show file tree
Hide file tree
Showing 6 changed files with 451 additions and 1,195 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ repos:
entry: poetry run check-executables-have-shebangs
stages: [commit, push, manual]
- id: check-json
name: Check JSON files
name: Check JSON files
language: system
types: [json]
entry: poetry run check-json
Expand Down
1,197 changes: 324 additions & 873 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ packages = [
[tool.poetry.dependencies]
python = "^3.9"
aiohttp = ">=3.0.0"
awesomeversion = ">=22.9.0"

[tool.poetry.dev-dependencies]
aresponses = "^2.1.6"
Expand Down Expand Up @@ -47,6 +46,7 @@ darglint = "^1.8.1"
safety = "^2.3.5"
codespell = "^2.2.6"
bandit = "^1.7.5"
syrupy = "^4.6.0"

[tool.poetry.urls]
"Bug Tracker" = "https://github.com/dcsbl/python-homewizard-energy/issues"
Expand Down
52 changes: 52 additions & 0 deletions tests/__snapshots__/test_models.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# serializer version: 1
# name: test_data[data_energysocket.json]
Data(wifi_ssid='My Wi-Fi', wifi_strength=100, smr_version=None, meter_model=None, unique_meter_id=None, active_tariff=None, total_energy_import_kwh=10830.511, total_energy_import_t1_kwh=10830.511, total_energy_import_t2_kwh=None, total_energy_import_t3_kwh=None, total_energy_import_t4_kwh=None, total_energy_export_kwh=2948.827, total_energy_export_t1_kwh=2948.827, total_energy_export_t2_kwh=None, total_energy_export_t3_kwh=None, total_energy_export_t4_kwh=None, active_power_w=123, active_power_l1_w=123, active_power_l2_w=None, active_power_l3_w=None, active_voltage_l1_v=None, active_voltage_l2_v=None, active_voltage_l3_v=None, active_current_l1_a=None, active_current_l2_a=None, active_current_l3_a=None, active_frequency_hz=None, voltage_sag_l1_count=None, voltage_sag_l2_count=None, voltage_sag_l3_count=None, voltage_swell_l1_count=None, voltage_swell_l2_count=None, voltage_swell_l3_count=None, any_power_fail_count=None, long_power_fail_count=None, active_power_average_w=None, monthly_power_peak_w=None, monthly_power_peak_timestamp=None, total_gas_m3=None, gas_timestamp=None, gas_unique_id=None, active_liter_lpm=None, total_liter_m3=None, external_devices=None)
# ---
# name: test_data[data_kwh_single_phase.json]
Data(wifi_ssid='My Wi-Fi', wifi_strength=100, smr_version=None, meter_model=None, unique_meter_id=None, active_tariff=None, total_energy_import_kwh=10830.511, total_energy_import_t1_kwh=10830.511, total_energy_import_t2_kwh=None, total_energy_import_t3_kwh=None, total_energy_import_t4_kwh=None, total_energy_export_kwh=2948.827, total_energy_export_t1_kwh=2948.827, total_energy_export_t2_kwh=None, total_energy_export_t3_kwh=None, total_energy_export_t4_kwh=None, active_power_w=640, active_power_l1_w=640, active_power_l2_w=None, active_power_l3_w=None, active_voltage_l1_v=None, active_voltage_l2_v=None, active_voltage_l3_v=None, active_current_l1_a=None, active_current_l2_a=None, active_current_l3_a=None, active_frequency_hz=None, voltage_sag_l1_count=None, voltage_sag_l2_count=None, voltage_sag_l3_count=None, voltage_swell_l1_count=None, voltage_swell_l2_count=None, voltage_swell_l3_count=None, any_power_fail_count=None, long_power_fail_count=None, active_power_average_w=None, monthly_power_peak_w=None, monthly_power_peak_timestamp=None, total_gas_m3=None, gas_timestamp=None, gas_unique_id=None, active_liter_lpm=None, total_liter_m3=None, external_devices=None)
# ---
# name: test_data[data_kwh_three_phase.json]
Data(wifi_ssid='My Wi-Fi', wifi_strength=100, smr_version=None, meter_model=None, unique_meter_id=None, active_tariff=None, total_energy_import_kwh=10830.511, total_energy_import_t1_kwh=10830.511, total_energy_import_t2_kwh=None, total_energy_import_t3_kwh=None, total_energy_import_t4_kwh=None, total_energy_export_kwh=2948.827, total_energy_export_t1_kwh=2948.827, total_energy_export_t2_kwh=None, total_energy_export_t3_kwh=None, total_energy_export_t4_kwh=None, active_power_w=-543, active_power_l1_w=-676, active_power_l2_w=133, active_power_l3_w=0, active_voltage_l1_v=None, active_voltage_l2_v=None, active_voltage_l3_v=None, active_current_l1_a=None, active_current_l2_a=None, active_current_l3_a=None, active_frequency_hz=None, voltage_sag_l1_count=None, voltage_sag_l2_count=None, voltage_sag_l3_count=None, voltage_swell_l1_count=None, voltage_swell_l2_count=None, voltage_swell_l3_count=None, any_power_fail_count=None, long_power_fail_count=None, active_power_average_w=None, monthly_power_peak_w=None, monthly_power_peak_timestamp=None, total_gas_m3=None, gas_timestamp=None, gas_unique_id=None, active_liter_lpm=None, total_liter_m3=None, external_devices=None)
# ---
# name: test_data[data_p1.json]
Data(wifi_ssid='My Wi-Fi', wifi_strength=100, smr_version=50, meter_model='ISKRA 2M550T-101', unique_meter_id=None, active_tariff=None, total_energy_import_kwh=10830.511, total_energy_import_t1_kwh=10830.511, total_energy_import_t2_kwh=2948.827, total_energy_import_t3_kwh=None, total_energy_import_t4_kwh=None, total_energy_export_kwh=1285.951, total_energy_export_t1_kwh=1285.951, total_energy_export_t2_kwh=2876.51, total_energy_export_t3_kwh=None, total_energy_export_t4_kwh=None, active_power_w=-543, active_power_l1_w=-676, active_power_l2_w=133, active_power_l3_w=0, active_voltage_l1_v=None, active_voltage_l2_v=None, active_voltage_l3_v=None, active_current_l1_a=None, active_current_l2_a=None, active_current_l3_a=None, active_frequency_hz=None, voltage_sag_l1_count=None, voltage_sag_l2_count=None, voltage_sag_l3_count=None, voltage_swell_l1_count=None, voltage_swell_l2_count=None, voltage_swell_l3_count=None, any_power_fail_count=None, long_power_fail_count=None, active_power_average_w=None, monthly_power_peak_w=None, monthly_power_peak_timestamp=None, total_gas_m3=2569.646, gas_timestamp=datetime.datetime(2021, 6, 6, 14, 0, 10), gas_unique_id=None, active_liter_lpm=None, total_liter_m3=None, external_devices=None)
# ---
# name: test_data[data_p1_full.json]
Data(wifi_ssid='My Wi-Fi', wifi_strength=100, smr_version=50, meter_model='ISKRA 2M550T-101', unique_meter_id='NGGYU', active_tariff=2, total_energy_import_kwh=13779.338, total_energy_import_t1_kwh=10830.511, total_energy_import_t2_kwh=2948.827, total_energy_import_t3_kwh=None, total_energy_import_t4_kwh=None, total_energy_export_kwh=0, total_energy_export_t1_kwh=0, total_energy_export_t2_kwh=0, total_energy_export_t3_kwh=None, total_energy_export_t4_kwh=None, active_power_w=-543, active_power_l1_w=-676, active_power_l2_w=133, active_power_l3_w=0, active_voltage_l1_v=None, active_voltage_l2_v=None, active_voltage_l3_v=None, active_current_l1_a=-4, active_current_l2_a=2, active_current_l3_a=0, active_frequency_hz=50, voltage_sag_l1_count=1, voltage_sag_l2_count=1, voltage_sag_l3_count=0, voltage_swell_l1_count=0, voltage_swell_l2_count=0, voltage_swell_l3_count=0, any_power_fail_count=4, long_power_fail_count=5, active_power_average_w=123.0, monthly_power_peak_w=1111.0, monthly_power_peak_timestamp=datetime.datetime(2023, 1, 1, 8, 0, 10), total_gas_m3=2569.646, gas_timestamp=datetime.datetime(2021, 6, 6, 14, 0, 10), gas_unique_id='NGLYD', active_liter_lpm=None, total_liter_m3=None, external_devices={'NGLYD': ExternalDevice(unique_id='NGLYD', meter_type=<DeviceType.GAS_METER: 3>, value=111.111, unit='m3', timestamp=datetime.datetime(2021, 6, 6, 14, 0, 10)), 'NGRAADY': ExternalDevice(unique_id='NGRAADY', meter_type=<DeviceType.HEAT_METER: 4>, value=222.222, unit='m3', timestamp=datetime.datetime(2021, 6, 6, 14, 0, 10)), 'NGMYC': ExternalDevice(unique_id='NGMYC', meter_type=<DeviceType.WARM_WATER_METER: 6>, value=333.333, unit='m3', timestamp=datetime.datetime(2021, 6, 6, 14, 0, 10)), 'NGSG': ExternalDevice(unique_id='NGSG', meter_type=<DeviceType.WATER_METER: 7>, value=444.444, unit='m3', timestamp=datetime.datetime(2021, 6, 6, 14, 0, 10)), 'NGTALAHY': ExternalDevice(unique_id='NGTALAHY', meter_type=<DeviceType.INLET_HEAT_METER: 12>, value=555.555, unit='m3', timestamp=datetime.datetime(2021, 6, 6, 14, 0, 10))})
# ---
# name: test_data[data_p1_no_gas.json]
Data(wifi_ssid='My Wi-Fi', wifi_strength=100, smr_version=50, meter_model='ISKRA 2M550T-101', unique_meter_id=None, active_tariff=None, total_energy_import_kwh=10830.511, total_energy_import_t1_kwh=10830.511, total_energy_import_t2_kwh=2948.827, total_energy_import_t3_kwh=None, total_energy_import_t4_kwh=None, total_energy_export_kwh=1285.951, total_energy_export_t1_kwh=1285.951, total_energy_export_t2_kwh=2876.51, total_energy_export_t3_kwh=None, total_energy_export_t4_kwh=None, active_power_w=-543, active_power_l1_w=-676, active_power_l2_w=133, active_power_l3_w=0, active_voltage_l1_v=None, active_voltage_l2_v=None, active_voltage_l3_v=None, active_current_l1_a=None, active_current_l2_a=None, active_current_l3_a=None, active_frequency_hz=None, voltage_sag_l1_count=None, voltage_sag_l2_count=None, voltage_sag_l3_count=None, voltage_swell_l1_count=None, voltage_swell_l2_count=None, voltage_swell_l3_count=None, any_power_fail_count=None, long_power_fail_count=None, active_power_average_w=None, monthly_power_peak_w=None, monthly_power_peak_timestamp=None, total_gas_m3=None, gas_timestamp=None, gas_unique_id=None, active_liter_lpm=None, total_liter_m3=None, external_devices=None)
# ---
# name: test_data[data_p1_single_phase.json]
Data(wifi_ssid='My Wi-Fi', wifi_strength=100, smr_version=50, meter_model='ISKRA 2M550T-101', unique_meter_id=None, active_tariff=None, total_energy_import_kwh=10830.511, total_energy_import_t1_kwh=10830.511, total_energy_import_t2_kwh=2948.827, total_energy_import_t3_kwh=None, total_energy_import_t4_kwh=None, total_energy_export_kwh=1285.951, total_energy_export_t1_kwh=1285.951, total_energy_export_t2_kwh=2876.51, total_energy_export_t3_kwh=None, total_energy_export_t4_kwh=None, active_power_w=-543, active_power_l1_w=-676, active_power_l2_w=None, active_power_l3_w=None, active_voltage_l1_v=None, active_voltage_l2_v=None, active_voltage_l3_v=None, active_current_l1_a=None, active_current_l2_a=None, active_current_l3_a=None, active_frequency_hz=None, voltage_sag_l1_count=None, voltage_sag_l2_count=None, voltage_sag_l3_count=None, voltage_swell_l1_count=None, voltage_swell_l2_count=None, voltage_swell_l3_count=None, any_power_fail_count=None, long_power_fail_count=None, active_power_average_w=None, monthly_power_peak_w=None, monthly_power_peak_timestamp=None, total_gas_m3=2569.646, gas_timestamp=datetime.datetime(2021, 6, 6, 14, 0, 10), gas_unique_id=None, active_liter_lpm=None, total_liter_m3=None, external_devices=None)
# ---
# name: test_data[data_watermeter.json]
Data(wifi_ssid='My Wi-Fi', wifi_strength=100, smr_version=None, meter_model=None, unique_meter_id=None, active_tariff=None, total_energy_import_kwh=None, total_energy_import_t1_kwh=None, total_energy_import_t2_kwh=None, total_energy_import_t3_kwh=None, total_energy_import_t4_kwh=None, total_energy_export_kwh=None, total_energy_export_t1_kwh=None, total_energy_export_t2_kwh=None, total_energy_export_t3_kwh=None, total_energy_export_t4_kwh=None, active_power_w=None, active_power_l1_w=None, active_power_l2_w=None, active_power_l3_w=None, active_voltage_l1_v=None, active_voltage_l2_v=None, active_voltage_l3_v=None, active_current_l1_a=None, active_current_l2_a=None, active_current_l3_a=None, active_frequency_hz=None, voltage_sag_l1_count=None, voltage_sag_l2_count=None, voltage_sag_l3_count=None, voltage_swell_l1_count=None, voltage_swell_l2_count=None, voltage_swell_l3_count=None, any_power_fail_count=None, long_power_fail_count=None, active_power_average_w=None, monthly_power_peak_w=None, monthly_power_peak_timestamp=None, total_gas_m3=None, gas_timestamp=None, gas_unique_id=None, active_liter_lpm=13.12, total_liter_m3=8129.123, external_devices=None)
# ---
# name: test_decryption[decryption.json]
Decryption(key_set=True, aad_set=True)
# ---
# name: test_device[device.json]
Device(product_name='P1 Meter', product_type='HWE-P1', serial='3c39e7aabbcc', api_version='v1', firmware_version='2.11')
# ---
# name: test_device[device_energysocket.json]
Device(product_name='Energy Socket', product_type='HWE-SKT', serial='3c39e7aabbcc', api_version='v1', firmware_version='2.11')
# ---
# name: test_device[device_extra_parameters.json]
Device(product_name='P1 Meter', product_type='HWE-P1', serial='3c39e7aabbcc', api_version='v1', firmware_version='2.11')
# ---
# name: test_device[device_invalid_api.json]
Device(product_name='P1 Meter', product_type='HWE-P1', serial='3c39e7aabbcc', api_version='v2', firmware_version='2.11')
# ---
# name: test_state[state.json]
State(power_on=False, switch_lock=False, brightness=255)
# ---
# name: test_state[state_switch_lock_and_brightness.json]
State(power_on=True, switch_lock=True, brightness=10)
# ---
# name: test_system[system_cloud_disabled.json]
System(cloud_enabled=False)
# ---
# name: test_system[system_cloud_enabled.json]
System(cloud_enabled=True)
# ---
23 changes: 2 additions & 21 deletions tests/test_homewizard_energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

from . import load_fixtures

pytestmark = [pytest.mark.asyncio]


@pytest.mark.asyncio
async def test_request_returns_json(aresponses):
"""Test JSON response is handled correctly."""
aresponses.add(
Expand All @@ -31,7 +32,6 @@ async def test_request_returns_json(aresponses):
await api.close()


@pytest.mark.asyncio
async def test_request_internal_session(aresponses):
"""Test session is closed when created internally."""
aresponses.add(
Expand All @@ -50,7 +50,6 @@ async def test_request_internal_session(aresponses):
await api.close()


@pytest.mark.asyncio
async def test_request_returns_txt(aresponses):
"""Test request returns raw text when non-json."""
aresponses.add(
Expand All @@ -71,7 +70,6 @@ async def test_request_returns_txt(aresponses):
await api.close()


@pytest.mark.asyncio
async def test_request_detects_403(aresponses):
"""Test request detects disabled API."""
aresponses.add(
Expand All @@ -93,7 +91,6 @@ async def test_request_detects_403(aresponses):
await api.close()


@pytest.mark.asyncio
async def test_request_detects_non_200(aresponses):
"""Test detects non-ok response."""
aresponses.add(
Expand All @@ -115,7 +112,6 @@ async def test_request_detects_non_200(aresponses):
await api.close()


@pytest.mark.asyncio
async def test_request_detects_clienterror():
"""Test other clienterror."""
async with aiohttp.ClientSession() as session:
Expand All @@ -129,7 +125,6 @@ async def test_request_detects_clienterror():
await api.close()


@pytest.mark.asyncio
async def test_get_device_object(aresponses):
"""Test device object is fetched and sets detected values."""

Expand All @@ -154,7 +149,6 @@ async def test_get_device_object(aresponses):
await api.close()


@pytest.mark.asyncio
async def test_get_device_object_detects_invalid_api(aresponses):
"""Test raises error when invalid API is used."""

Expand All @@ -178,7 +172,6 @@ async def test_get_device_object_detects_invalid_api(aresponses):
await api.close()


@pytest.mark.asyncio
async def test_get_data_object(aresponses):
"""Test fetches data object and device object when unknown."""

Expand Down Expand Up @@ -215,7 +208,6 @@ async def test_get_data_object(aresponses):
await api.close()


@pytest.mark.asyncio
async def test_get_data_object_with_known_device(aresponses):
"""Test fetches data object."""

Expand Down Expand Up @@ -243,7 +235,6 @@ async def test_get_data_object_with_known_device(aresponses):
await api.close()


@pytest.mark.asyncio
async def test_get_state_object(aresponses):
"""Test fetches state object and device object when unknown."""

Expand Down Expand Up @@ -279,7 +270,6 @@ async def test_get_state_object(aresponses):
await api.close()


@pytest.mark.asyncio
async def test_get_state_object_with_known_device(aresponses):
"""Test fetches state object."""

Expand Down Expand Up @@ -315,7 +305,6 @@ async def test_get_state_object_with_known_device(aresponses):
await api.close()


@pytest.mark.asyncio
async def test_state_set(aresponses):
"""Test state set."""

Expand All @@ -339,7 +328,6 @@ async def test_state_set(aresponses):
await api.close()


@pytest.mark.asyncio
async def test_state_set_detects_no_statechange(aresponses):
"""Test state set does not send request when nothing is changed."""

Expand All @@ -361,7 +349,6 @@ async def test_state_set_detects_no_statechange(aresponses):
assert not state


@pytest.mark.asyncio
async def test_identify(aresponses):
"""Test identify call."""

Expand All @@ -385,7 +372,6 @@ async def test_identify(aresponses):
await api.close()


@pytest.mark.asyncio
async def test_identify_not_available(aresponses):
"""Test identify call when not supported."""

Expand All @@ -409,7 +395,6 @@ async def test_identify_not_available(aresponses):
await api.close()


@pytest.mark.asyncio
async def test_get_system_object(aresponses):
"""Test fetches system object and device object when unknown."""

Expand Down Expand Up @@ -460,7 +445,6 @@ async def test_get_system_object(aresponses):
await api.close()


@pytest.mark.asyncio
async def test_system_set(aresponses):
"""Test system set."""

Expand All @@ -484,7 +468,6 @@ async def test_system_set(aresponses):
await api.close()


@pytest.mark.asyncio
async def test_get_decryption_object(aresponses):
"""Test fetches decryption object."""

Expand Down Expand Up @@ -521,7 +504,6 @@ async def test_get_decryption_object(aresponses):
await api.close()


@pytest.mark.asyncio
async def test_decryption_set(aresponses):
"""Test decryption set."""

Expand Down Expand Up @@ -562,7 +544,6 @@ async def test_decryption_set(aresponses):
await api.close()


@pytest.mark.asyncio
async def test_decryption_reset(aresponses):
"""Test decryption reset."""

Expand Down
Loading

0 comments on commit ddeb879

Please sign in to comment.