-
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
Showing
4 changed files
with
58 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,35 @@ | ||
import pytest | ||
|
||
from dbt.config.utils import exclusive_primary_alt_value_setting | ||
from dbt.config.utils import normalize_warn_error_options | ||
from dbt.exceptions import DbtExclusivePropertyUseError | ||
|
||
|
||
class TestExclusivePrimaryAltValueSetting: | ||
@pytest.fixture(scope="class") | ||
def primary_key(self) -> str: | ||
return "key_a" | ||
|
||
@pytest.fixture(scope="class") | ||
def alt_key(self) -> str: | ||
return "key_b" | ||
|
||
@pytest.fixture(scope="class") | ||
def value(self) -> str: | ||
return "I LIKE CATS" | ||
|
||
def test_primary_set(self, primary_key: str, alt_key: str, value: str): | ||
test_dict = {primary_key: value} | ||
exclusive_primary_alt_value_setting(test_dict, primary_key, alt_key) | ||
assert test_dict.get(primary_key) == value | ||
assert test_dict.get(alt_key) is None | ||
|
||
def test_alt_set(self, primary_key: str, alt_key: str, value: str): | ||
test_dict = {alt_key: value} | ||
exclusive_primary_alt_value_setting(test_dict, primary_key, alt_key) | ||
assert test_dict.get(primary_key) == value | ||
|
||
def test_primary_and_alt_set(self, primary_key: str, alt_key: str, value: str): | ||
test_dict = {primary_key: value, alt_key: value} | ||
class TestNormalizeWarnErrorOptions: | ||
def test_primary_set(self): | ||
test_dict = { | ||
"error": ["SomeWarning"], | ||
} | ||
normalize_warn_error_options(test_dict) | ||
assert len(test_dict) == 1 | ||
assert test_dict["include"] == ["SomeWarning"] | ||
|
||
def test_convert(self): | ||
test_dict = {"warn": None, "silence": None, "include": ["SomeWarning"]} | ||
normalize_warn_error_options(test_dict) | ||
assert test_dict["exclude"] == [] | ||
assert test_dict["include"] == ["SomeWarning"] | ||
assert test_dict["silence"] == [] | ||
|
||
def test_both_keys_set(self): | ||
test_dict = { | ||
"warn": ["SomeWarning"], | ||
"exclude": ["SomeWarning"], | ||
} | ||
with pytest.raises(DbtExclusivePropertyUseError): | ||
exclusive_primary_alt_value_setting(test_dict, primary_key, alt_key) | ||
normalize_warn_error_options(test_dict) | ||
|
||
def test_neither_primary_nor_alt_set(self, primary_key: str, alt_key: str): | ||
def test_empty_dict(self): | ||
test_dict = {} | ||
exclusive_primary_alt_value_setting(test_dict, primary_key, alt_key) | ||
assert test_dict.get(primary_key) is None | ||
assert test_dict.get(alt_key) is None | ||
normalize_warn_error_options(test_dict) | ||
assert test_dict.get("include") is None | ||
assert test_dict.get("exclude") is None |