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 2 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: 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 @@ def handle_change(key: str, delete: Callable):
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)
handle_change("saved_queries", self.delete_schema_saved_query)

def _handle_element_change(
Expand Down Expand Up @@ -711,7 +711,7 @@ def _handle_element_change(
# 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"
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 @@ def get_diff_for(self, key, saved_yaml_dict, new_yaml_dict):
# 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 @@

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")

Check warning on line 196 in core/dbt/parser/unit_tests.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/parser/unit_tests.py#L196

Added line #L196 was not covered by 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 @@
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}"

Check warning on line 207 in core/dbt/parser/unit_tests.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/parser/unit_tests.py#L207

Added line #L207 was not covered by tests
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
4 changes: 2 additions & 2 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
14 changes: 7 additions & 7 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_tests.snowplow.my_model.test_my_model",
given=[],
expect=UnitTestOutputFixture(rows=[{"a": 1}]),
description="unit test description",
Expand Down
Loading