Skip to content

Commit

Permalink
Split error handling tests for snow init (#1305)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-pczajka authored Jul 11, 2024
1 parent 2ae3107 commit a3aad2b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tests/__snapshots__/test_init.ambr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# serializer version: 1
# name: test_error_handling
# name: test_error_too_low_cli_version
'''
+- Error ----------------------------------------------------------------------+
| Snowflake CLI version (915.6.0) is too low - minimum version required by |
Expand Down
18 changes: 14 additions & 4 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ def copy_project_definition(project_name: str):
yield copy_project_definition


def test_error_handling(
runner, test_projects_path, temp_dir, project_definition_copy, monkeypatch, snapshot
):
def test_error_missing_template_yml(runner, test_projects_path, temp_dir):
# no template.yml
project_name = "example_streamlit_no_defaults"
result = runner.invoke(
Expand All @@ -68,7 +66,9 @@ def test_error_handling(
assert "Template does not have template.yml file." in result.output
assert not Path(project_name).exists()

# project already exists

def test_error_project_already_exists(runner, test_projects_path, temp_dir):
# destination directory already exists
project_name = "project_templating"
result = runner.invoke(
[
Expand All @@ -82,6 +82,8 @@ def test_error_handling(
assert "The directory" in result.output
assert "exists." in result.output


def test_error_template_does_not_exist(runner, test_projects_path, temp_dir):
# template does not exist
project_name = "this_project_does_not_exist"
result = runner.invoke(
Expand All @@ -98,6 +100,8 @@ def test_error_handling(
assert f"Template '{project_name}' cannot be found under" in result.output
assert not Path(project_name).exists()


def test_error_source_does_not_exist(runner, test_projects_path, temp_dir):
# template source does not exist
with pytest.raises(FileNotFoundError, match=".*No such file or directory.*"):
project_name = "this_project_does_not_exist"
Expand All @@ -111,6 +115,10 @@ def test_error_handling(
)
assert not Path(project_name).exists()


def test_error_too_low_cli_version(
runner, temp_dir, project_definition_copy, monkeypatch, snapshot
):
# Too low CLI version
project_name = "example_streamlit_no_defaults"
with project_definition_copy(project_name) as template_root:
Expand All @@ -127,6 +135,8 @@ def test_error_handling(
assert result.output == snapshot
assert not Path(project_name).exists()


def test_error_undefined_variable(runner, temp_dir, project_definition_copy):
# variable not defined in template.yml
project_name = "project_templating"
with project_definition_copy(project_name) as template_root:
Expand Down

0 comments on commit a3aad2b

Please sign in to comment.