From 9c26751a8cbc7b1741a9ebe543d44d62635fe89b Mon Sep 17 00:00:00 2001 From: Adam Stus Date: Wed, 4 Dec 2024 18:30:52 +0100 Subject: [PATCH] Fixed precommit errors and tests --- .pre-commit-config.yaml | 4 +++ tests/nativeapp/test_artifacts.py | 2 +- tests/snowpark/test_function.py | 2 +- tests/streamlit/test_artifacts.py | 4 +-- tests/streamlit/test_commands.py | 29 ------------------- .../streamlit_templated_v1/streamlit_app.py | 5 ++++ tests/testing_utils/fixtures.py | 3 ++ tests_integration/conftest.py | 3 ++ 8 files changed, 19 insertions(+), 33 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f2fa52cfec..73d97beea8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,6 +25,10 @@ repos: hooks: - id: mypy additional_dependencies: [types-pkg-resources==0.1.3, types-all==1.0.0] + exclude: > + (?x) + ^tests/test_data/projects/.*| + ^tests_integration/test_data/projects/.* - repo: https://github.com/codespell-project/codespell rev: v2.2.4 hooks: diff --git a/tests/nativeapp/test_artifacts.py b/tests/nativeapp/test_artifacts.py index b098e987ce..6cec78e676 100644 --- a/tests/nativeapp/test_artifacts.py +++ b/tests/nativeapp/test_artifacts.py @@ -19,6 +19,7 @@ import pytest from click import ClickException from snowflake.cli._plugins.nativeapp.artifacts import ( + VersionInfo, build_bundle, find_events_definitions_in_manifest_file, find_version_info_in_manifest_file, @@ -29,7 +30,6 @@ NotInDeployRootError, SourceNotFoundError, TooManyFilesError, - VersionInfo, ) from snowflake.cli.api.project.definition import load_project from snowflake.cli.api.project.schemas.entities.common import PathMapping diff --git a/tests/snowpark/test_function.py b/tests/snowpark/test_function.py index b071277602..1df689c4b5 100644 --- a/tests/snowpark/test_function.py +++ b/tests/snowpark/test_function.py @@ -18,12 +18,12 @@ from unittest import mock import pytest + from snowflake.cli._plugins.snowpark.package_utils import ( DownloadUnavailablePackagesResult, ) from snowflake.cli.api.errno import DOES_NOT_EXIST_OR_NOT_AUTHORIZED from snowflake.connector import ProgrammingError - from tests_common import IS_WINDOWS if IS_WINDOWS: diff --git a/tests/streamlit/test_artifacts.py b/tests/streamlit/test_artifacts.py index 4b75406d1c..d63f3033df 100644 --- a/tests/streamlit/test_artifacts.py +++ b/tests/streamlit/test_artifacts.py @@ -112,7 +112,7 @@ @mock.patch("snowflake.cli._plugins.snowpark.commands.StageManager.put") @mock.patch( "snowflake.cli._plugins.connection.util.get_ui_parameters", - return_value={UIParameter.NA_ENABLE_REGIONLESS_REDIRECT: "false"}, + return_value={UIParameter.NA_ENABLE_REGIONLESS_REDIRECT: False}, ) def test_deploy_with_artifacts( mock_param, @@ -252,7 +252,7 @@ def test_deploy_with_artifacts( @mock.patch("snowflake.cli._plugins.snowpark.commands.StageManager.put") @mock.patch( "snowflake.cli._plugins.connection.util.get_ui_parameters", - return_value={UIParameter.NA_ENABLE_REGIONLESS_REDIRECT: "false"}, + return_value={UIParameter.NA_ENABLE_REGIONLESS_REDIRECT: False}, ) def test_deploy_with_artifacts_from_other_directory( mock_param, diff --git a/tests/streamlit/test_commands.py b/tests/streamlit/test_commands.py index cd39056335..9a859ad030 100644 --- a/tests/streamlit/test_commands.py +++ b/tests/streamlit/test_commands.py @@ -920,35 +920,6 @@ def test_deploy_streamlit_main_and_pages_files_experimental_replace( ] -@pytest.mark.parametrize( - "project_name,opts", - [ - ("example_streamlit", {"streamlit": {"pages_dir": "foo.bar"}}), - ("example_streamlit", {"streamlit": {"env_file": "foo.bar"}}), - ( - "example_streamlit_v2", - {"entities": {"test_streamlit": {"pages_dir": "foo.bar"}}}, - ), - ( - "example_streamlit_v2", - {"entities": {"test_streamlit": {"artifacts": ["foo.bar"]}}}, - ), - ], -) -@mock.patch("snowflake.connector.connect") -def test_deploy_streamlit_nonexisting_file( - mock_connector, runner, mock_ctx, snapshot, project_directory, opts, project_name -): - ctx = mock_ctx() - mock_connector.return_value = ctx - - with project_directory(project_name, merge_project_definition=opts): - result = runner.invoke(["streamlit", "deploy"]) - - assert result.exit_code == 1 - assert result.output == snapshot - - @mock.patch("snowflake.connector.connect") def test_share_streamlit(mock_connector, runner, mock_ctx): ctx = mock_ctx() diff --git a/tests/test_data/projects/streamlit_templated_v1/streamlit_app.py b/tests/test_data/projects/streamlit_templated_v1/streamlit_app.py index e69de29bb2..1a8695c60d 100644 --- a/tests/test_data/projects/streamlit_templated_v1/streamlit_app.py +++ b/tests/test_data/projects/streamlit_templated_v1/streamlit_app.py @@ -0,0 +1,5 @@ +from common.hello import say_hello + +import streamlit as st + +st.title(f"Example streamlit app. {say_hello()}") diff --git a/tests/testing_utils/fixtures.py b/tests/testing_utils/fixtures.py index 457acec1c6..192776fcc9 100644 --- a/tests/testing_utils/fixtures.py +++ b/tests/testing_utils/fixtures.py @@ -473,5 +473,8 @@ def enable_snowpark_glob_support_feature_flag(): with mock.patch( f"snowflake.cli.api.feature_flags.FeatureFlag.ENABLE_SNOWPARK_GLOB_SUPPORT.is_enabled", return_value=True, + ), mock.patch( + f"snowflake.cli.api.feature_flags.FeatureFlag.ENABLE_SNOWPARK_GLOB_SUPPORT.is_disabled", + return_value=False, ): yield diff --git a/tests_integration/conftest.py b/tests_integration/conftest.py index 6be62f1ce5..1ac9bda801 100644 --- a/tests_integration/conftest.py +++ b/tests_integration/conftest.py @@ -266,5 +266,8 @@ def enable_snowpark_glob_support_feature_flag(): with mock.patch( f"snowflake.cli.api.feature_flags.FeatureFlag.ENABLE_SNOWPARK_GLOB_SUPPORT.is_enabled", return_value=True, + ), mock.patch( + f"snowflake.cli.api.feature_flags.FeatureFlag.ENABLE_SNOWPARK_GLOB_SUPPORT.is_disabled", + return_value=False, ): yield