-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move to test concrete class over abstract class (#10243)
- Loading branch information
1 parent
8c850b5
commit a677abd
Showing
4 changed files
with
72 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file was deleted.
Oops, something went wrong.