Skip to content

Commit

Permalink
Mock + rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
LennartKloppenburg committed Nov 16, 2023
1 parent 723b7ce commit 9972e03
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions cosmos/operators/virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def _get_or_create_venv_py_interpreter(self) -> str:
)

self.log.info(f"Checking if {str(self.__lock_file)} exists")
while not self.__is_lock_available():
while not self._is_lock_available():
self.log.info("Waiting for lock to release")
time.sleep(1)

Expand Down Expand Up @@ -154,7 +154,7 @@ def _pid(self) -> int:
return os.getpid()

@depends_on_virtualenv_dir
def __is_lock_available(self) -> bool:
def _is_lock_available(self) -> bool:
if self.__lock_file.is_file():
with open(self.__lock_file, "r") as lf:
pid = int(lf.read())
Expand Down
3 changes: 3 additions & 0 deletions tests/operators/test_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,18 @@ def test_run_command(
@patch("cosmos.operators.virtualenv.DbtLocalBaseOperator.store_compiled_sql")
@patch("cosmos.operators.virtualenv.DbtLocalBaseOperator.exception_handling")
@patch("cosmos.operators.virtualenv.DbtLocalBaseOperator.subprocess_hook")
@patch("cosmos.operators.virtualenv.DbtVirtualenvBaseOperator._is_lock_available")
@patch("airflow.hooks.base.BaseHook.get_connection")
def test_supply_virtualenv_dir_flag(
mock_get_connection,
mock_lock_available,
mock_subprocess_hook,
mock_exception_handling,
mock_store_compiled_sql,
mock_calculate_openlineage_events_completes,
mock_execute,
):
mock_lock_available.return_value = True
mock_get_connection.return_value = Connection(
conn_id="fake_conn",
conn_type="postgres",
Expand Down
6 changes: 3 additions & 3 deletions tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,14 @@ def test_converter_creates_dag_with_project_path_str(mock_load_dbt_graph, execut
# (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`
and still pass a defined `virtualenv_dir`
"""
project_config = ProjectConfig(dbt_project_path=SAMPLE_DBT_PROJECT)
project_config = ProjectConfig(dbt_project_path=SAMPLE_DBT_PROJECT.as_posix())
execution_config = ExecutionConfig(execution_mode=execution_mode, virtualenv_dir=virtualenv_dir)
render_config = RenderConfig(emit_datasets=True)
profile_config = ProfileConfig(
Expand All @@ -137,8 +139,6 @@ def test_converter_raises_warning(mock_load_dbt_graph, execution_mode, virtualen
operator_args=operator_args,
)

assert converter

assert "`ExecutionConfig.virtualenv_dir` is only supported when \
ExecutionConfig.execution_mode is set to ExecutionMode.VIRTUALENV." in caplog.text

Expand Down

0 comments on commit 9972e03

Please sign in to comment.