Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
nevdelap committed Jun 5, 2024
2 parents 55a6a63 + a677abd commit 28ac6d7
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 154 deletions.
4 changes: 2 additions & 2 deletions tests/functional/dependencies/test_dependency_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_deps_lock(self, clean_start):
- package: fivetran/fivetran_utils
version: 0.4.7
- package: dbt-labs/dbt_utils
version: 1.1.1
version: 1.2.0
sha1_hash: 71304bca2138cf8004070b3573a1e17183c0c1a8
"""
)
Expand All @@ -56,7 +56,7 @@ def test_deps_default(self, clean_start):
- package: fivetran/fivetran_utils
version: 0.4.7
- package: dbt-labs/dbt_utils
version: 1.1.1
version: 1.2.0
sha1_hash: 71304bca2138cf8004070b3573a1e17183c0c1a8
"""
)
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Unit test README

## test_contracts_graph_parsed.py

### The Why
We need to ensure that we can go from objects to dictionaries and back without any
Expand All @@ -16,3 +15,7 @@ versions of the object we're interested in testing, and run the different genera
of the object through the test. This gives us confidence that for any allowable configuration
of an object, state is not changed when moving back and forth betweeen the python object
version and the seralized version.

### The What

- We test concrete classes in the codebase and do not test abstract classes as they are implementation details. [reference](https://enterprisecraftsmanship.com/posts/how-to-unit-test-an-abstract-class/)
16 changes: 16 additions & 0 deletions tests/unit/task/test_clone.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from unittest.mock import MagicMock, patch

from dbt.flags import get_flags
from dbt.task.clone import CloneTask


def test_clone_task_not_preserve_edges():
mock_node_selector = MagicMock()
mock_spec = MagicMock()
with patch.object(
CloneTask, "get_node_selector", return_value=mock_node_selector
), patch.object(CloneTask, "get_selection_spec", return_value=mock_spec):
task = CloneTask(get_flags(), None, None)
task.get_graph_queue()
# when we get the graph queue, preserve_edges is False
mock_node_selector.get_graph_queue.assert_called_with(mock_spec, False)
52 changes: 52 additions & 0 deletions tests/unit/task/test_run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from argparse import Namespace
from unittest.mock import MagicMock, patch

import pytest

from dbt.config.runtime import RuntimeConfig
from dbt.flags import get_flags, set_from_args
from dbt.task.run import RunTask
from dbt.tests.util import safe_set_invocation_context


@pytest.mark.parametrize(
"exception_to_raise, expected_cancel_connections",
[
(SystemExit, True),
(KeyboardInterrupt, True),
(Exception, False),
],
)
def test_run_task_cancel_connections(
exception_to_raise, expected_cancel_connections, runtime_config: RuntimeConfig
):
safe_set_invocation_context()

def mock_run_queue(*args, **kwargs):
raise exception_to_raise("Test exception")

with patch.object(RunTask, "run_queue", mock_run_queue), patch.object(
RunTask, "_cancel_connections"
) as mock_cancel_connections:

set_from_args(Namespace(write_json=False), None)
task = RunTask(
get_flags(),
runtime_config,
None,
)
with pytest.raises(exception_to_raise):
task.execute_nodes()
assert mock_cancel_connections.called == expected_cancel_connections


def test_run_task_preserve_edges():
mock_node_selector = MagicMock()
mock_spec = MagicMock()
with patch.object(RunTask, "get_node_selector", return_value=mock_node_selector), patch.object(
RunTask, "get_selection_spec", return_value=mock_spec
):
task = RunTask(get_flags(), None, None)
task.get_graph_queue()
# when we get the graph queue, preserve_edges is True
mock_node_selector.get_graph_queue.assert_called_with(mock_spec, True)
151 changes: 0 additions & 151 deletions tests/unit/task/test_runnable.py

This file was deleted.

0 comments on commit 28ac6d7

Please sign in to comment.