forked from dbt-labs/dbt-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_selector_errors.py
More file actions
202 lines (187 loc) · 6.51 KB
/
test_selector_errors.py
File metadata and controls
202 lines (187 loc) · 6.51 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
import dbt.exceptions
import textwrap
import yaml
import unittest
from dbt.config.selectors import (
selector_config_from_data
)
from dbt.config.selectors import SelectorConfig
def get_selector_dict(txt: str) -> dict:
txt = textwrap.dedent(txt)
dct = yaml.safe_load(txt)
return dct
class SelectorUnitTest(unittest.TestCase):
def test_parse_multiple_excludes(self):
dct = get_selector_dict('''\
selectors:
- name: mult_excl
definition:
union:
- method: tag
value: nightly
- exclude:
- method: tag
value: hourly
- exclude:
- method: tag
value: daily
''')
with self.assertRaisesRegex(
dbt.exceptions.DbtSelectorsError,
'cannot provide multiple exclude arguments'
):
selector_config_from_data(dct)
def test_parse_set_op_plus(self):
dct = get_selector_dict('''\
selectors:
- name: union_plus
definition:
- union:
- method: tag
value: nightly
- exclude:
- method: tag
value: hourly
- method: tag
value: foo
''')
with self.assertRaisesRegex(
dbt.exceptions.DbtSelectorsError,
'Valid root-level selector definitions'
):
selector_config_from_data(dct)
def test_parse_multiple_methods(self):
dct = get_selector_dict('''\
selectors:
- name: mult_methods
definition:
- tag:hourly
- tag:nightly
- fqn:start
''')
with self.assertRaisesRegex(
dbt.exceptions.DbtSelectorsError,
'Valid root-level selector definitions'
):
selector_config_from_data(dct)
def test_parse_set_with_method(self):
dct = get_selector_dict('''\
selectors:
- name: mixed_syntaxes
definition:
key: value
method: tag
value: foo
union:
- method: tag
value: m1234
- exclude:
- method: tag
value: m5678
''')
with self.assertRaisesRegex(
dbt.exceptions.DbtSelectorsError,
"Only a single 'union' or 'intersection' key is allowed"
):
selector_config_from_data(dct)
def test_complex_sector(self):
dct = get_selector_dict('''\
selectors:
- name: nightly_diet_snowplow
definition:
union:
- intersection:
- method: source
value: snowplow
childrens_parents: true
- method: tag
value: nightly
- method: path
value: models/export
- exclude:
- intersection:
- method: package
value: snowplow
- method: config.materialized
value: incremental
- method: fqn
value: export_performance_timing
''')
selectors = selector_config_from_data(dct)
assert(isinstance(selectors, SelectorConfig))
def test_exclude_not_list(self):
dct = get_selector_dict('''\
selectors:
- name: summa_exclude
definition:
union:
- method: tag
value: nightly
- exclude:
method: tag
value: daily
''')
with self.assertRaisesRegex(
dbt.exceptions.DbtSelectorsError,
"Expected a list"
):
selector_config_from_data(dct)
def test_invalid_key(self):
dct = get_selector_dict('''\
selectors:
- name: summa_nothing
definition:
method: tag
key: nightly
''')
with self.assertRaisesRegex(
dbt.exceptions.DbtSelectorsError,
"Expected either 1 key"
):
selector_config_from_data(dct)
def test_invalid_single_def(self):
dct = get_selector_dict('''\
selectors:
- name: summa_nothing
definition:
fubar: tag
''')
with self.assertRaisesRegex(
dbt.exceptions.DbtSelectorsError,
"not a valid method name"
):
selector_config_from_data(dct)
def test_method_no_value(self):
dct = get_selector_dict('''\
selectors:
- name: summa_nothing
definition:
method: tag
''')
with self.assertRaisesRegex(
dbt.exceptions.DbtSelectorsError,
"not a valid method name"
):
selector_config_from_data(dct)
def test_multiple_default_true(self):
"""Test selector_config_from_data returns the correct error when multiple
default values are set
"""
dct = get_selector_dict('''\
selectors:
- name: summa_nothing
definition:
method: tag
value: nightly
default: true
- name: summa_something
definition:
method: tag
value: daily
default: true
''')
with self.assertRaisesRegex(
dbt.exceptions.DbtSelectorsError,
'Found multiple selectors with `default: true`:'
):
selector_config_from_data(dct)