Skip to content

Commit

Permalink
Add unit test for newly added Mergeable class
Browse files Browse the repository at this point in the history
  • Loading branch information
QMalcolm committed Feb 1, 2024
1 parent 4f27dd4 commit 682b62c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/unit/test_contracts_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import unittest

from dataclasses import dataclass
from dbt_common.contracts.util import Mergeable
from typing import List, Optional


@dataclass
class ExampleMergableClass(Mergeable):
attr_a: str
attr_b: Optional[int]
attr_c: Optional[List[str]]


class TestMergableClass(unittest.TestCase):
def test_mergeability(self):
mergeable1 = ExampleMergableClass(
attr_a="loses", attr_b=None, attr_c=["I'll", "still", "exist"]
)
mergeable2 = ExampleMergableClass(attr_a="Wins", attr_b=1, attr_c=None)
merge_result: ExampleMergableClass = mergeable1.merged(mergeable2)
assert (
merge_result.attr_a == mergeable2.attr_a
) # mergeable2's attr_a is the "last" non None value
assert merge_result.attr_b == mergeable2.attr_b # mergeable1's attrb_b value was None
assert merge_result.attr_c == mergeable1.attr_c # mergeable2's attr_c value was None

0 comments on commit 682b62c

Please sign in to comment.