123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- from module import mqtt_test_client, init_state, state_change_by_mqtt
- from devices import my_powerplug as test_device
- from devices.base import warning
- from mqtt import mqtt_client
- import pytest
- import time
-
- DUT_CLIENT_ID = "__%s__" % __name__
- TOPIC = "__test__/%s" % __name__
- #
- MQTT_SIGNAL_TIME = 0.2
-
-
- ALL_STATE_KEYS = ["output/1", "output/2", "output/3", "output/4", ]
- BOOL_KEYS = ALL_STATE_KEYS
-
-
- @pytest.fixture
- def this_device():
- mc = mqtt_client(DUT_CLIENT_ID, 'localhost')
- return test_device(mc, TOPIC)
-
-
- def test_initial_states(this_device: test_device):
- # test all initial values
- init_state(ALL_STATE_KEYS, this_device)
-
-
- def test_state_change_by_mqtt(this_device: test_device):
- def state_data(key):
- return (True, False)
-
- def mqtt_data(key):
- return state_data(key)
-
- # test state changes
- tm_warning = state_change_by_mqtt(ALL_STATE_KEYS, 2, mqtt_test_client, TOPIC, this_device,
- mqtt_data, state_data, None, MQTT_SIGNAL_TIME)
-
-
- def test_specific_get_functions(this_device: test_device):
- assert this_device.output_0 == this_device.get(this_device.KEY_OUTPUT_0)
- assert this_device.output_1 == this_device.get(this_device.KEY_OUTPUT_1)
- assert this_device.output_2 == this_device.get(this_device.KEY_OUTPUT_2)
- assert this_device.output_3 == this_device.get(this_device.KEY_OUTPUT_3)
|