From cb97686f69182f986c07cfd99fcd0444be7d7ad3 Mon Sep 17 00:00:00 2001 From: Quigley Malcolm Date: Tue, 28 May 2024 16:21:16 -0700 Subject: [PATCH] Convert `test_from_parts` of `TestRuntimeConfig` to a pytest test using fixtures --- tests/unit/config/test_project.py | 2 +- tests/unit/config/test_runtime.py | 53 +++++++++++++++++++------------ tests/unit/utils/config.py | 2 +- tests/unit/utils/project.py | 2 +- 4 files changed, 36 insertions(+), 23 deletions(-) diff --git a/tests/unit/config/test_project.py b/tests/unit/config/test_project.py index 7d0006570af..6b9cbfb1ddb 100644 --- a/tests/unit/config/test_project.py +++ b/tests/unit/config/test_project.py @@ -42,7 +42,7 @@ def test_fixture_paths(self, project: Project): def test__str__(self, project: Project): assert ( str(project) - == "{'name': 'test_project', 'version': 1.0, 'project-root': 'doesnt/actually/exist', 'profile': 'test_profile', 'model-paths': ['models'], 'macro-paths': ['macros'], 'seed-paths': ['seeds'], 'test-paths': ['tests'], 'analysis-paths': ['analyses'], 'docs-paths': ['docs'], 'asset-paths': ['assets'], 'target-path': 'target', 'snapshot-paths': ['snapshots'], 'clean-targets': ['target'], 'log-path': 'path/to/project/logs', 'quoting': {'database': True, 'schema': True, 'identifier': True}, 'models': {}, 'on-run-start': [], 'on-run-end': [], 'dispatch': [{'macro_namespace': 'dbt_utils', 'search_order': ['test_project', 'dbt_utils']}], 'seeds': {}, 'snapshots': {}, 'sources': {}, 'data_tests': {}, 'unit_tests': {}, 'metrics': {}, 'semantic-models': {}, 'saved-queries': {}, 'exposures': {}, 'vars': {}, 'require-dbt-version': ['=0.0.0'], 'restrict-access': False, 'dbt-cloud': {}, 'query-comment': {'comment': \"\\n{%- set comment_dict = {} -%}\\n{%- do comment_dict.update(\\n app='dbt',\\n dbt_version=dbt_version,\\n profile_name=target.get('profile_name'),\\n target_name=target.get('target_name'),\\n) -%}\\n{%- if node is not none -%}\\n {%- do comment_dict.update(\\n node_id=node.unique_id,\\n ) -%}\\n{% else %}\\n {# in the node context, the connection name is the node_id #}\\n {%- do comment_dict.update(connection_name=connection_name) -%}\\n{%- endif -%}\\n{{ return(tojson(comment_dict)) }}\\n\", 'append': False, 'job-label': False}, 'packages': []}" + == "{'name': 'test_project', 'version': 1.0, 'project-root': 'doesnt/actually/exist', 'profile': 'test_profile', 'model-paths': ['models'], 'macro-paths': ['macros'], 'seed-paths': ['seeds'], 'test-paths': ['tests'], 'analysis-paths': ['analyses'], 'docs-paths': ['docs'], 'asset-paths': ['assets'], 'target-path': 'target', 'snapshot-paths': ['snapshots'], 'clean-targets': ['target'], 'log-path': 'path/to/project/logs', 'quoting': {}, 'models': {}, 'on-run-start': [], 'on-run-end': [], 'dispatch': [{'macro_namespace': 'dbt_utils', 'search_order': ['test_project', 'dbt_utils']}], 'seeds': {}, 'snapshots': {}, 'sources': {}, 'data_tests': {}, 'unit_tests': {}, 'metrics': {}, 'semantic-models': {}, 'saved-queries': {}, 'exposures': {}, 'vars': {}, 'require-dbt-version': ['=0.0.0'], 'restrict-access': False, 'dbt-cloud': {}, 'query-comment': {'comment': \"\\n{%- set comment_dict = {} -%}\\n{%- do comment_dict.update(\\n app='dbt',\\n dbt_version=dbt_version,\\n profile_name=target.get('profile_name'),\\n target_name=target.get('target_name'),\\n) -%}\\n{%- if node is not none -%}\\n {%- do comment_dict.update(\\n node_id=node.unique_id,\\n ) -%}\\n{% else %}\\n {# in the node context, the connection name is the node_id #}\\n {%- do comment_dict.update(connection_name=connection_name) -%}\\n{%- endif -%}\\n{{ return(tojson(comment_dict)) }}\\n\", 'append': False, 'job-label': False}, 'packages': []}" ) def test_get_selector(self, project: Project): diff --git a/tests/unit/config/test_runtime.py b/tests/unit/config/test_runtime.py index 2957a66c0cd..54124426400 100644 --- a/tests/unit/config/test_runtime.py +++ b/tests/unit/config/test_runtime.py @@ -1,7 +1,10 @@ import os +import tempfile from argparse import Namespace from unittest import mock +import pytest + import dbt.config import dbt.exceptions from dbt import tracking @@ -19,12 +22,42 @@ class TestRuntimeConfig: + @pytest.fixture + def args(self) -> Namespace: + return Namespace( + profiles_dir=tempfile.mkdtemp(), + cli_vars={}, + version_check=True, + project_dir=tempfile.mkdtemp(), + target=None, + threads=None, + profile=None, + ) + def test_str(self, profile: Profile, project: Project) -> None: config = dbt.config.RuntimeConfig.from_parts(project, profile, {}) # to make sure nothing terrible happens str(config) + def test_from_parts(self, args: Namespace, profile: Profile, project: Project): + config = dbt.config.RuntimeConfig.from_parts(project, profile, args) + + assert config.cli_vars == {} + assert config.to_profile_info() == profile.to_profile_info() + # we should have the default quoting set in the full config, but not in + # the project + # TODO(jeb): Adapters must assert that quoting is populated? + expected_project = project.to_project_config() + assert expected_project["quoting"] == {} + + expected_project["quoting"] = { + "database": True, + "identifier": True, + "schema": True, + } + assert config.to_project_config() == expected_project + class TestRuntimeConfigOLD(BaseConfigTest): def get_project(self): @@ -52,26 +85,6 @@ def from_parts(self, exc=None): else: return err - def test_from_parts(self): - project = self.get_project() - profile = self.get_profile() - config = dbt.config.RuntimeConfig.from_parts(project, profile, self.args) - - self.assertEqual(config.cli_vars, {}) - self.assertEqual(config.to_profile_info(), profile.to_profile_info()) - # we should have the default quoting set in the full config, but not in - # the project - # TODO(jeb): Adapters must assert that quoting is populated? - expected_project = project.to_project_config() - self.assertEqual(expected_project["quoting"], {}) - - expected_project["quoting"] = { - "database": True, - "identifier": True, - "schema": True, - } - self.assertEqual(config.to_project_config(), expected_project) - def test_supported_version(self): self.default_project_data["require-dbt-version"] = ">0.0.0" conf = self.from_parts() diff --git a/tests/unit/utils/config.py b/tests/unit/utils/config.py index d34c62fa901..72cb4fa024c 100644 --- a/tests/unit/utils/config.py +++ b/tests/unit/utils/config.py @@ -37,7 +37,7 @@ def profile() -> Profile: }, } return Profile.from_raw_profile_info( - raw_profile=profile_yaml, profile_name="unit_tests", renderer=ProfileRenderer({}) + raw_profile=profile_yaml, profile_name="test_profile", renderer=ProfileRenderer({}) ) diff --git a/tests/unit/utils/project.py b/tests/unit/utils/project.py index c7215990e6d..2e374b82fac 100644 --- a/tests/unit/utils/project.py +++ b/tests/unit/utils/project.py @@ -45,7 +45,7 @@ def project(selector_config: SelectorConfig) -> Project: log_path="path/to/project/logs", packages_install_path="dbt_packages", packages_specified_path="packages.yml", - quoting={"database": True, "schema": True, "identifier": True}, + quoting={}, models={}, on_run_start=[], on_run_end=[],