From a18481c75ed00878eb2c88891da820566cab30f5 Mon Sep 17 00:00:00 2001 From: Tom Carrio Date: Tue, 22 Nov 2022 17:27:26 -0500 Subject: [PATCH] fix: running test suite with immutable hook hints Signed-off-by: Tom Carrio --- open_feature/open_feature_client.py | 17 ++++++++--------- tests/hooks/test_hook_support.py | 16 ++++++++++------ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/open_feature/open_feature_client.py b/open_feature/open_feature_client.py index e9ab068..d6e2cf7 100644 --- a/open_feature/open_feature_client.py +++ b/open_feature/open_feature_client.py @@ -25,7 +25,6 @@ from open_feature.open_feature_evaluation_context import api_evaluation_context from open_feature.provider.no_op_provider import NoOpProvider from open_feature.provider.provider import AbstractProvider - GetDetailCallable = typing.Union[ typing.Callable[ [str, bool, typing.Optional[EvaluationContext]], FlagEvaluationDetails[bool] @@ -252,15 +251,11 @@ class OpenFeatureClient: # in the flag evaluation # before: API, Client, Invocation, Provider merged_hooks = ( - self.hooks - + flag_evaluation_options.hooks - + self.provider.get_provider_hooks() + self.hooks + evaluation_hooks + self.provider.get_provider_hooks() ) # after, error, finally: Provider, Invocation, Client, API reversed_merged_hooks = ( - self.provider.get_provider_hooks() - + flag_evaluation_options.hooks - + self.hooks + self.provider.get_provider_hooks() + evaluation_hooks + self.hooks ) try: @@ -286,7 +281,11 @@ class OpenFeatureClient: ) after_hooks( - flag_type, hook_context, flag_evaluation, reversed_merged_hooks, hook_hints, + flag_type, + hook_context, + flag_evaluation, + reversed_merged_hooks, + hook_hints, ) return flag_evaluation @@ -363,7 +362,7 @@ class OpenFeatureClient: raise TypeMismatchError() return value - + def __extract_evaluation_options( self, flag_evaluation_options: typing.Any ) -> typing.Tuple[typing.List[Hook], MappingProxyType]: diff --git a/tests/hooks/test_hook_support.py b/tests/hooks/test_hook_support.py index 5a5d8e3..28914c4 100644 --- a/tests/hooks/test_hook_support.py +++ b/tests/hooks/test_hook_support.py @@ -9,7 +9,7 @@ from open_feature.hooks.hook_support import ( before_hooks, error_hooks, ) -from open_feature.immutable_dict import MappingProxyType +from open_feature.immutable_dict.mapping_proxy_type import MappingProxyType def test_error_hooks_run_error_method(mock_hook): @@ -21,7 +21,9 @@ def test_error_hooks_run_error_method(mock_hook): # Then mock_hook.supports_flag_value_type.assert_called_once() mock_hook.error.assert_called_once() - mock_hook.error.assert_called_with(hook_context, ANY, hook_hints) + mock_hook.error.assert_called_with( + hook_context=hook_context, exception=ANY, hints=hook_hints + ) def test_before_hooks_run_before_method(mock_hook): @@ -33,7 +35,7 @@ def test_before_hooks_run_before_method(mock_hook): # Then mock_hook.supports_flag_value_type.assert_called_once() mock_hook.before.assert_called_once() - mock_hook.error.assert_called_with(hook_context, hook_hints) + mock_hook.before.assert_called_with(hook_context=hook_context, hints=hook_hints) def test_after_hooks_run_after_method(mock_hook): @@ -50,8 +52,8 @@ def test_after_hooks_run_after_method(mock_hook): # Then mock_hook.supports_flag_value_type.assert_called_once() mock_hook.after.assert_called_once() - mock_hook.error.assert_called_with( - hook_context, flag_evaluation_details, hook_hints + mock_hook.after.assert_called_with( + hook_context=hook_context, details=flag_evaluation_details, hints=hook_hints ) @@ -64,4 +66,6 @@ def test_finally_after_hooks_run_finally_after_method(mock_hook): # Then mock_hook.supports_flag_value_type.assert_called_once() mock_hook.finally_after.assert_called_once() - mock_hook.error.assert_called_with(hook_context, hook_hints) + mock_hook.finally_after.assert_called_with( + hook_context=hook_context, hints=hook_hints + )