def test_execute_int_int_ok(usb_handle_mock): usb_handle_mock.execute_remote_function_int_int.return_value = 20 result = ActionSelector.select_and_execute(usb_handle_mock, "fake_int_int_function", 13, 67) usb_handle_mock.execute_remote_function_int_int.assert_called_with("fake_int_int_function", 13, 67) assert result == 20
def test_execute_float_ok(usb_handle_mock): usb_handle_mock.execute_remote_function_float.return_value = 18.11 result = ActionSelector.select_and_execute(usb_handle_mock, "fake_float_function", 11.18) usb_handle_mock.execute_remote_function_float.assert_called_with("fake_float_function", 11.18) assert result == 18.11
def test_execute_string_ok(usb_handle_mock): usb_handle_mock.execute_remote_function_str.return_value = "result_value" result = ActionSelector.select_and_execute(usb_handle_mock, "fake_string_function", "test_value") usb_handle_mock.execute_remote_function_str.assert_called_with("fake_string_function", "test_value") assert result == "result_value"
def execute_remote_function(self, function_name: str, arg1=None, arg2=None): ''' Executes a function (of Arduino sketch) with signature selected by the not none arguments combination :param function_name: the name of Arduino's function to call. :param arg1: the optional first argument :param arg2: the optional second argument (must be None if arg1 is None) :return: the Arduino response if arg1 is not none; None otherwise ''' return ActionSelector.select_and_execute(self.usb_handler, function_name, arg1, arg2)
def test_execute_int_int_with_int_float_fails(usb_handle_mock): with pytest.raises(LocalException, match="Error calling fake_method: invalid second argument type. Found float instead of int"): ActionSelector.select_and_execute(usb_handle_mock, "fake_method", 8, 33.2)
def test_execute_int_int_with_arg1_none_fails(usb_handle_mock): with pytest.raises(LocalException, match="Error calling fake_method: invalid empty first argument with the second argument: 6.19"): ActionSelector.select_and_execute(usb_handle_mock, "fake_method", None, 6.19)
def test_execute_int_int_without_name_fails(usb_handle_mock): with pytest.raises(LocalException, match=EMPTY_ACTION_NAME_EXCEPTION): ActionSelector.select_and_execute(usb_handle_mock, None, 38, 43) with pytest.raises(LocalException, match=EMPTY_ACTION_NAME_EXCEPTION): ActionSelector.select_and_execute(usb_handle_mock, "", 6, 82)
def test_execute_string_without_name_fails(usb_handle_mock): with pytest.raises(LocalException, match=EMPTY_ACTION_NAME_EXCEPTION): ActionSelector.select_and_execute(usb_handle_mock, None, "fake_Arg") with pytest.raises(LocalException, match=EMPTY_ACTION_NAME_EXCEPTION): ActionSelector.select_and_execute(usb_handle_mock, "", "fake_Arg")
def test_execute_void_ok(usb_handle_mock): usb_handle_mock.execute_remote_function.return_value = None result = ActionSelector.select_and_execute(usb_handle_mock, "fake_void_function") usb_handle_mock.execute_remote_function.assert_called_with("fake_void_function") assert result is None