Skip to content

Commit

Permalink
fix: nested declarative hook nested method call
Browse files Browse the repository at this point in the history
  • Loading branch information
robcxyz committed Aug 22, 2022
1 parent 94fc9e9 commit d9cbf11
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tackle/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ def get_hook(hook_type, context: 'Context') -> Type[BaseHook]:
path=h.hooks_path,
)
h = context.provider_hooks[hook_type]
# TODO: Refactor this whole function so this is not repeated
# Make it so hook is split right away and evaluated in one loop
elif isinstance(h, LazyBaseFunction):
h = create_function_model(
context=context,
func_name=hook_type,
func_dict=h.function_dict.copy(),
)

return h

Expand Down
41 changes: 41 additions & 0 deletions tests/parser/functions/fixtures/method-nested-override.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

method_overlap<-:
home:
default: baz

call<-:
home:
type: str

out<-:
home: earth

method_overlap_jinja->: "{{method_overlap.call.out()}}"
method_overlap_compact->: method_overlap.call.out --home foo

attribute_override<-:
home:
default: bar

call<-:
home:
default: baz

out<-:
home:
default: bing

attribute_override_jinja->: "{{attribute_override.call.out()}}"
attribute_override_compact->: attribute_override.call.out

nested<-:
home:
default: bar

call<-:
out<-:
home:
default: baz

nested_jinja->: "{{nested.call.out()}}"
nexted_compact->: nested.call.out
14 changes: 14 additions & 0 deletions tests/parser/functions/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,20 @@ def test_function_method_nested(change_curdir_fixtures):
assert output['jinja_method_home'] == output['t_home']


def test_function_method_override(change_curdir_fixtures):
"""
Check that when we call methods that attributes are properly overridden if they
exist in the base.
"""
output = tackle('method-nested-override.yaml')
assert output['method_overlap_jinja']['home'] == 'earth'
assert output['method_overlap_compact']['home'] == 'foo'
assert output['attribute_override_jinja']['home'] == 'bing'
assert output['attribute_override_compact']['home'] == 'bing'
assert output['nested_jinja']['home'] == 'baz'
assert output['nexted_compact']['home'] == 'baz'


def test_function_import_func_from_hooks_dir(change_dir):
"""Assert that we can call functions from local hooks dir."""
os.chdir(os.path.join('fixtures', 'func-provider'))
Expand Down

0 comments on commit d9cbf11

Please sign in to comment.