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
|
import pytest
from APsystemsEZ1 import InverterReturnedError
@pytest.mark.asyncio
@pytest.mark.parametrize(
"test_id, output_data, expected_status",
[
("happy-on", {"data": {"status": 0}, "status": 0}, True),
("happy-off", {"data": {"status": 1}, "status": 0}, False),
],
)
async def test_get_device_power_status_happy_paths(
test_id, output_data, expected_status, mock_response
):
# Arrange
ez1m = mock_response(output_data)
# Act
status = await ez1m.get_device_power_status()
# Assert
assert status == expected_status, f"Test failed for {test_id}"
@pytest.mark.asyncio
@pytest.mark.parametrize(
"test_id, output_data",
[
("edge-no-status", {"data": {"status": ""}, "status": 0}),
],
)
async def test_get_device_power_status_value_error(test_id, output_data, mock_response):
# Arrange
ez1m = mock_response(output_data)
# Assert
with pytest.raises(InverterReturnedError):
await ez1m.get_device_power_status()
@pytest.mark.asyncio
@pytest.mark.parametrize(
"test_id, output_data",
[
("edge-empty-data", {"data": {}, "status": 0}),
("error-malformed-data", {"wrong": "data"}),
],
)
async def test_get_device_power_status_key_error(test_id, output_data, mock_response):
# Arrange
ez1m = mock_response(output_data)
# Assert
with pytest.raises(KeyError) as exc_info:
await ez1m.get_device_power_status()
|