Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KarolGongola committed Dec 18, 2024
1 parent ad5c5d8 commit 381ef80
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
7 changes: 3 additions & 4 deletions cosmos/dbt/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from dataclasses import dataclass, field
from functools import cached_property
from pathlib import Path
from subprocess import PIPE, Popen
from subprocess import PIPE, STDOUT, Popen
from typing import TYPE_CHECKING, Any, Dict, Optional

from airflow.models import Variable
Expand Down Expand Up @@ -166,7 +166,7 @@ def run_command(command: list[str], tmp_dir: Path, env_vars: dict[str, str]) ->
process = Popen(
command,
stdout=PIPE,
stderr=PIPE,
stderr=STDOUT,
cwd=tmp_dir,
universal_newlines=True,
env=env_vars,
Expand All @@ -180,8 +180,7 @@ def run_command(command: list[str], tmp_dir: Path, env_vars: dict[str, str]) ->
)

if returncode or "Error" in stdout.replace("WarnErrorOptions", ""):
details = f"stderr: {stderr}\nstdout: {stdout}"
raise CosmosLoadDbtException(f"Unable to run {command} due to the error:\n{details}")
raise CosmosLoadDbtException(f"Unable to run {command} due to the error:\n{stdout}")

return stdout

Expand Down
6 changes: 3 additions & 3 deletions tests/dbt/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ def test_load_via_dbt_ls_with_non_zero_returncode(mock_popen, postgres_profile_c
execution_config=execution_config,
profile_config=postgres_profile_config,
)
expected = r"Unable to run \['.+dbt', 'deps', .*\] due to the error:\nstderr: Some stderr message\nstdout: "
expected = r"Unable to run \['.+dbt', 'deps', .*\] due to the error:\nSome stderr message"
with pytest.raises(CosmosLoadDbtException, match=expected):
dbt_graph.load_via_dbt_ls()

Expand All @@ -859,7 +859,7 @@ def test_load_via_dbt_ls_with_runtime_error_in_stdout(mock_popen_communicate, po
execution_config=execution_config,
profile_config=postgres_profile_config,
)
expected = r"Unable to run \['.+dbt', 'deps', .*\] due to the error:\nstderr: \nstdout: Some Runtime Error"
expected = r"Unable to run \['.+dbt', 'deps', .*\] due to the error:\nSome Runtime Error"
with pytest.raises(CosmosLoadDbtException, match=expected):
dbt_graph.load_via_dbt_ls()

Expand Down Expand Up @@ -1131,7 +1131,7 @@ def test_run_command_none_argument(mock_popen, caplog):
with pytest.raises(CosmosLoadDbtException) as exc_info:
run_command(fake_command, fake_dir, env_vars)

expected = "Unable to run ['invalid-cmd', '<None>'] due to the error:\nstderr: None\nstdout: Invalid None argument"
expected = "Unable to run ['invalid-cmd', '<None>'] due to the error:\nInvalid None argument"
assert str(exc_info.value) == expected


Expand Down

0 comments on commit 381ef80

Please sign in to comment.