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

Fix query comment tests #7928

Merged
merged 1 commit into from
Jul 13, 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
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230623-092933.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Fix query comment tests
time: 2023-06-23T09:29:33.225649+02:00
custom:
Author: damian3031
Issue: "7845"
Original file line number Diff line number Diff line change
Expand Up @@ -28,46 +28,44 @@ def run_get_json(self, expect_pass=True):
assert len(res) > 0
return raw_logs

def run_assert_comments(self):
logs = self.run_get_json()
return logs

def test_comments(self, project):
self.run_assert_comments()


# Base setup to be inherited #
class BaseQueryComments(BaseDefaultQueryComments):
@pytest.fixture(scope="class")
def project_config_update(self):
return {"query-comment": "dbt\nrules!\n"}

def matches_comment(self, logs) -> bool:
assert "/* dbt\nrules! */\n" in logs
def test_matches_comment(self, project) -> bool:
logs = self.run_get_json()
assert r"/* dbt\nrules! */\n" in logs


class BaseMacroQueryComments(BaseDefaultQueryComments):
@pytest.fixture(scope="class")
def project_config_update(self):
return {"query-comment": "{{ query_header_no_args() }}"}

def matches_comment(self, logs) -> bool:
assert "/* dbt macros\nare pretty cool */\n" in logs
def test_matches_comment(self, project) -> bool:
logs = self.run_get_json()
assert r"/* dbt macros\nare pretty cool */\n" in logs


class BaseMacroArgsQueryComments(BaseDefaultQueryComments):
@pytest.fixture(scope="class")
def project_config_update(self):
return {"query-comment": "{{ return(ordered_to_json(query_header_args(target.name))) }}"}

def matches_comment(self, logs) -> bool:
def test_matches_comment(self, project) -> bool:
logs = self.run_get_json()
expected_dct = {
"app": "dbt++",
"dbt_version": dbt_version,
"macro_version": "0.1.0",
"message": "blah: default2",
"message": f"blah: {project.adapter.config.target_name}",
}
expected = "/* {} */\n".format(json.dumps(expected_dct, sort_keys=True))
expected = r"/* {} */\n".format(json.dumps(expected_dct, sort_keys=True)).replace(
'"', r"\""
)
assert expected in logs


Expand All @@ -76,17 +74,18 @@ class BaseMacroInvalidQueryComments(BaseDefaultQueryComments):
def project_config_update(self):
return {"query-comment": "{{ invalid_query_header() }}"}

def run_assert_comments(self):
def test_run_assert_comments(self, project):
with pytest.raises(DbtRuntimeError):
self.run_get_json(expect_pass=False)


class BaseNullQueryComments(BaseDefaultQueryComments):
@pytest.fixture(scope="class")
def project_config_update(self):
return {"query-comment": ""}
return {"query-comment": None}

def matches_comment(self, logs) -> bool:
def test_matches_comment(self, project) -> bool:
logs = self.run_get_json()
assert "/*" not in logs or "*/" not in logs


Expand All @@ -95,7 +94,8 @@ class BaseEmptyQueryComments(BaseDefaultQueryComments):
def project_config_update(self):
return {"query-comment": ""}

def matches_comment(self, logs) -> bool:
def test_matches_comment(self, project) -> bool:
logs = self.run_get_json()
assert "/*" not in logs or "*/" not in logs


Expand Down