-
Notifications
You must be signed in to change notification settings - Fork 30
feat: Add evaluation details to finally hook stage #403 #423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
beeme1mr
merged 12 commits into
open-feature:main
from
chrfwow:Add-evaluation-details-to-finally-hook-stage-#403
Jan 30, 2025
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f1676e7
Add evaluation details to finally hook stage #403
chrfwow 71bedbd
fixup! Add evaluation details to finally hook stage #403
chrfwow fc97b1b
fixup! Add evaluation details to finally hook stage #403
chrfwow cb8a432
Merge branch 'main' into Add-evaluation-details-to-finally-hook-stage…
chrfwow d0d74cf
fixup! Add evaluation details to finally hook stage #403
chrfwow e803ae6
fixup! Add evaluation details to finally hook stage #403
chrfwow 6f71842
fixup! Add evaluation details to finally hook stage #403
chrfwow 07b512e
fixup! Add evaluation details to finally hook stage #403
chrfwow 81f15df
fixup! Add evaluation details to finally hook stage #403
chrfwow 66c4a8f
fixup! Add evaluation details to finally hook stage #403
chrfwow d37a56f
Merge branch 'main' into Add-evaluation-details-to-finally-hook-stage…
gruebel 005007d
Merge branch 'main' into Add-evaluation-details-to-finally-hook-stage…
beeme1mr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| from unittest.mock import MagicMock | ||
|
|
||
| from behave import then, when | ||
|
|
||
| from openfeature.exception import ErrorCode | ||
| from openfeature.hook import Hook | ||
|
|
||
|
|
||
| @when("a hook is added to the client") | ||
| def step_impl_add_hook(context): | ||
| hook = MagicMock(spec=Hook) | ||
| hook.before = MagicMock() | ||
| hook.after = MagicMock() | ||
| hook.error = MagicMock() | ||
| hook.finally_after = MagicMock() | ||
| context.hook = hook | ||
| context.client.add_hooks([hook]) | ||
|
|
||
|
|
||
| @then("error hooks should be called") | ||
| def step_impl_call_error(context): | ||
| assert context.hook.before.called | ||
| assert context.hook.error.called | ||
| assert context.hook.finally_after.called | ||
|
|
||
|
|
||
| @then("non-error hooks should be called") | ||
| def step_impl_call_non_error(context): | ||
| assert context.hook.before.called | ||
| assert context.hook.after.called | ||
| assert context.hook.finally_after.called | ||
|
|
||
|
|
||
| def get_hook_from_name(context, hook_name): | ||
| if hook_name.lower() == "before": | ||
| return context.hook.before | ||
| elif hook_name.lower() == "after": | ||
| return context.hook.after | ||
| elif hook_name.lower() == "error": | ||
| return context.hook.error | ||
| elif hook_name.lower() == "finally": | ||
| return context.hook.finally_after | ||
| else: | ||
| raise ValueError(str(hook_name) + " is not a valid hook name") | ||
|
|
||
|
|
||
| def convert_value_from_flag_type(value, flag_type): | ||
| if value == "None": | ||
| return None | ||
| if flag_type.lower() == "boolean": | ||
| return bool(value) | ||
| elif flag_type.lower() == "integer": | ||
| return int(value) | ||
| elif flag_type.lower() == "float": | ||
| return float(value) | ||
| return value | ||
|
|
||
|
|
||
| @then('"{hook_names}" hooks should have evaluation details') | ||
| def step_impl_should_have_eval_details(context, hook_names): | ||
| for hook_name in hook_names.split(", "): | ||
| hook = get_hook_from_name(context, hook_name) | ||
| for row in context.table: | ||
| flag_type, key, value = row | ||
|
|
||
| value = convert_value_from_flag_type(value, flag_type) | ||
|
|
||
| actual = hook.call_args[1]["details"].__dict__[key] | ||
| if isinstance(actual, ErrorCode): | ||
| actual = str(actual) | ||
|
|
||
| assert actual == value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.