-
Notifications
You must be signed in to change notification settings - Fork 83
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
Showing
4 changed files
with
66 additions
and
45 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,39 @@ | ||
from __future__ import annotations | ||
|
||
import textwrap | ||
from typing import Awaitable, Callable, cast | ||
|
||
from .._namespaces import Root | ||
from ..session import Inputs, Outputs, Session | ||
|
||
all = ("MockSession",) | ||
|
||
|
||
# A very bare-bones mock session class that is used only in shiny.express's UI rendering | ||
# phase. | ||
class MockSession: | ||
def __init__(self): | ||
self.ns = Root | ||
self.input = Inputs({}) | ||
self.output = Outputs(cast(Session, self), self.ns, {}, {}) | ||
|
||
# This is needed so that Outputs don't throw an error. | ||
def _is_hidden(self, name: str) -> bool: | ||
return False | ||
|
||
def on_ended( | ||
self, | ||
fn: Callable[[], None] | Callable[[], Awaitable[None]], | ||
) -> Callable[[], None]: | ||
return lambda: None | ||
|
||
def __getattr__(self, name: str): | ||
raise AttributeError( | ||
textwrap.dedent( | ||
f""" | ||
The session attribute `{name}` is not yet available for use. Since this code | ||
will run again when the session is initialized, you can use `if session:` to | ||
only run this code when the session is established. | ||
""" | ||
) | ||
) |
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