Skip to content

Commit

Permalink
Improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
tatiana committed Jan 27, 2025
1 parent 5b4360d commit d4e6dc2
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions tests/dbt/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@

from cosmos import settings
from cosmos.config import CosmosConfigException, ExecutionConfig, ProfileConfig, ProjectConfig, RenderConfig
from cosmos.constants import DBT_TARGET_DIR_NAME, DbtResourceType, ExecutionMode, SourceRenderingBehavior
from cosmos.constants import (
DBT_LOG_FILENAME,
DBT_TARGET_DIR_NAME,
DbtResourceType,
ExecutionMode,
SourceRenderingBehavior,
)
from cosmos.dbt.graph import (
CosmosLoadDbtException,
DbtGraph,
Expand Down Expand Up @@ -1165,14 +1171,21 @@ def test_run_command(mock_popen, stdout, returncode):
assert return_value == stdout


@pytest.mark.integration
@patch.dict(sys.modules, {"dbt.cli.main": None})
def test_run_command_success_with_log(tmp_dbt_project_dir):
project_dir = tmp_dbt_project_dir / DBT_PROJECT_NAME
(project_dir / DBT_LOG_FILENAME).touch()
response = run_command(command=["dbt", "deps"], env_vars=os.environ, tmp_dir=project_dir)
assert "Installing dbt-labs/dbt_utils" in response


@pytest.mark.integration
def test_run_command_with_dbt_runner_exception(tmp_dbt_project_dir):
with pytest.raises(CosmosLoadDbtException) as err_info:
run_command(command=["dbt", "ls"], env_vars=os.environ, tmp_dir=tmp_dbt_project_dir)
err_msg1 = "Unable to run ['dbt', 'ls']"
err_msg2 = "No dbt_project.yml"
assert err_msg1 in str(err_info.value)
assert err_msg2 in str(err_info.value)
run_command(command=["dbt", "ls"], env_vars=os.environ, tmp_dir=tmp_dbt_project_dir / DBT_PROJECT_NAME)
err_msg = "Unable to run dbt ls command due to missing dbt_packages"
assert err_msg in str(err_info.value)


@pytest.mark.integration
Expand Down

0 comments on commit d4e6dc2

Please sign in to comment.