Skip to content

Commit

Permalink
Fix query comment tests (#7928) (#7928)
Browse files Browse the repository at this point in the history
  • Loading branch information
damian3031 authored Jul 13, 2023
1 parent 95a9169 commit 015c490
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
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"
36 changes: 18 additions & 18 deletions tests/adapter/dbt/tests/adapter/query_comment/test_query_comment.py
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

0 comments on commit 015c490

Please sign in to comment.