diff --git a/meiga/result.py b/meiga/result.py index 2ad2ec0..9b0d436 100644 --- a/meiga/result.py +++ b/meiga/result.py @@ -103,7 +103,11 @@ def unwrap_or_else( if not self._is_success: if on_failure: if failure_args: - failure_args = list(failure_args) + failure_args = ( + list(failure_args) + if isinstance(failure_args, tuple) + else [failure_args] + ) if Result.__id__ in failure_args: index_meiga_result = failure_args.index(Result.__id__) failure_args[index_meiga_result] = self @@ -121,7 +125,11 @@ def unwrap_and(self, on_success: Callable, success_args=None): if self._is_success: if on_success: if success_args: - success_args = list(success_args) + success_args = ( + list(success_args) + if isinstance(success_args, tuple) + else [success_args] + ) if Result.__id__ in success_args: index_meiga_result = success_args.index(Result.__id__) success_args[index_meiga_result] = self diff --git a/tests/unit/test_result_handle.py b/tests/unit/test_result_handle.py index 3ce789b..018e280 100644 --- a/tests/unit/test_result_handle.py +++ b/tests/unit/test_result_handle.py @@ -219,3 +219,25 @@ def run(): ) run() + + +@pytest.mark.parametrize("result", [isSuccess, isFailure]) +def test_should_execute_handler_with_only_one_parameter(result): + given_first_parameter = 1 + + def on_success(param_1: int): + assert param_1 == 1 + + def on_failure(param_1: int): + assert param_1 == 1 + + @meiga + def run(): + result.handle( + on_success=on_success, + on_failure=on_failure, + success_args=given_first_parameter, + failure_args=given_first_parameter, + ) + + run()