From ef41c92ba7086fcc094e326f66ae8a922f132407 Mon Sep 17 00:00:00 2001 From: Damian Owsianny Date: Mon, 19 Jun 2023 22:49:15 +0200 Subject: [PATCH] Fix query comment tests (#7928) --- .../unreleased/Fixes-20230623-092933.yaml | 6 ++++ .../query_comment/test_query_comment.py | 36 +++++++++---------- 2 files changed, 24 insertions(+), 18 deletions(-) create mode 100644 .changes/unreleased/Fixes-20230623-092933.yaml diff --git a/.changes/unreleased/Fixes-20230623-092933.yaml b/.changes/unreleased/Fixes-20230623-092933.yaml new file mode 100644 index 00000000000..8221fb8034d --- /dev/null +++ b/.changes/unreleased/Fixes-20230623-092933.yaml @@ -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" diff --git a/tests/adapter/dbt/tests/adapter/query_comment/test_query_comment.py b/tests/adapter/dbt/tests/adapter/query_comment/test_query_comment.py index 053fcc506c8..16d51b35e75 100644 --- a/tests/adapter/dbt/tests/adapter/query_comment/test_query_comment.py +++ b/tests/adapter/dbt/tests/adapter/query_comment/test_query_comment.py @@ -28,13 +28,6 @@ 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): @@ -42,8 +35,9 @@ class BaseQueryComments(BaseDefaultQueryComments): 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): @@ -51,8 +45,9 @@ class BaseMacroQueryComments(BaseDefaultQueryComments): 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): @@ -60,14 +55,17 @@ class BaseMacroArgsQueryComments(BaseDefaultQueryComments): 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 @@ -76,7 +74,7 @@ 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) @@ -84,9 +82,10 @@ def run_assert_comments(self): 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 @@ -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