fix: running test suite with immutable hook hints

Signed-off-by: Tom Carrio <tom@carrio.dev>
This commit is contained in:
Tom Carrio 2022-11-22 17:27:26 -05:00
parent 63619164c1
commit a18481c75e
2 changed files with 18 additions and 15 deletions

View File

@ -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]:

View File

@ -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
)