test_actor_base.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 paho.mqtt.client
  19. import pytest
  20. import switchbot_mqtt
  21. # pylint: disable=protected-access
  22. def test_abstract():
  23. with pytest.raises(TypeError, match=r"\babstract class\b"):
  24. # pylint: disable=abstract-class-instantiated
  25. switchbot_mqtt._MQTTControlledActor(mac_address=None, retry_count=21)
  26. def test_execute_command_abstract():
  27. class _ActorMock(switchbot_mqtt._MQTTControlledActor):
  28. def __init__(self, mac_address: str, retry_count: int) -> None:
  29. super().__init__(mac_address=mac_address, retry_count=retry_count)
  30. def execute_command(
  31. self, mqtt_message_payload: bytes, mqtt_client: paho.mqtt.client.Client
  32. ) -> None:
  33. super().execute_command(
  34. mqtt_message_payload=mqtt_message_payload, mqtt_client=mqtt_client
  35. )
  36. actor = _ActorMock(mac_address=None, retry_count=42)
  37. with pytest.raises(NotImplementedError):
  38. actor.execute_command(mqtt_message_payload=b"dummy", mqtt_client="dummy")