Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update unit test key: unit -> unit-tests #8988

Merged
merged 3 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/dbt/config/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ def to_project_config(self, with_packages=False):
"snapshots": self.snapshots,
"sources": self.sources,
"tests": self.tests,
"unit_tests": self.unit_tests,
"unit-tests": self.unit_tests,
"metrics": self.metrics,
"semantic-models": self.semantic_models,
"saved-queries": self.saved_queries,
Expand Down
1 change: 0 additions & 1 deletion core/dbt/contracts/graph/model_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,6 @@ class UnitTestConfig(BaseConfig):
NodeType.Source: SourceConfig,
NodeType.Seed: SeedConfig,
NodeType.Test: TestConfig,
NodeType.Unit: TestConfig,
NodeType.Model: NodeConfig,
NodeType.Snapshot: SnapshotConfig,
NodeType.Unit: UnitTestConfig,
Expand Down
1 change: 1 addition & 0 deletions core/dbt/contracts/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ class Config(dbtMashConfig):
"semantic_models": "semantic-models",
"saved_queries": "saved-queries",
"dbt_cloud": "dbt-cloud",
"unit_tests": "unit-tests",
}

@classmethod
Expand Down
6 changes: 3 additions & 3 deletions core/dbt/parser/partial.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@
handle_change("metrics", self.delete_schema_metric)
handle_change("groups", self.delete_schema_group)
handle_change("semantic_models", self.delete_schema_semantic_model)
handle_change("unit", self.delete_schema_unit_test)
handle_change("unit_tests", self.delete_schema_unit_test)

Check warning on line 684 in core/dbt/parser/partial.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/parser/partial.py#L684

Added line #L684 was not covered by tests
handle_change("saved_queries", self.delete_schema_saved_query)

def _handle_element_change(
Expand Down Expand Up @@ -711,7 +711,7 @@
# Take a "section" of the schema file yaml dictionary from saved and new schema files
# and determine which parts have changed
def get_diff_for(self, key, saved_yaml_dict, new_yaml_dict):
dict_name = "model" if key == "unit" else "name"
dict_name = "model" if key == "unit_tests" else "name"

Check warning on line 714 in core/dbt/parser/partial.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/parser/partial.py#L714

Added line #L714 was not covered by tests
emmyoop marked this conversation as resolved.
Show resolved Hide resolved
if key in saved_yaml_dict or key in new_yaml_dict:
saved_elements = saved_yaml_dict[key] if key in saved_yaml_dict else []
new_elements = new_yaml_dict[key] if key in new_yaml_dict else []
Expand Down Expand Up @@ -754,7 +754,7 @@
# flag indicates that we're processing a schema file, so if a matching
# patch has already been scheduled, replace it.
def merge_patch(self, schema_file, key, patch, new_patch=False):
elem_name = "model" if key == "unit" else "name"
elem_name = "model" if key == "unit_tests" else "name"
emmyoop marked this conversation as resolved.
Show resolved Hide resolved
if schema_file.pp_dict is None:
schema_file.pp_dict = {}
pp_dict = schema_file.pp_dict
Expand Down
7 changes: 4 additions & 3 deletions core/dbt/parser/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def parse_file(self, block: FileBlock, dct: Optional[Dict] = None) -> None:
semantic_model_parser = SemanticModelParser(self, yaml_block)
semantic_model_parser.parse()

if "unit" in dct:
if "unit_tests" in dct:
emmyoop marked this conversation as resolved.
Show resolved Hide resolved
from dbt.parser.unit_tests import UnitTestParser

unit_test_parser = UnitTestParser(self, yaml_block)
Expand Down Expand Up @@ -262,12 +262,13 @@ class ParseResult:


# abstract base class (ABCMeta)
# Four subclasses: MetricParser, ExposureParser, GroupParser, SourceParser, PatchParser
# Many subclasses: MetricParser, ExposureParser, GroupParser, SourceParser,
# PatchParser, SemanticModelParser, SavedQueryParser, UnitTestParser
class YamlReader(metaclass=ABCMeta):
def __init__(self, schema_parser: SchemaParser, yaml: YamlBlock, key: str) -> None:
self.schema_parser = schema_parser
# key: models, seeds, snapshots, sources, macros,
# analyses, exposures
# analyses, exposures, unit_tests
self.key = key
self.yaml = yaml
self.schema_yaml_vars = SchemaYamlVars()
Expand Down
6 changes: 2 additions & 4 deletions core/dbt/parser/unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def _get_original_input_node(self, input: str, tested_node: ModelNode):

class UnitTestParser(YamlReader):
def __init__(self, schema_parser: SchemaParser, yaml: YamlBlock) -> None:
super().__init__(schema_parser, yaml, "unit")
super().__init__(schema_parser, yaml, "unit_tests")
emmyoop marked this conversation as resolved.
Show resolved Hide resolved
self.schema_parser = schema_parser
self.yaml = yaml

Expand All @@ -204,9 +204,7 @@ def parse(self) -> ParseResult:
tested_model_node = self._find_tested_model_node(unit_test_suite)

for test in unit_test_suite.tests:
unit_test_case_unique_id = (
f"unit.{self.project.project_name}.{unit_test_suite.model}.{test.name}"
)
unit_test_case_unique_id = f"{NodeType.Unit}.{self.project.project_name}.{unit_test_suite.model}.{test.name}"
unit_test_fqn = [self.project.project_name] + model_name_split + [test.name]
unit_test_config = self._build_unit_test_config(unit_test_fqn, test.config)

Expand Down
6 changes: 3 additions & 3 deletions tests/functional/unit_testing/test_unit_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"""

test_my_model_yml = """
unit:
unit_tests:
- model: my_model
tests:
- name: test_my_model
Expand Down Expand Up @@ -180,7 +180,7 @@ def test_basic(self, project):


test_my_model_csv_yml = """
unit:
unit_tests:
- model: my_model
tests:
- name: test_my_model
Expand Down Expand Up @@ -355,7 +355,7 @@ def test_basic(self, project):
"""

test_my_model_incremental_yml = """
unit:
unit_tests:
- model: my_incremental_model
tests:
- name: incremental_false
Expand Down
18 changes: 9 additions & 9 deletions tests/unit/test_unit_test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


UNIT_TEST_MODEL_NOT_FOUND_SOURCE = """
unit:
unit_tests:
- model: my_model_doesnt_exist
tests:
- name: test_my_model_doesnt_exist
Expand All @@ -24,7 +24,7 @@


UNIT_TEST_SOURCE = """
unit:
unit_tests:
- model: my_model
tests:
- name: test_my_model
Expand All @@ -37,7 +37,7 @@


UNIT_TEST_VERSIONED_MODEL_SOURCE = """
unit:
unit_tests:
- model: my_model_versioned.v1
tests:
- name: test_my_model_versioned
Expand All @@ -50,7 +50,7 @@


UNIT_TEST_CONFIG_SOURCE = """
unit:
unit_tests:
- model: my_model
tests:
- name: test_my_model
Expand All @@ -68,7 +68,7 @@


UNIT_TEST_MULTIPLE_SOURCE = """
unit:
unit_tests:
- model: my_model
tests:
- name: test_my_model
Expand Down Expand Up @@ -105,7 +105,7 @@ def setUp(self):
)

def file_block_for(self, data, filename):
return super().file_block_for(data, filename, "unit")
return super().file_block_for(data, filename, "unit_tests")

def test_basic_model_not_found(self):
block = self.yaml_block_for(UNIT_TEST_MODEL_NOT_FOUND_SOURCE, "test_my_model.yml")
Expand All @@ -127,7 +127,7 @@ def test_basic(self):
package_name="snowplow",
path=block.path.relative_path,
original_file_path=block.path.original_file_path,
unique_id="unit.snowplow.my_model.test_my_model",
unique_id="unit_test.snowplow.my_model.test_my_model",
given=[],
expect=UnitTestOutputFixture(rows=[{"a": 1}]),
description="unit test description",
Expand All @@ -147,7 +147,7 @@ def test_unit_test_config(self):
UnitTestParser(self.parser, block).parse()

self.assert_has_manifest_lengths(self.parser.manifest, nodes=1, unit_tests=1)
unit_test = self.parser.manifest.unit_tests["unit.snowplow.my_model.test_my_model"]
unit_test = self.parser.manifest.unit_tests["unit_test.snowplow.my_model.test_my_model"]
self.assertEqual(sorted(unit_test.config.tags), sorted(["schema_tag", "project_tag"]))
self.assertEqual(unit_test.config.meta, {"meta_key": "meta_value", "meta_jinja_key": "2"})

Expand All @@ -168,7 +168,7 @@ def test_unit_test_versioned_model(self):

self.assert_has_manifest_lengths(self.parser.manifest, nodes=2, unit_tests=1)
unit_test = self.parser.manifest.unit_tests[
"unit.snowplow.my_model_versioned.v1.test_my_model_versioned"
"unit_test.snowplow.my_model_versioned.v1.test_my_model_versioned"
]
self.assertEqual(len(unit_test.depends_on.nodes), 1)
self.assertEqual(unit_test.depends_on.nodes[0], "model.snowplow.my_model_versioned.v1")
Expand Down
Loading