-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fdf01c9
commit 25c4f55
Showing
6 changed files
with
177 additions
and
15 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
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
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,49 @@ | ||
from argparse import Namespace | ||
import pytest | ||
|
||
import dbt.flags as flags | ||
from dbt.events.functions import warn_or_error | ||
from dbt.events.types import NoNodesForSelectionCriteria | ||
from dbt.exceptions import EventCompilationException | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"warn_error_options,expect_compilation_exception", | ||
[ | ||
('{"include": "all"}', True), | ||
('{"include": [NoNodesForSelectionCriteria]}', True), | ||
('{"include": []}', False), | ||
('{}', False), | ||
('{"include": [MainTrackingUserState]}', False), | ||
('{"include": "all", "exclude": [NoNodesForSelectionCriteria]}', False), | ||
], | ||
) | ||
def test_warn_or_error_warn_error_options(warn_error_options, expect_compilation_exception): | ||
args = Namespace( | ||
warn_error_options=warn_error_options | ||
) | ||
flags.set_from_args(args, {}) | ||
if expect_compilation_exception: | ||
with pytest.raises(EventCompilationException): | ||
warn_or_error(NoNodesForSelectionCriteria()) | ||
else: | ||
warn_or_error(NoNodesForSelectionCriteria()) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"warn_error,expect_compilation_exception", | ||
[ | ||
(True, True), | ||
(False, False), | ||
], | ||
) | ||
def test_warn_or_error_warn_error(warn_error, expect_compilation_exception): | ||
args = Namespace( | ||
warn_error=warn_error | ||
) | ||
flags.set_from_args(args, {}) | ||
if expect_compilation_exception: | ||
with pytest.raises(EventCompilationException): | ||
warn_or_error(NoNodesForSelectionCriteria()) | ||
else: | ||
warn_or_error(NoNodesForSelectionCriteria()) |
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,46 @@ | ||
|
||
import pytest | ||
|
||
from dbt.helper_types import IncludeExclude, WarnErrorOptions | ||
from dbt.exceptions import ValidationException | ||
|
||
|
||
class TestIncludeExclude: | ||
def test_init_invalid(self): | ||
with pytest.raises(ValidationException): | ||
IncludeExclude(include="invalid") | ||
|
||
with pytest.raises(ValidationException): | ||
IncludeExclude(include=["ItemA"], exclude=["ItemB"]) | ||
|
||
@pytest.mark.parametrize( | ||
"include,exclude,expected_includes", | ||
[ | ||
("all", [], True), | ||
("*", [], True), | ||
("*", ["ItemA"], False), | ||
(["ItemA"], [], True), | ||
(["ItemA", "ItemB"], [], True), | ||
] | ||
) | ||
def test_includes(self, include, exclude, expected_includes): | ||
include_exclude = IncludeExclude(include=include, exclude=exclude) | ||
|
||
assert include_exclude.includes("ItemA") == expected_includes | ||
|
||
|
||
class TestWarnErrorOptions: | ||
def test_init(self): | ||
with pytest.raises(ValidationException): | ||
WarnErrorOptions(include=["InvalidError"]) | ||
|
||
with pytest.raises(ValidationException): | ||
WarnErrorOptions(include="*", exclude=["InvalidError"]) | ||
|
||
warn_error_options = WarnErrorOptions(include=["NoNodesForSelectionCriteria"]) | ||
assert warn_error_options.include == ["NoNodesForSelectionCriteria"] | ||
assert warn_error_options.exclude == [] | ||
|
||
warn_error_options = WarnErrorOptions(include="*", exclude=["NoNodesForSelectionCriteria"]) | ||
assert warn_error_options.include == "*" | ||
assert warn_error_options.exclude == ["NoNodesForSelectionCriteria"] |