Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RJPoelstra committed Feb 3, 2025
1 parent 5477220 commit 8d7c6d2
Showing 1 changed file with 139 additions and 0 deletions.
139 changes: 139 additions & 0 deletions tests/components/motionmount/test_sensor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
"""Tests for the MotionMount Sensor platform."""

from unittest.mock import MagicMock, PropertyMock

import motionmount

from homeassistant.core import HomeAssistant

from . import ZEROCONF_NAME

from tests.common import MockConfigEntry

MAC = bytes.fromhex("c4dd57f8a55f")


async def test_error_status_sensor_none(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
mock_motionmount_config_flow: MagicMock,
) -> None:
"""Tests the state attributes."""
mock_config_entry.add_to_hass(hass)

type(mock_motionmount_config_flow).name = PropertyMock(return_value=ZEROCONF_NAME)
type(mock_motionmount_config_flow).mac = PropertyMock(return_value=MAC)
type(mock_motionmount_config_flow).is_authenticated = PropertyMock(
return_value=True
)
assert await hass.config_entries.async_setup(mock_config_entry.entry_id)

assert hass.states.get("sensor.my_motionmount_error_status").state == "none"

Check failure on line 31 in tests/components/motionmount/test_sensor.py

View workflow job for this annotation

GitHub Actions / Run tests Python 3.13 (motionmount)

test_error_status_sensor_none AttributeError: 'NoneType' object has no attribute 'state'


async def test_error_status_sensor_motor(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
mock_motionmount_config_flow: MagicMock,
) -> None:
"""Tests the state attributes."""
mock_config_entry.add_to_hass(hass)

type(mock_motionmount_config_flow).name = PropertyMock(return_value=ZEROCONF_NAME)
type(mock_motionmount_config_flow).mac = PropertyMock(return_value=MAC)
type(mock_motionmount_config_flow).is_authenticated = PropertyMock(
return_value=True
)
type(mock_motionmount_config_flow).system_status = PropertyMock(
return_value=[motionmount.MotionMountSystemError.MotorError]
)
assert await hass.config_entries.async_setup(mock_config_entry.entry_id)

assert hass.states.get("sensor.my_motionmount_error_status").state == "motor"

Check failure on line 52 in tests/components/motionmount/test_sensor.py

View workflow job for this annotation

GitHub Actions / Run tests Python 3.13 (motionmount)

test_error_status_sensor_motor AttributeError: 'NoneType' object has no attribute 'state'


async def test_error_status_sensor_obstruction(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
mock_motionmount_config_flow: MagicMock,
) -> None:
"""Tests the state attributes."""
mock_config_entry.add_to_hass(hass)

type(mock_motionmount_config_flow).name = PropertyMock(return_value=ZEROCONF_NAME)
type(mock_motionmount_config_flow).mac = PropertyMock(return_value=MAC)
type(mock_motionmount_config_flow).is_authenticated = PropertyMock(
return_value=True
)
type(mock_motionmount_config_flow).system_status = PropertyMock(
return_value=[motionmount.MotionMountSystemError.ObstructionDetected]
)
assert await hass.config_entries.async_setup(mock_config_entry.entry_id)

assert hass.states.get("sensor.my_motionmount_error_status").state == "obstruction"

Check failure on line 73 in tests/components/motionmount/test_sensor.py

View workflow job for this annotation

GitHub Actions / Run tests Python 3.13 (motionmount)

test_error_status_sensor_obstruction AttributeError: 'NoneType' object has no attribute 'state'


async def test_error_status_sensor_tv_width_constraint(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
mock_motionmount_config_flow: MagicMock,
) -> None:
"""Tests the state attributes."""
mock_config_entry.add_to_hass(hass)

type(mock_motionmount_config_flow).name = PropertyMock(return_value=ZEROCONF_NAME)
type(mock_motionmount_config_flow).mac = PropertyMock(return_value=MAC)
type(mock_motionmount_config_flow).is_authenticated = PropertyMock(
return_value=True
)
type(mock_motionmount_config_flow).system_status = PropertyMock(
return_value=[motionmount.MotionMountSystemError.TVWidthConstraintError]
)
assert await hass.config_entries.async_setup(mock_config_entry.entry_id)

assert (
hass.states.get("sensor.my_motionmount_error_status").state

Check failure on line 95 in tests/components/motionmount/test_sensor.py

View workflow job for this annotation

GitHub Actions / Run tests Python 3.13 (motionmount)

test_error_status_sensor_tv_width_constraint AttributeError: 'NoneType' object has no attribute 'state'
== "tv_width_constraint"
)


async def test_error_status_sensor_hdmi_cec(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
mock_motionmount_config_flow: MagicMock,
) -> None:
"""Tests the state attributes."""
mock_config_entry.add_to_hass(hass)

type(mock_motionmount_config_flow).name = PropertyMock(return_value=ZEROCONF_NAME)
type(mock_motionmount_config_flow).mac = PropertyMock(return_value=MAC)
type(mock_motionmount_config_flow).is_authenticated = PropertyMock(
return_value=True
)
type(mock_motionmount_config_flow).system_status = PropertyMock(
return_value=[motionmount.MotionMountSystemError.HDMICECError]
)
assert await hass.config_entries.async_setup(mock_config_entry.entry_id)

assert hass.states.get("sensor.my_motionmount_error_status").state == "hdmi_cec"

Check failure on line 118 in tests/components/motionmount/test_sensor.py

View workflow job for this annotation

GitHub Actions / Run tests Python 3.13 (motionmount)

test_error_status_sensor_hdmi_cec AttributeError: 'NoneType' object has no attribute 'state'


async def test_error_status_sensor_internal(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
mock_motionmount_config_flow: MagicMock,
) -> None:
"""Tests the state attributes."""
mock_config_entry.add_to_hass(hass)

type(mock_motionmount_config_flow).name = PropertyMock(return_value=ZEROCONF_NAME)
type(mock_motionmount_config_flow).mac = PropertyMock(return_value=MAC)
type(mock_motionmount_config_flow).is_authenticated = PropertyMock(
return_value=True
)
type(mock_motionmount_config_flow).system_status = PropertyMock(
return_value=[motionmount.MotionMountSystemError.InternalError]
)
assert await hass.config_entries.async_setup(mock_config_entry.entry_id)

assert hass.states.get("sensor.my_motionmount_error_status").state == "internal"

Check failure on line 139 in tests/components/motionmount/test_sensor.py

View workflow job for this annotation

GitHub Actions / Run tests Python 3.13 (motionmount)

test_error_status_sensor_internal AttributeError: 'NoneType' object has no attribute 'state'

0 comments on commit 8d7c6d2

Please sign in to comment.