Skip to content

Commit

Permalink
Add unit tests for exclusive_primary_alt_value_setting method
Browse files Browse the repository at this point in the history
I debated about parametrizing these tests, and it can be done. However,
I found that the resulting code ended up being about the same number of
lines and slightly less readable (in my opinion). Given the simplicity of
these tests, I think not parametrizing them is okay.
  • Loading branch information
QMalcolm committed Apr 29, 2024
1 parent 0e87a17 commit 49b66e1
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/unit/config/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import pytest

from dbt.config.utils import exclusive_primary_alt_value_setting
from dbt.exceptions import DbtWarnErrorOptionsError


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
assert test_dict.get(alt_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}
with pytest.raises(DbtWarnErrorOptionsError):
exclusive_primary_alt_value_setting(test_dict, primary_key, alt_key)

def test_neither_primary_nor_alt_set(self, primary_key: str, alt_key: str):
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

0 comments on commit 49b66e1

Please sign in to comment.