From 89913c23c6a55ee650afd43f4d98d034f86d2d87 Mon Sep 17 00:00:00 2001 From: Lennart Kloppenburg Date: Mon, 23 Oct 2023 15:24:06 +0200 Subject: [PATCH] Assert warning --- tests/test_converter.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/test_converter.py b/tests/test_converter.py index 0d321730a..823eff460 100644 --- a/tests/test_converter.py +++ b/tests/test_converter.py @@ -1,4 +1,5 @@ from pathlib import Path +import logging from unittest.mock import patch import pytest @@ -12,6 +13,7 @@ SAMPLE_PROFILE_YML = Path(__file__).parent / "sample/profiles.yml" SAMPLE_DBT_PROJECT = Path(__file__).parent / "sample/" +LOGGER = logging.getLogger(__name__) @pytest.mark.parametrize("argument_key", ["tags", "paths"]) @@ -67,3 +69,36 @@ def test_converter_creates_dag_with_seed(mock_load_dbt_graph, execution_mode, op operator_args=operator_args, ) assert converter + +@pytest.mark.parametrize( + "execution_mode,virtualenv_dir,operator_args", + [ + (ExecutionMode.KUBERNETES, Path("/some/virtualenv/dir"), {}), + # (ExecutionMode.DOCKER, {"image": "sample-image"}), + ], +) +@patch("cosmos.converter.DbtGraph.filtered_nodes", nodes) +@patch("cosmos.converter.DbtGraph.load") +def test_converter_raises_warning(mock_load_dbt_graph, execution_mode, virtualenv_dir, operator_args, caplog): + """ + This test will raise a warning if we are trying to pass ExecutionMode != `VirtualEnv` andm still pass a defined `virtualenv_dir` + """ + project_config = ProjectConfig(dbt_project_path=SAMPLE_DBT_PROJECT) + execution_config = ExecutionConfig(execution_mode=execution_mode, virtualenv_dir=virtualenv_dir) + render_config = RenderConfig(emit_datasets=True) + profile_config = ProfileConfig( + profile_name="my_profile_name", + target_name="my_target_name", + profiles_yml_filepath=SAMPLE_PROFILE_YML, + ) + converter = DbtToAirflowConverter( + nodes=nodes, + project_config=project_config, + profile_config=profile_config, + execution_config=execution_config, + render_config=render_config, + operator_args=operator_args, + ) + + assert "`ExecutionConfig.virtualenv_dir` is only supported when \ + ExecutionConfig.execution_mode is set to ExecutionMode.VIRTUALENV." in caplog.text \ No newline at end of file