Skip to content

Commit 5bf0bca

Browse files
committed
updated test logic and tests
1 parent be032aa commit 5bf0bca

File tree

5 files changed

+33
-44
lines changed

5 files changed

+33
-44
lines changed

.devcontainer/devcontainer-lock.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "Python 3",
33
"image": "mcr.microsoft.com/devcontainers/python:1-3.10-bookworm",
44
"features": {
5-
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
5+
"ghcr.io/devcontainers/features/docker-in-docker:2.12.0": {}
66
},
77
"forwardPorts": [1433],
88
"postStartCommand": "/bin/bash ./.devcontainer/setup_odbc.sh & /bin/bash ./.devcontainer/setup_env.sh",

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,4 @@ env.bak/
9797
venv.bak/
9898
.mise.toml
9999

100-
**devcontainer-lock.json**
100+
devcontainer-lock.json

dbt/include/sqlserver/macros/materializations/tests.sql

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,23 @@
77
EXEC('CREATE SCHEMA [{{ target.schema }}]')
88
END
99

10-
{% set with_statement_pattern = 'with .+ as\s*\(' %}
11-
{% set re = modules.re %}
12-
{% set is_match = re.search(with_statement_pattern, main_sql, re.IGNORECASE) %}
10+
{% set testview %}
11+
[{{ target.schema }}.testview_{{ range(1300, 19000) | random }}]
12+
{% endset %}
1313

14-
{% if is_match %}
15-
{% set testview %}
16-
[{{ target.schema }}.testview_{{ range(1300, 19000) | random }}]
17-
{% endset %}
14+
{% set sql = main_sql.replace("'", "''")%}
15+
EXEC('create view {{testview}} as {{ sql }};')
16+
select
17+
{{ "top (" ~ limit ~ ')' if limit != none }}
18+
{{ fail_calc }} as failures,
19+
case when {{ fail_calc }} {{ warn_if }}
20+
then 'true' else 'false' end as should_warn,
21+
case when {{ fail_calc }} {{ error_if }}
22+
then 'true' else 'false' end as should_error
23+
from (
24+
select * from {{testview}}
25+
) dbt_internal_test;
1826

19-
{% set sql = main_sql.replace("'", "''")%}
20-
EXEC('create view {{testview}} as {{ sql }};')
21-
select
22-
{{ "top (" ~ limit ~ ')' if limit != none }}
23-
{{ fail_calc }} as failures,
24-
case when {{ fail_calc }} {{ warn_if }}
25-
then 'true' else 'false' end as should_warn,
26-
case when {{ fail_calc }} {{ error_if }}
27-
then 'true' else 'false' end as should_error
28-
from (
29-
select * from {{testview}}
30-
) dbt_internal_test;
27+
EXEC('drop view {{testview}};')
3128

32-
EXEC('drop view {{testview}};')
33-
34-
{% else -%}
35-
select
36-
{{ "top (" ~ limit ~ ')' if limit != none }}
37-
{{ fail_calc }} as failures,
38-
case when {{ fail_calc }} {{ warn_if }}
39-
then 'true' else 'false' end as should_warn,
40-
case when {{ fail_calc }} {{ error_if }}
41-
then 'true' else 'false' end as should_error
42-
from (
43-
{{ main_sql }}
44-
) dbt_internal_test
45-
{%- endif -%}
4629
{%- endmacro %}

tests/functional/adapter/mssql/test_test_with.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,20 @@
8484
{% endtest %}
8585
"""
8686

87+
with_test_multiline = """
88+
{% test with_test_multiline(model, field) %}
89+
-- comments
90+
with
91+
92+
test_sample AS (
93+
SELECT {{ field }} FROM {{ model }}
94+
GROUP BY {{ field }}
95+
HAVING COUNT(*) > 2
96+
)
97+
SELECT * FROM test_sample
98+
{% endtest %}
99+
"""
100+
87101

88102
class BaseSQLTestWith:
89103
@pytest.fixture(scope="class")
@@ -99,6 +113,7 @@ def macros(self):
99113
"with_statement_pass.sql": with_test_pass_sql,
100114
"with_statement_fail.sql": with_test_fail_sql,
101115
"with_statement_comments.sql": with_test_with_comments_sql,
116+
"with_test_multiline.sql": with_test_multiline,
102117
}
103118

104119
@pytest.fixture(scope="class")

0 commit comments

Comments
 (0)