-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: isolate get_test_context to reduce circular imports
- Loading branch information
1 parent
2c39c79
commit 913428a
Showing
27 changed files
with
111 additions
and
118 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,43 @@ | ||
from __future__ import annotations | ||
|
||
import typing | ||
from contextlib import contextmanager | ||
from contextvars import ContextVar | ||
|
||
if typing.TYPE_CHECKING: | ||
from collections.abc import Generator | ||
|
||
import algopy | ||
|
||
from algopy_testing import AlgopyTestContext | ||
|
||
_var: ContextVar[AlgopyTestContext] = ContextVar("_var") | ||
|
||
|
||
def get_test_context() -> AlgopyTestContext: | ||
try: | ||
result = _var.get() | ||
except LookupError: | ||
raise ValueError( | ||
"Test context is not initialized! Use `with algopy_testing_context()` to " | ||
"access the context manager." | ||
) from None | ||
return result | ||
|
||
|
||
@contextmanager | ||
def algopy_testing_context( | ||
*, | ||
default_creator: algopy.Account | None = None, | ||
) -> Generator[AlgopyTestContext, None, None]: | ||
from algopy_testing.context import AlgopyTestContext | ||
|
||
token = _var.set( | ||
AlgopyTestContext( | ||
default_creator=default_creator, | ||
) | ||
) | ||
try: | ||
yield _var.get() | ||
finally: | ||
_var.reset(token) |
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
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
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
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
Oops, something went wrong.