Skip to content

Commit

Permalink
Fix + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jsikorski committed Jan 31, 2024
1 parent d02912d commit 4537560
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/snowflake/cli/api/project/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def merge_left(target: Union[Dict, YAML], source: Union[Dict, YAML]) -> None:
"""
for k, v in source.items():
if k in target and (
isinstance(v, dict) or (isinstance(v, YAML) and not v.is_scalar())
isinstance(v, dict) or (isinstance(v, YAML) and v.is_mapping())
):
# assumption: all inputs have been validated.
assert isinstance(target[k], dict) or isinstance(target[k], YAML)
Expand Down
35 changes: 35 additions & 0 deletions tests/streamlit/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from collections import OrderedDict
from pathlib import Path

import pytest
from strictyaml import YAML, as_document

from src.snowflake.cli.api.project.definition import load_project_definition, merge_left

TEST_DATA = Path(__file__).parent.parent / "test_data" / "streamlit"
FILE_WITH_LONG_LIST = TEST_DATA / "with_list_in_source_file.yml"
ANOTHER_FILE_WITH_LONG_LIST = TEST_DATA / "another_file_with_list.yml"
FILE_WITH_SINGLE_ITEM_LIST = TEST_DATA / "with_single_item.yml"
ANOTHER_FILE_WITH_SINGLE_ITEM = TEST_DATA / "another_file_with_single_item.yml"


@pytest.mark.parametrize(
"test_files,expected",
[
(
[FILE_WITH_LONG_LIST, FILE_WITH_SINGLE_ITEM_LIST],
"a_tree_cut_down_with_a_herring",
),
([FILE_WITH_SINGLE_ITEM_LIST, FILE_WITH_LONG_LIST], "a_shrubbery.py"),
(
[FILE_WITH_SINGLE_ITEM_LIST, ANOTHER_FILE_WITH_SINGLE_ITEM],
"another_shrubbery_but_a_bit_higher",
),
([FILE_WITH_LONG_LIST, ANOTHER_FILE_WITH_LONG_LIST], "boing.py"),
],
)
def test_load_project_definition(test_files, expected):

result = load_project_definition(test_files)

assert expected in result["streamlit"]["additional_source_files"]
13 changes: 13 additions & 0 deletions tests/test_data/streamlit/another_file_with_list.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
definition_version: 1
streamlit:
name: streamlit_app
stage: my_streamlit_stage
query_warehouse: my_streamlit_warehouse
main_file: streamlit_app.py
env_file: environment.yml
pages_dir: pages/
additional_source_files:
- ekke.py
- ptang.py
- zoo.py
- boing.py
6 changes: 6 additions & 0 deletions tests/test_data/streamlit/another_file_with_single_item.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
definition_version: 1
streamlit:
name: knights_who_say_ni
query_warehouse: my_streamlit_warehouse
additional_source_files:
- another_shrubbery_but_a_bit_higher
12 changes: 12 additions & 0 deletions tests/test_data/streamlit/with_list_in_source_file.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
definition_version: 1
streamlit:
name: streamlit_app
stage: my_streamlit_stage
query_warehouse: my_streamlit_warehouse
main_file: streamlit_app.py
env_file: environment.yml
pages_dir: pages/
additional_source_files:
- a_shrubbery.py
- looking_nice.py
- not_too_expensive.py
6 changes: 6 additions & 0 deletions tests/test_data/streamlit/with_single_item.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
definition_version: 1
streamlit:
name: knights_who_say_ni
query_warehouse: my_streamlit_warehouse
additional_source_files:
- a_tree_cut_down_with_a_herring

0 comments on commit 4537560

Please sign in to comment.