Skip to content

Commit

Permalink
All but selector test passing.
Browse files Browse the repository at this point in the history
  • Loading branch information
VersusFacit committed Oct 28, 2021
1 parent e3f699c commit fa42880
Showing 1 changed file with 44 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ def project_config(self):
"test-paths": ["tests"]
}

def list_tests_and_assert(self, include, exclude, expected_tests, eagerly_expand='eager', selector_name=None):
def list_tests_and_assert(self, include, exclude, expected_tests, indirect_selection='eager', selector_name=None):
list_args = [ 'ls', '--resource-type', 'test']
if include:
list_args.extend(('--select', include))
if exclude:
list_args.extend(('--exclude', exclude))
if eagerly_expand:
list_args.extend(('--indirect-selection', eagerly_expand))
if indirect_selection:
list_args.extend(('--indirect-selection', indirect_selection))
if selector_name:
list_args.extend(('--selector', selector_name))

Expand All @@ -38,7 +38,7 @@ def list_tests_and_assert(self, include, exclude, expected_tests, eagerly_expand
test_names = [name.split('.')[-1] for name in listed]
assert sorted(test_names) == sorted(expected_tests)

def run_tests_and_assert(self, include, exclude, expected_tests, eagerly_expand='eager', selector_name=None):
def run_tests_and_assert(self, include, exclude, expected_tests, indirect_selection='eager', selector_name=None):
results = self.run_dbt(['run'])
self.assertEqual(len(results), 2)

Expand All @@ -47,8 +47,8 @@ def run_tests_and_assert(self, include, exclude, expected_tests, eagerly_expand=
test_args.extend(('--models', include))
if exclude:
test_args.extend(('--exclude', exclude))
if eagerly_expand:
test_args.extend(('--indirect-selection', 'eager'))
if indirect_selection:
test_args.extend(('--indirect-selection', indirect_selection))
if selector_name:
test_args.extend(('--selector', selector_name))

Expand Down Expand Up @@ -156,22 +156,33 @@ def test__postgres__only_generic(self):
self.run_tests_and_assert(select, exclude, expected)

@use_profile('postgres')
def test__postgres__model_a_only_singular(self):
def test__postgres__model_a_only_singular_unset(self):
select = 'model_a,test_type:singular'
exclude = None
expected = ['cf_a_b','cf_a_src','just_a']

self.list_tests_and_assert(select, exclude, expected)
self.run_tests_and_assert(select, exclude, expected)

@use_profile('postgres')
def test__postgres__model_a_only_singular_eager(self):
select = 'model_a,test_type:singular'
exclude = None
expected = ['cf_a_b','cf_a_src','just_a']
indirect_selection = 'eager'

self.list_tests_and_assert(select, exclude, expected)
self.run_tests_and_assert(select, exclude, expected)

# TODO: add this as cautious @use_profile('postgres')
# def test__postgres__model_a_only_singular(self):
# select = 'model_a,test_type:singular'
# exclude = None
# expected = ['just_a']
@use_profile('postgres')
def test__postgres__model_a_only_singular_cautious(self):
select = 'model_a,test_type:singular'
exclude = None
expected = ['just_a']
indirect_selection = 'cautious'

# self.list_tests_and_assert(select, exclude, expected)
# self.run_tests_and_assert(select, exclude, expected)
self.list_tests_and_assert(select, exclude, expected, indirect_selection=indirect_selection)
self.run_tests_and_assert(select, exclude, expected, indirect_selection=indirect_selection)

@use_profile('postgres')
def test__postgres__only_singular(self):
Expand Down Expand Up @@ -258,7 +269,7 @@ def test__postgres__exclude_data_test_tag(self):
self.run_tests_and_assert(select, exclude, expected)

@use_profile('postgres')
def test__postgres__model_a_eagerly_expand(self):
def test__postgres__model_a_indirect_selection(self):
select = 'model_a'
exclude = None
expected = [
Expand All @@ -272,69 +283,69 @@ def test__postgres__model_a_eagerly_expand(self):
self.run_tests_and_assert(select, exclude, expected)

@use_profile('postgres')
def test__postgres__model_a_eagerly_expand_exclude_unique_tests(self):
def test__postgres__model_a_indirect_selection_exclude_unique_tests(self):
select = 'model_a'
exclude = 'test_name:unique'
eagerly_expand = 'eager'
indirect_selection = 'eager'
expected = [
'cf_a_b', 'cf_a_src', 'just_a',
'relationships_model_a_fun__fun__ref_model_b_',
'relationships_model_a_fun__fun__source_my_src_my_tbl_',
]

self.list_tests_and_assert(select, exclude, expected, eagerly_expand)
self.run_tests_and_assert(select, exclude, expected, eagerly_expand=eagerly_expand)
self.list_tests_and_assert(select, exclude, expected, indirect_selection)
self.run_tests_and_assert(select, exclude, expected, indirect_selection=indirect_selection)

class TestExpansionWithSelectors(TestSelectionExpansion):

@property
def selectors_config(self):
return yaml.safe_load('''
selectors:
- name: model_a_unset_eagerly_expand
- name: model_a_unset_indirect_selection
definition:
method: fqn
value: model_a
- name: model_a_no_eagerly_expand
- name: model_a_no_indirect_selection
definition:
method: fqn
value: model_a
eagerly_expand: "cautious"
- name: model_a_yes_eagerly_expand
indirect_selection: "cautious"
- name: model_a_yes_indirect_selection
definition:
method: fqn
value: model_a
eagerly_expand: "eager"
indirect_selection: "eager"
''')

@use_profile('postgres')
def test__postgres__selector_model_a_unset_eagerly_expand(self):
def test__postgres__selector_model_a_unset_indirect_selection(self):
expected = [
'cf_a_b', 'cf_a_src', 'just_a',
'relationships_model_a_fun__fun__ref_model_b_',
'relationships_model_a_fun__fun__source_my_src_my_tbl_',
'unique_model_a_fun'
]

self.list_tests_and_assert(include=None, exclude=None, expected_tests=expected, selector_name='model_a_unset_eagerly_expand')
self.run_tests_and_assert(include=None, exclude=None, expected_tests=expected, selector_name='model_a_unset_eagerly_expand')
self.list_tests_and_assert(include=None, exclude=None, expected_tests=expected, selector_name='model_a_unset_indirect_selection')
self.run_tests_and_assert(include=None, exclude=None, expected_tests=expected, selector_name='model_a_unset_indirect_selection')

@use_profile('postgres')
def test__postgres__selector_model_a_no_eagerly_expand(self):
def test__postgres__selector_model_a_no_indirect_selection(self):
expected = ['just_a','unique_model_a_fun']

self.list_tests_and_assert(include=None, exclude=None, expected_tests=expected, eagerly_expand='cautious', selector_name='model_a_no_eagerly_expand')
self.run_tests_and_assert(include=None, exclude=None, expected_tests=expected, eagerly_expand='cautious', selector_name='model_a_no_eagerly_expand')
self.list_tests_and_assert(include=None, exclude=None, expected_tests=expected, selector_name='model_a_no_indirect_selection')
self.run_tests_and_assert(include=None, exclude=None, expected_tests=expected, selector_name='model_a_no_indirect_selection')


@use_profile('postgres')
def test__postgres__selector_model_a_yes_eagerly_expand(self):
def test__postgres__selector_model_a_yes_indirect_selection(self):
expected = [
'cf_a_b', 'cf_a_src', 'just_a',
'relationships_model_a_fun__fun__ref_model_b_',
'relationships_model_a_fun__fun__source_my_src_my_tbl_',
'unique_model_a_fun'
]

self.list_tests_and_assert(include=None, exclude=None, expected_tests=expected, eagerly_expand='eager', selector_name='model_a_yes_eagerly_expand')
self.run_tests_and_assert(include=None, exclude=None, expected_tests=expected, eagerly_expand='eager', selector_name='model_a_yes_eagerly_expand')
self.list_tests_and_assert(include=None, exclude=None, expected_tests=expected, selector_name='model_a_yes_indirect_selection')
self.run_tests_and_assert(include=None, exclude=None, expected_tests=expected, selector_name='model_a_yes_indirect_selection')

0 comments on commit fa42880

Please sign in to comment.