Skip to content

Commit b8c3076

Browse files
SNOW-1762538 add application detection for Jupyter notebook and Snowbook
1 parent 77c8990 commit b8c3076

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/snowflake/connector/connection.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,3 +2294,5 @@ def _detect_application() -> None | str:
22942294
for jpmod in ("ipykernel", "jupyter_core", "jupyter_client")
22952295
):
22962296
return "jupyter_notebook"
2297+
if "snowbooks" in sys.modules:
2298+
return "snowflake_notebook"

test/unit/test_connection.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,23 @@ def test_partner_env_var(mock_post_requests):
194194

195195

196196
@pytest.mark.skipolddriver
197-
def test_imported_module(mock_post_requests):
198-
with patch.dict(sys.modules, {"streamlit": "foo"}):
199-
assert fake_connector().application == "streamlit"
197+
@pytest.mark.parametrize(
198+
"sys_modules,application",
199+
[
200+
({"streamlit": None}, "streamlit"),
201+
(
202+
{"ipykernel": None, "jupyter_core": None, "jupyter_client": None},
203+
"jupyter_notebook",
204+
),
205+
({"snowbooks": None}, "snowflake_notebook"),
206+
],
207+
)
208+
def test_imported_module(mock_post_requests, sys_modules, application):
209+
with patch.dict(sys.modules, sys_modules):
210+
assert fake_connector().application == application
200211

201212
assert (
202-
mock_post_requests["data"]["CLIENT_ENVIRONMENT"]["APPLICATION"] == "streamlit"
213+
mock_post_requests["data"]["CLIENT_ENVIRONMENT"]["APPLICATION"] == application
203214
)
204215

205216

0 commit comments

Comments
 (0)