Skip to content

Commit

Permalink
nits
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenyuLInx committed Dec 19, 2024
1 parent 7a8be34 commit 0c96f71
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
6 changes: 2 additions & 4 deletions core/dbt/artifacts/resources/v1/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TimeSpine(dbtClassMixin):
custom_granularities: List[CustomGranularity] = field(default_factory=list)


class ModelFreshnessDependsOnOptions(enum.StrEnum):
class ModelFreshnessDependsOnOptions(enum.Enum):
all = "all"
any = "any"

Expand All @@ -50,9 +50,7 @@ class ModelBuildAfter(Time):

@dataclass
class ModelFreshness(dbtClassMixin):
build_after: ModelBuildAfter = field(
default_factory=lambda: ModelBuildAfter(period=TimePeriod.hour, count=0)
)
build_after: ModelBuildAfter = field(default_factory=ModelBuildAfter)


@dataclass
Expand Down
8 changes: 8 additions & 0 deletions tests/functional/artifacts/expected_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ def expected_seeded_manifest(project, model_database=None, quote_model=False):
"version": None,
"latest_version": None,
"time_spine": None,
"freshness": None,
},
"model.test.second_model": {
"compiled_path": os.path.join(compiled_model_path, "second_model.sql"),
Expand Down Expand Up @@ -471,6 +472,7 @@ def expected_seeded_manifest(project, model_database=None, quote_model=False):
"version": None,
"latest_version": None,
"time_spine": None,
"freshness": None,
},
"seed.test.seed": {
"build_path": None,
Expand Down Expand Up @@ -1003,6 +1005,7 @@ def expected_references_manifest(project):
"latest_version": None,
"constraints": [],
"time_spine": None,
"freshness": None,
},
"model.test.ephemeral_summary": {
"alias": "ephemeral_summary",
Expand Down Expand Up @@ -1075,6 +1078,7 @@ def expected_references_manifest(project):
"latest_version": None,
"constraints": [],
"time_spine": None,
"freshness": None,
},
"model.test.view_summary": {
"alias": "view_summary",
Expand Down Expand Up @@ -1143,6 +1147,7 @@ def expected_references_manifest(project):
"latest_version": None,
"constraints": [],
"time_spine": None,
"freshness": None,
},
"seed.test.seed": {
"alias": "seed",
Expand Down Expand Up @@ -1609,6 +1614,7 @@ def expected_versions_manifest(project):
"version": 1,
"latest_version": 2,
"time_spine": None,
"freshness": None,
},
"model.test.versioned_model.v2": {
"alias": "versioned_model_v2",
Expand Down Expand Up @@ -1680,6 +1686,7 @@ def expected_versions_manifest(project):
"version": 2,
"latest_version": 2,
"time_spine": None,
"freshness": None,
},
"model.test.ref_versioned_model": {
"alias": "ref_versioned_model",
Expand Down Expand Up @@ -1738,6 +1745,7 @@ def expected_versions_manifest(project):
"version": None,
"latest_version": None,
"time_spine": None,
"freshness": None,
},
"test.test.unique_versioned_model_v1_first_name.6138195dec": {
"alias": "unique_versioned_model_v1_first_name",
Expand Down
1 change: 1 addition & 0 deletions tests/unit/contracts/graph/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"defer_relation",
"time_spine",
"batch",
"freshness",
}
)

Expand Down
13 changes: 10 additions & 3 deletions tests/unit/parser/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

from dbt import tracking
from dbt.artifacts.resources import ModelConfig, RefArgs
from dbt.artifacts.resources.v1.model import ModelBuildAfter
from dbt.artifacts.resources.v1.model import (
ModelBuildAfter,
ModelFreshnessDependsOnOptions,
)
from dbt.context.context_config import ContextConfig
from dbt.contracts.files import FileHash, FilePath, SchemaSourceFile, SourceFile
from dbt.contracts.graph.manifest import Manifest
Expand Down Expand Up @@ -728,7 +731,9 @@ def test__parse_model_freshness(self):

assert self.parser.manifest.nodes[
"model.root.my_model"
].freshness.build_after == ModelBuildAfter(count=1, period="day", depends_on="any")
].freshness.build_after == ModelBuildAfter(
count=1, period="day", depends_on=ModelFreshnessDependsOnOptions.any
)

def test__parse_model_freshness_depend_on(self):
block = self.file_block_for(SINGLE_TALBE_MODEL_FRESHNESS_ONLY_DEPEND_ON, "test_one.yml")
Expand All @@ -738,7 +743,9 @@ def test__parse_model_freshness_depend_on(self):
self.assert_has_manifest_lengths(self.parser.manifest, nodes=1)
assert self.parser.manifest.nodes[
"model.root.my_model"
].freshness.build_after == ModelBuildAfter(count=0, period="hour", depends_on="all")
].freshness.build_after == ModelBuildAfter(
count=0, period="hour", depends_on=ModelFreshnessDependsOnOptions.all
)

def test__read_basic_model_tests_wrong_severity(self):
block = self.yaml_block_for(SINGLE_TABLE_MODEL_TESTS_WRONG_SEVERITY, "test_one.yml")
Expand Down

0 comments on commit 0c96f71

Please sign in to comment.