forked from dbt-labs/dbt-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_manifest_selectors.py
115 lines (100 loc) · 4.07 KB
/
test_manifest_selectors.py
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
import dbt.exceptions
import textwrap
import yaml
import unittest
from dbt.config.selectors import SelectorDict
def get_selector_dict(txt: str) -> dict:
txt = textwrap.dedent(txt)
dct = yaml.safe_load(txt)
return dct
class SelectorUnitTest(unittest.TestCase):
def test_compare_cli_non_cli(self):
dct = get_selector_dict('''\
selectors:
- name: nightly_diet_snowplow
description: "This uses more CLI-style syntax"
definition:
union:
- intersection:
- '@source:snowplow'
- 'tag:nightly'
- 'models/export'
- exclude:
- intersection:
- 'package:snowplow'
- 'config.materialized:incremental'
- export_performance_timing
- name: nightly_diet_snowplow_full
description: "This is a fuller YAML specification"
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
''')
sel_dict = SelectorDict.parse_from_selectors_list(dct['selectors'])
assert(sel_dict)
with_strings = sel_dict['nightly_diet_snowplow']['definition']
no_strings = sel_dict['nightly_diet_snowplow_full']['definition']
self.assertEqual(with_strings, no_strings)
def test_single_string_definition(self):
dct = get_selector_dict('''\
selectors:
- name: nightly_selector
definition:
'tag:nightly'
''')
sel_dict = SelectorDict.parse_from_selectors_list(dct['selectors'])
assert(sel_dict)
expected = {'method': 'tag', 'value': 'nightly'}
definition = sel_dict['nightly_selector']['definition']
self.assertEqual(expected, definition)
def test_single_key_value_definition(self):
dct = get_selector_dict('''\
selectors:
- name: nightly_selector
definition:
tag: nightly
''')
sel_dict = SelectorDict.parse_from_selectors_list(dct['selectors'])
assert(sel_dict)
expected = {'method': 'tag', 'value': 'nightly'}
definition = sel_dict['nightly_selector']['definition']
self.assertEqual(expected, definition)
def test_parent_definition(self):
dct = get_selector_dict('''\
selectors:
- name: kpi_nightly_selector
definition:
'+exposure:kpi_nightly'
''')
sel_dict = SelectorDict.parse_from_selectors_list(dct['selectors'])
assert(sel_dict)
expected = {'method': 'exposure', 'value': 'kpi_nightly', 'parents': True}
definition = sel_dict['kpi_nightly_selector']['definition']
self.assertEqual(expected, definition)
def test_plus_definition(self):
dct = get_selector_dict('''\
selectors:
- name: my_model_children_selector
definition:
'my_model+2'
''')
sel_dict = SelectorDict.parse_from_selectors_list(dct['selectors'])
assert(sel_dict)
expected = {'method': 'fqn', 'value': 'my_model', 'children': True, 'children_depth': '2'}
definition = sel_dict['my_model_children_selector']['definition']
self.assertEqual(expected, definition)