-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathtest_utils.py
More file actions
361 lines (254 loc) · 9.45 KB
/
test_utils.py
File metadata and controls
361 lines (254 loc) · 9.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
import pytest
from dbt.tests.adapter.utils import fixture_cast_bool_to_text, fixture_dateadd, fixture_listagg
from dbt.tests.adapter.utils.test_any_value import BaseAnyValue
from dbt.tests.adapter.utils.test_array_append import BaseArrayAppend
from dbt.tests.adapter.utils.test_array_concat import BaseArrayConcat
from dbt.tests.adapter.utils.test_array_construct import BaseArrayConstruct
from dbt.tests.adapter.utils.test_bool_or import BaseBoolOr
from dbt.tests.adapter.utils.test_cast import BaseCast
from dbt.tests.adapter.utils.test_cast_bool_to_text import BaseCastBoolToText
from dbt.tests.adapter.utils.test_concat import BaseConcat
from dbt.tests.adapter.utils.test_current_timestamp import (
BaseCurrentTimestampAware,
BaseCurrentTimestampNaive,
)
from dbt.tests.adapter.utils.test_date import BaseDate
from dbt.tests.adapter.utils.test_date_spine import BaseDateSpine
from dbt.tests.adapter.utils.test_date_trunc import BaseDateTrunc
from dbt.tests.adapter.utils.test_dateadd import BaseDateAdd
from dbt.tests.adapter.utils.test_datediff import BaseDateDiff
from dbt.tests.adapter.utils.test_equals import BaseEquals
from dbt.tests.adapter.utils.test_escape_single_quotes import (
BaseEscapeSingleQuotesBackslash,
BaseEscapeSingleQuotesQuote,
)
from dbt.tests.adapter.utils.test_except import BaseExcept
from dbt.tests.adapter.utils.test_generate_series import BaseGenerateSeries
from dbt.tests.adapter.utils.test_get_intervals_between import BaseGetIntervalsBetween
from dbt.tests.adapter.utils.test_get_powers_of_two import BaseGetPowersOfTwo
from dbt.tests.adapter.utils.test_hash import BaseHash
from dbt.tests.adapter.utils.test_intersect import BaseIntersect
from dbt.tests.adapter.utils.test_last_day import BaseLastDay
from dbt.tests.adapter.utils.test_length import BaseLength
from dbt.tests.adapter.utils.test_listagg import BaseListagg
from dbt.tests.adapter.utils.test_null_compare import BaseMixedNullCompare, BaseNullCompare
from dbt.tests.adapter.utils.test_position import BasePosition
from dbt.tests.adapter.utils.test_replace import BaseReplace
from dbt.tests.adapter.utils.test_right import BaseRight
from dbt.tests.adapter.utils.test_safe_cast import BaseSafeCast
from dbt.tests.adapter.utils.test_split_part import BaseSplitPart
from dbt.tests.adapter.utils.test_string_literal import BaseStringLiteral
from dbt.tests.adapter.utils.test_timestamps import BaseCurrentTimestamps
from dbt.tests.adapter.utils.test_validate_sql import BaseValidateSqlMethod
# flake8: noqa: E501
class TestAnyValue(BaseAnyValue):
pass
@pytest.mark.skip(reason="Not supported/Not implemented")
class TestArrayAppend(BaseArrayAppend):
pass
@pytest.mark.skip(reason="Not supported/Not implemented")
class TestArrayConcat(BaseArrayConcat):
pass
@pytest.mark.skip(reason="Not supported/Not implemented")
class TestArrayConstruct(BaseArrayConstruct):
pass
@pytest.mark.skip(reason="Not supported/Not implemented")
class TestBoolOr(BaseBoolOr):
pass
class TestCast(BaseCast):
pass
models__test_cast_bool_to_text_sql = """
with data as (
select 0 as input, 'false' as expected union all
select 1 as input, 'true' as expected union all
select null as input, null as expected
)
select
{{ cast_bool_to_text("input") }} as actual,
expected
from data
"""
class TestCastBoolToText(BaseCastBoolToText):
@pytest.fixture(scope="class")
def models(self):
return {
"test_cast_bool_to_text.yml": fixture_cast_bool_to_text.models__test_cast_bool_to_text_yml, # noqa: E501
"test_cast_bool_to_text.sql": self.interpolate_macro_namespace(
models__test_cast_bool_to_text_sql, "cast_bool_to_text"
),
}
class TestConcat(BaseConcat):
pass
@pytest.mark.skip(
reason="Only should implement Aware or Naive. Opted for Naive to align with fabric."
)
class TestCurrentTimestampAware(BaseCurrentTimestampAware):
pass
class TestCurrentTimestampNaive(BaseCurrentTimestampNaive):
pass
@pytest.mark.skip(reason="Date spine relies on recursive CTES which are not supported.")
class TestDate(BaseDate):
pass
@pytest.mark.skip(reason="Date spine relies on recursive CTES which are not supported.")
class TestDateSpine(BaseDateSpine):
pass
class TestDateTrunc(BaseDateTrunc):
pass
class TestDateAdd(BaseDateAdd):
models__test_dateadd_sql = """
with data as (
select * from {{ ref('data_dateadd') }}
)
select
case
when datepart = 'hour' then cast({{ dateadd('hour', 'interval_length', 'from_time') }} as {{ api.Column.translate_type('timestamp') }})
when datepart = 'day' then cast({{ dateadd('day', 'interval_length', 'from_time') }} as {{ api.Column.translate_type('timestamp') }})
when datepart = 'month' then cast({{ dateadd('month', 'interval_length', 'from_time') }} as {{ api.Column.translate_type('timestamp') }})
when datepart = 'year' then cast({{ dateadd('year', 'interval_length', 'from_time') }} as {{ api.Column.translate_type('timestamp') }})
else null
end as actual,
result as expected
from data
"""
@pytest.fixture(scope="class")
def project_config_update(self):
return {
"name": "test",
# this is only needed for BigQuery, right?
# no harm having it here until/unless there's an adapter that doesn't support the 'timestamp' type
"seeds": {
"test": {
"data_dateadd": {
"+column_types": {
"from_time": "datetime2(6)",
"result": "datetime2(6)",
},
},
},
},
}
@pytest.fixture(scope="class")
def seeds(self):
return {"data_dateadd.csv": fixture_dateadd.seeds__data_dateadd_csv}
@pytest.fixture(scope="class")
def models(self):
return {
"test_dateadd.yml": fixture_dateadd.models__test_dateadd_yml,
"test_dateadd.sql": self.interpolate_macro_namespace(
self.models__test_dateadd_sql, "dateadd"
),
}
class TestDateDiff(BaseDateDiff):
pass
class TestEquals(BaseEquals):
pass
class TestEscapeSingleQuotesQuote(BaseEscapeSingleQuotesQuote):
pass
@pytest.mark.skip(reason="SQLServer applies escaping with double of values")
class TestEscapeSingleQuotesBackslash(BaseEscapeSingleQuotesBackslash):
pass
class TestExcept(BaseExcept):
pass
@pytest.mark.skip(
reason="Only newer versions of SQLServer support Generate Series. Skipping for back compat"
)
class TestGenerateSeries(BaseGenerateSeries):
pass
class TestGetIntervalsBetween(BaseGetIntervalsBetween):
pass
class TestGetPowersOfTwo(BaseGetPowersOfTwo):
pass
class TestHash(BaseHash):
pass
class TestIntersect(BaseIntersect):
pass
class TestLastDay(BaseLastDay):
pass
class TestLength(BaseLength):
pass
seeds__data_listagg_output_csv = """group_col,expected,version
1,"a_|_b_|_c",bottom_ordered
2,"1_|_a_|_p",bottom_ordered
3,"g_|_g_|_g",bottom_ordered
1,"c_|_b_|_a",reverse_order
2,"p_|_a_|_1",reverse_order
3,"g_|_g_|_g",reverse_order
3,"g, g, g",comma_whitespace_unordered
"""
models__test_listagg_sql = """
with data as (
select * from {{ ref('data_listagg') }}
),
data_output as (
select * from {{ ref('data_listagg_output') }}
),
calculate as (
select
group_col,
{{ listagg('string_text', "'_|_'", "order by order_col") }} as actual,
'bottom_ordered' as version
from data
group by group_col
union all
select
group_col,
{{ listagg('string_text', "'_|_'", "order by order_col desc", 2) }} as actual,
'reverse_order' as version
from data
group by group_col
union all
select
group_col,
{{ listagg('string_text', "', '") }} as actual,
'comma_whitespace_unordered' as version
from data
where group_col = 3
group by group_col
)
select
calculate.actual,
data_output.expected
from calculate
left join data_output
on calculate.group_col = data_output.group_col
and calculate.version = data_output.version
"""
class TestListagg(BaseListagg):
@pytest.fixture(scope="class")
def seeds(self):
return {
"data_listagg.csv": fixture_listagg.seeds__data_listagg_csv,
"data_listagg_output.csv": seeds__data_listagg_output_csv,
}
@pytest.fixture(scope="class")
def models(self):
return {
"test_listagg.yml": fixture_listagg.models__test_listagg_yml,
"test_listagg.sql": self.interpolate_macro_namespace(
models__test_listagg_sql, "listagg"
),
}
class TestMixedNullCompare(BaseMixedNullCompare):
pass
class TestNullCompare(BaseNullCompare):
pass
class TestPosition(BasePosition):
pass
class TestReplace(BaseReplace):
pass
class TestRight(BaseRight):
pass
class TestSafeCast(BaseSafeCast):
pass
class TestSplitPart(BaseSplitPart):
pass
class TestStringLiteral(BaseStringLiteral):
pass
@pytest.mark.skip(reason="""
comment here about why this is skipped.
https://github.com/dbt-labs/dbt-adapters/blob/f1987d4313cc94bac9906963dff1337ee0bffbc6/dbt/include/global_project/macros/adapters/timestamps.sql#L39
""")
class TestCurrentTimestamps(BaseCurrentTimestamps):
pass
class TestValidateSqlMethod(BaseValidateSqlMethod):
pass