Skip to content

Commit

Permalink
Added integration test for execute streamlit command
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-vmaleki committed Sep 20, 2024
1 parent ce6a9a4 commit 657e3fc
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions tests_integration/test_streamlit.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
rows_from_snowflake_session,
)
from tests_integration.testing_utils import assert_that_result_is_successful
from snowflake.cli._plugins.streamlit.manager import StreamlitManager


@pytest.mark.integration
Expand Down Expand Up @@ -367,3 +368,58 @@ def _new_streamlit_role(snowflake_session, test_database):
row_from_snowflake_session(result),
{"status": f"{role_name.upper()} successfully dropped."},
)


def _execute_streamlit(runner, streamlit_name):
result = runner.invoke_with_connection_json(
["streamlit", "execute", streamlit_name, "--format", "json"]
)
assert result.exit_code == 0
assert result.json == {"message": f"Streamlit {streamlit_name} executed."}


def _execute_streamlit_failure(runner, streamlit_name):
result = runner.invoke_with_connection(["streamlit", "execute", streamlit_name])
assert result.exit_code == 1
assert f"NameError: name {streamlit_name} is not defined" in result.output


@pytest.mark.integration
def test_execute_streamlit(runner, snowflake_session, test_database):
stage_name = "streamlit_stage"
snowflake_session.execute_string(f"create stage {stage_name};")

# Create a Streamlit app and upload it to the stage
streamlit_app = Path("test_streamlit_app.py")

_create_streamlit(
streamlit=streamlit_app,
runner=runner,
snowflake_session=snowflake_session,
stage_name=stage_name,
)

# Test successful and failure executions
_execute_streamlit(runner, streamlit_app.stem)
_execute_streamlit_failure(runner, "nonexistent_app")


def _create_streamlit(local_streamlit_file, runner, snowflake_session, stage_name):
streamlit_name = local_streamlit_file.stem
stage_path = f"@{stage_name}/{local_streamlit_file.name}"
snowflake_session.execute_string(
f"put file://{local_streamlit_file.absolute()} @{stage_name} AUTO_COMPRESS=FALSE;"
)
command = (
"streamlit",
"create",
streamlit_name,
"--streamlit-file",
stage_path,
"--format",
"json",
)
result = runner.invoke_with_connection_json(command)
assert result.exit_code == 0
message: str = result.json.get("message", "")
assert message.endswith(streamlit_name.upper())

0 comments on commit 657e3fc

Please sign in to comment.