def test_set_value_events_delta(): spine = MockupSpine() number = NumberValue("Dynamic Number", value_id="dn", spine=spine) number.delta = 10 assert number.value == 0 number.value = 5 assert number.value == 0 assert "valueChanged" not in spine.events.keys() spine.events = {} number.value = 10 assert number.value == 10 assert spine.events["valueChanged"]["args"][0]["value"] == 10 spine.events = {} number.value = 7 assert number.value == 10 assert "valueChanged" not in spine.events.keys() spine.events = {} number.value = 0 assert number.value == 0 assert spine.events["valueChanged"]["args"][0]["value"] == 0
def test_action_async(): global P1, P2, K1 spine = MockupSpine() set_spine(spine) configuration = get_test_config() P1 = "a" P2 = "b" K1 = "c" @action def action_func_async(p1, p2, **kwargs): global P1, P2, K1, event time.sleep(2) P1 = p1 P2 = p2 K1 = kwargs.get("k1", None) event.set() spine.clear() Actions["action_func_async"]("axa", "bxa", k1="kxa", run_async=True) assert P1 == "a" assert P2 == "b" assert K1 == "c" event.wait(5) assert P1 == "axa" assert P2 == "bxa" assert K1 == "kxa"
def test_controller_exit_event_no_start(): spine = MockupSpine() configuration = get_test_config() controller = XController(spine=spine, configuration=configuration) assert not controller.exit_event spine.simulate_app_exit() assert not controller.exit_event
def test_value_change(): spine = MockupSpine() configuration = get_test_config() controller = XController(spine=spine, configuration=configuration) spine.simulate_app_start() controller.input_1.value = 1 assert controller.last_input == controller.input_1 assert controller.output.value == 1 controller.input_2.value = 2 assert controller.output.value == 3
def test_boolean_instantiation(): spine = MockupSpine() number = BooleanValue("Dynamic Boolean", value_id="db", spine=spine) assert number.value_id == "db" assert number.name == "Dynamic Boolean" assert number.value == False
def test_number_instantiation(): spine = MockupSpine() number = NumberValue("Dynamic Number", value_id="dn", spine=spine) assert number.value_id == "dn" assert number.name == "Dynamic Number" assert number.value == 0 assert number.is_input == True
def test_set_value_events(): spine = MockupSpine() number = NumberValue("Dynamic Number", value_id="dn", spine=spine) number.value = 10 assert "valueChanged" in spine.events.keys() assert spine.events["valueChanged"]["args"][0]["value"] == 10
def test_single_sensor(): spine = MockupSpine() device = MockupSensorDeviceDriver() device.value = 10 sensor = Sensor("test_id", "Test sensor", device, spine=spine, configuration = get_test_config()) assert sensor.device == device assert sensor.value_type == "temperature" assert sensor.value_unit == "C" spine.simulate_app_start() sensor_thread = MockupSensorThread(sensor) sensor_thread.step() assert sensor.value == 10
def test_boolean_set_value(): spine = MockupSpine() number = BooleanValue("Dynamic Boolean", value_id="db", spine=spine) number.value = True assert number.value == True number.value = False assert number.value == False
def test_instantiation(): spine = MockupSpine() component = KerviComponent("test_component", "component", "Test component", spine=spine) assert component.component_id == "test_component" assert component.component_type == "component" assert component.name == "Test component" assert component.visible assert "getDashboardComponents" in spine.queryHandlers assert "getComponentInfo" in spine.queryHandlers
def test_controller_creation(): spine = MockupSpine() configuration = get_test_config() controller = XController(spine=spine, configuration=configuration) assert controller.controller_id == "test_controller" assert controller.input_1.value == 0 assert controller.input_2.value == 0 assert controller.output.value == 0
def test_value_instantitation_output(): spine = MockupSpine() value = KerviValue("Dynamic Value", "Dynamic-test-value", is_input=False, value_id="dv", spine=spine) assert value.value_id == "dv" assert value.name == "Dynamic Value" assert value.value == None assert value.is_input == False
def test_action_messages(): spine = MockupSpine() set_spine(spine) configuration = get_test_config() @action def action_func(p1, p2, **kwargs): global P1, P2, K1 P1 = p1 P2 = p2 K1 = kwargs.get("k1", None) spine.clear() Actions["action_func"]("ax", "bx", k1="kx") commands = spine.get_send_commands("messageManagerSend") assert P1 == "ax" assert P2 == "bx" assert K1 == "kx" assert len(commands) == 2
def test_value_instantitation_input(): spine = MockupSpine() value = KerviValue("Dynamic Value", "Dynamic-test-value", value_id="dv", spine=spine, configuration=get_test_config()) assert value.value_id == "dv" assert value.name == "Dynamic Value" assert value.value == None assert value.is_input == True
def test_multi_sensor(): spine = MockupSpine() device = MockupMultiDimSensorDeviceDriver() device.value1 = 10 device.value2 = 20 device.value3 = 30 sensor = Sensor("test_id", "Test sensor", device, spine=spine, configuration = get_test_config()) assert sensor.device == device assert sensor.value_type == "position" assert sensor.value_unit == "degree" spine.simulate_app_start() sensor_thread = MockupSensorThread(sensor) sensor_thread.step() assert sensor[0].value == 10 assert sensor[1].value == 20 assert sensor[2].value == 30
def test_linking_transformation(): spine = MockupSpine() number_out = NumberValue("Dynamic Number", is_input=False, value_id="dn", spine=spine) number_in = NumberValue("Dynamic Number", value_id="dn", spine=spine) assert number_out.value == 0 assert number_in.value == 0 number_out.link_to(number_in, lambda x: -2 * x) number_out.value = 10 assert number_in.value == -20
def test_linking_out_to_in(): spine = MockupSpine() number_out = NumberValue("Dynamic Number", is_input=False, value_id="dn", spine=spine) number_in = NumberValue("Dynamic Number", value_id="dn", spine=spine) assert number_out.value == 0 assert number_in.value == 0 number_out.link_to(number_in) number_out.value = 10 assert number_in.value == 10
def test_function_action_alternative_id(): spine = MockupSpine() set_spine(spine) configuration = get_test_config() @action(action_id="action_func_x") def action_func(p1, p2): global P1, P2 P1 = p1 P2 = p2 Actions["action_func_x"]("a1", "b1") assert P1 == "a1" assert P2 == "b1"
def test_function_action_direct(): spine = MockupSpine() set_spine(spine) configuration = get_test_config() @action def action_func(p1, p2, **kwargs): global P1, P2, K1 P1 = p1 P2 = p2 K1 = kwargs.get("k1", None) action_func("a", "b", k1="k") assert P1 == "a" assert P2 == "b" assert K1 == "k"
def test_controller_action(): spine = MockupSpine() set_spine(spine) configuration = get_test_config() class TestController(Controller): def __init__(self): Controller.__init__(self, "test_controller", "Test controller") self.p1 = None self.p2 = None @action def action1(self, p1, p2): self.p1 = p1 self.p2 = p2 tc = TestController() Actions["test_controller.action1"]("ca", "cb") assert tc.p1 == "ca" assert tc.p2 == "cb"
def test_controller_action_direct(): spine = MockupSpine() set_spine(spine) configuration = get_test_config() class TestController(Controller): def __init__(self): Controller.__init__(self, "test_controller3", "Test controller") self.p1 = None self.p2 = None @action(action_id="actionx") def action1(self, p1, p2): self.p1 = p1 self.p2 = p2 tc = TestController() tc.action1("cax", "cbx") assert tc.p1 == "cax" assert tc.p2 == "cbx"
def test_number_set_value(): spine = MockupSpine() number = NumberValue("Dynamic Number", value_id="dn", spine=spine) number.value = 10 assert number.value == 10