Skip to content

Commit

Permalink
Update names and styling to fit test requirements. Add default value …
Browse files Browse the repository at this point in the history
…for option.
  • Loading branch information
VersusFacit committed Oct 27, 2021
1 parent d347fb8 commit f2b6e65
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
2 changes: 1 addition & 1 deletion core/dbt/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def set_from_args(args, user_config):
# cli args without user_config or env var option
FULL_REFRESH = getattr(args, 'full_refresh', FULL_REFRESH)
STORE_FAILURES = getattr(args, 'store_failures', STORE_FAILURES)
EAGER_INDIRECT_SELECTION = getattr(args, 'indirect_selection') != 'cautious'
EAGER_INDIRECT_SELECTION = getattr(args, 'indirect_selection', 'eager') != 'cautious'
WHICH = getattr(args, 'which', WHICH)

# global cli flags with env var and user_config alternatives
Expand Down
6 changes: 5 additions & 1 deletion core/dbt/graph/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ def parse_union_from_default(
def parse_difference(
include: Optional[List[str]], exclude: Optional[List[str]]
) -> SelectionDifference:
included = parse_union_from_default(include, DEFAULT_INCLUDES, eagerly_expand=flags.EAGER_INDIRECT_SELECTION)
included = parse_union_from_default(
include,
DEFAULT_INCLUDES,
eagerly_expand=flags.EAGER_INDIRECT_SELECTION
)
excluded = parse_union_from_default(exclude, DEFAULT_EXCLUDES, eagerly_expand=True)
return SelectionDifference(components=[included, excluded])

Expand Down
6 changes: 5 additions & 1 deletion core/dbt/graph/selector_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,11 @@ def from_single_spec(cls, raw: str, eagerly_expand: bool = True) -> 'SelectionCr
# bad spec!
raise RuntimeException(f'Invalid selector spec "{raw}"')

return cls.selection_criteria_from_dict(raw, result.groupdict(), eagerly_expand=eagerly_expand)
return cls.selection_criteria_from_dict(
raw,
result.groupdict(),
eagerly_expand=eagerly_expand
)


class BaseSelectionGroup(Iterable[SelectionSpec], metaclass=ABCMeta):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@ def project_config(self):
"test-paths": ["tests"]
}

def list_tests_and_assert(self, include, exclude, expected_tests, eagerly_expand=True, selector_name=None):
def list_tests_and_assert(self, include, exclude, expected_tests, eagerly_expand='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 exclude:
list_args.extend(('--exclude', exclude))
if eagerly_expand:
list_args.extend('--indirect-selection', 'eager')
list_args.extend(('--indirect-selection', eagerly_expand))
if selector_name:
list_args.extend(('--selector', selector_name))

Expand All @@ -40,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=True, selector_name=None):
def run_tests_and_assert(self, include, exclude, expected_tests, eagerly_expand='eager', selector_name=None):
results = self.run_dbt(['run'])
self.assertEqual(len(results), 2)

Expand All @@ -50,7 +48,7 @@ def run_tests_and_assert(self, include, exclude, expected_tests, eagerly_expand=
if exclude:
test_args.extend(('--exclude', exclude))
if eagerly_expand:
test_args.append('--indirect-selection', 'eager')
test_args.append(('--indirect-selection', 'eager'))
if selector_name:
test_args.extend(('--selector', selector_name))

Expand Down Expand Up @@ -248,7 +246,7 @@ def test__postgres__model_a_eagerly_expand(self):
def test__postgres__model_a_eagerly_expand_exclude_unique_tests(self):
select = 'model_a'
exclude = 'test_name:unique'
eagerly_expand = True
eagerly_expand = 'eager'
expected = [
'cf_a_b', 'cf_a_src', 'just_a',
'relationships_model_a_fun__fun__ref_model_b_',
Expand All @@ -264,20 +262,20 @@ class TestExpansionWithSelectors(TestSelectionExpansion):
def selectors_config(self):
return yaml.safe_load('''
selectors:
- name: model_a_eagerly_expand_unspecified
- name: model_a_unset_eagerly_expand
definition:
method: fqn
value: model_a
- name: model_a_eagerly_expand_false
- name: model_a_no_eagerly_expand
definition:
method: fqn
value: model_a
eagerly_expand: false
- name: model_a_eagerly_expand_true
eagerly_expand: "cautious"
- name: model_a_yes_eagerly_expand
definition:
method: fqn
value: model_a
eagerly_expand: true
eagerly_expand: "eager"
''')

@use_profile('postgres')
Expand All @@ -289,15 +287,15 @@ def test__postgres__selector_model_a_unset_eagerly_expand(self):
'unique_model_a_fun'
]

self.list_tests_and_assert(include=None, exclude=None, expected_tests=expected, selector_name='model_a_eagerly_expand_unspecified')
self.run_tests_and_assert(include=None, exclude=None, expected_tests=expected, selector_name='model_a_eagerly_expand_unspecified')
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')

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

self.list_tests_and_assert(include=None, exclude=None, expected_tests=expected, eagerly_expand=False, selector_name='model_a_eagerly_expand_false')
self.run_tests_and_assert(include=None, exclude=None, expected_tests=expected, eagerly_expand=False, selector_name='model_a_eagerly_expand_false')
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')


@use_profile('postgres')
Expand All @@ -309,5 +307,5 @@ def test__postgres__selector_model_a_yes_eagerly_expand(self):
'unique_model_a_fun'
]

self.list_tests_and_assert(include=None, exclude=None, expected_tests=expected, eagerly_expand=True, selector_name='model_a_eagerly_expand_true')
self.run_tests_and_assert(include=None, exclude=None, expected_tests=expected, eagerly_expand=True, selector_name='model_a_eagerly_expand_true')
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')

0 comments on commit f2b6e65

Please sign in to comment.