test_actor_base.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # switchbot-mqtt - MQTT client controlling SwitchBot button & curtain automators,
  2. # compatible with home-assistant.io's MQTT Switch & Cover platform
  3. #
  4. # Copyright (C) 2020 Fabian Peter Hammerle <fabian@hammerle.me>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. import typing
  19. import paho.mqtt.client
  20. import pytest
  21. import switchbot_mqtt
  22. # pylint: disable=protected-access
  23. def test_abstract():
  24. with pytest.raises(TypeError, match=r"\babstract class\b"):
  25. # pylint: disable=abstract-class-instantiated
  26. switchbot_mqtt._MQTTControlledActor(
  27. mac_address=None, retry_count=21, password=None
  28. )
  29. def test_execute_command_abstract():
  30. class _ActorMock(switchbot_mqtt._MQTTControlledActor):
  31. def __init__(
  32. self, mac_address: str, retry_count: int, password: typing.Optional[str]
  33. ) -> None:
  34. super().__init__(
  35. mac_address=mac_address, retry_count=retry_count, password=password
  36. )
  37. def execute_command(
  38. self, mqtt_message_payload: bytes, mqtt_client: paho.mqtt.client.Client
  39. ) -> None:
  40. super().execute_command(
  41. mqtt_message_payload=mqtt_message_payload, mqtt_client=mqtt_client
  42. )
  43. actor = _ActorMock(mac_address=None, retry_count=42, password=None)
  44. with pytest.raises(NotImplementedError):
  45. actor.execute_command(mqtt_message_payload=b"dummy", mqtt_client="dummy")