Skip to content

Commit

Permalink
Convert test_from_parts of TestRuntimeConfig to a pytest test usi…
Browse files Browse the repository at this point in the history
…ng fixtures
  • Loading branch information
QMalcolm committed May 28, 2024
1 parent 0db7352 commit cb97686
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 23 deletions.
2 changes: 1 addition & 1 deletion tests/unit/config/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
53 changes: 33 additions & 20 deletions tests/unit/config/test_runtime.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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({})
)


Expand Down
2 changes: 1 addition & 1 deletion tests/unit/utils/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[],
Expand Down

0 comments on commit cb97686

Please sign in to comment.