forked from marimo-team/marimo
-
Notifications
You must be signed in to change notification settings - Fork 0
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
695f8a4
commit de1b46e
Showing
2 changed files
with
73 additions
and
5 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,58 @@ | ||
import sys | ||
import types | ||
|
||
import pytest | ||
|
||
from marimo._dependencies.dependencies import DependencyManager | ||
from marimo._runtime.runtime import Kernel | ||
from tests.conftest import ExecReqProvider | ||
|
||
registering_fn_module = types.ModuleType("registering_fn_module") | ||
exec( | ||
""" | ||
import marimo as mo | ||
import pandas as pd | ||
def registering_fn() -> None: | ||
print('hi') | ||
df = pd.DataFrame({'a': [1], 'b': [2]}) | ||
name_fn = lambda x: x | ||
mo.editor.register_datasource(df, name_fn('test_var_name')) | ||
""", | ||
registering_fn_module.__dict__, | ||
) | ||
|
||
# Add this module to `sys.modules` | ||
sys.modules["registering_fn_module"] = registering_fn_module | ||
|
||
|
||
class TestCellRun: | ||
@staticmethod | ||
@pytest.mark.skipif( | ||
condition=not DependencyManager.pandas.has(), | ||
reason="requires matplotlib", | ||
) | ||
async def test_register_datasource( | ||
execution_kernel: Kernel, exec_req: ExecReqProvider | ||
) -> None: | ||
k = execution_kernel | ||
await k.run( | ||
[ | ||
exec_req.get( | ||
""" | ||
import registering_fn_module | ||
registering_fn_module.registering_fn() | ||
""" | ||
) | ||
] | ||
) | ||
|
||
assert k.globals["registering_fn_module"] | ||
assert ( | ||
"test_var_name" in k.globals | ||
), "test_var_name not found in globals." | ||
import pandas as pd | ||
|
||
assert isinstance( | ||
k.globals["test_var_name"], pd.DataFrame | ||
), "test_var_name is not a pandas DataFrame." |