-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make sure adapters can access the context of their parent chain
- Loading branch information
Showing
2 changed files
with
26 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import refiners.fluxion.layers as fl | ||
from refiners.fluxion.adapters.adapter import Adapter | ||
from refiners.fluxion.context import Contexts | ||
|
||
|
||
class ContextAdapter(fl.Chain, Adapter[fl.Chain]): | ||
def __init__(self, target: fl.Chain): | ||
with self.setup_adapter(target): | ||
super().__init__( | ||
fl.Lambda(lambda: 42), | ||
fl.SetContext("foo", "bar"), | ||
) | ||
|
||
|
||
class ContextChain(fl.Chain): | ||
def init_context(self) -> Contexts: | ||
return {"foo": {"bar": None}} | ||
|
||
|
||
def test_adapter_can_access_parent_context(): | ||
chain = ContextChain(fl.Chain(), fl.UseContext("foo", "bar")) | ||
adaptee = chain.layer("Chain", fl.Chain) | ||
ContextAdapter(adaptee).inject(chain) | ||
|
||
assert chain() == 42 |