-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aaca598
commit 59e5716
Showing
4 changed files
with
22 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,16 +1,20 @@ | ||
from typing import Callable | ||
from functools import wraps | ||
from typing import Callable | ||
|
||
from exchange.observers.base import ObserverManager | ||
|
||
def observe_wrapper(*args, **kwargs) -> Callable: | ||
|
||
def observe_wrapper(*args, **kwargs) -> Callable: # noqa: ANN002, ANN003 | ||
"""Decorator to wrap a function with all registered observer plugins, dynamically fetched.""" | ||
def wrapper(func): | ||
|
||
def wrapper(func: Callable) -> Callable: | ||
@wraps(func) | ||
def dynamic_wrapped(*func_args, **func_kwargs): | ||
def dynamic_wrapped(*func_args, **func_kwargs) -> Callable: # noqa: ANN002, ANN003 | ||
wrapped = func | ||
for observer in ObserverManager.get_instance()._observers: | ||
wrapped = observer.observe_wrapper(*args, **kwargs)(wrapped) | ||
return wrapped(*func_args, **func_kwargs) | ||
|
||
return dynamic_wrapped | ||
return wrapper | ||
|
||
return wrapper |
This file contains 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 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 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 |
---|---|---|
@@ -1,12 +1,16 @@ | ||
from goose.profile import ToolkitSpec, ObserverSpec | ||
|
||
|
||
def test_profile_info(profile_factory): | ||
profile = profile_factory( | ||
{ | ||
"provider": "provider", | ||
"processor": "processor", | ||
"toolkits": [ToolkitSpec("developer"), ToolkitSpec("github")], | ||
"observers": [ObserverSpec(name="test.plugin")] | ||
"observers": [ObserverSpec(name="test.plugin")], | ||
} | ||
) | ||
assert profile.profile_info() == "provider:provider, processor:processor toolkits: developer, github observers: test.plugin" | ||
assert ( | ||
profile.profile_info() | ||
== "provider:provider, processor:processor toolkits: developer, github observers: test.plugin" | ||
) |