Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix enabled for parent options #11707

Merged
merged 1 commit into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,11 @@ def write_option(option, writer, indent='', start_list=False):
multiple = option['multiple']
multiple_instances_defined = option.get('multiple_instances_defined')

writer.write(indent, option_name, ':', '\n')
if not option_enabled(option):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't it be true by default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems for the other non-nested options that if the option is not explicitly enabled, it is commented out: options with a value option and sections with an example option

writer.write(indent, '# ', option_name, ':', '\n')
else:
writer.write(indent, option_name, ':', '\n')

if multiple and multiple_instances_defined:
for instance in option['options']:
write_sub_option(instance, writer, indent, multiple, include_top_description=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
name: init_config
enabled: true
description: |
All options defined here are available to all instances.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: instances
multiple: true
enabled: true
description: |
Every instance is scheduled independent of the others.
Original file line number Diff line number Diff line change
Expand Up @@ -1584,3 +1584,133 @@ def test_option_multiple_instances_defined():
# bar: <BAR>
"""
)


def test_parent_option_disabled():
consumer = get_example_consumer(
"""
name: foo
version: 0.0.0
files:
- name: test.yaml
example_name: test.yaml.example
options:
- template: instances
options:
- name: enabled_option
required: true
description: Description of enabled option
value:
type: boolean
example: true
- name: parent_option
description: Description of parent option
options:
- name: sub_option_1
description: words
value:
type: boolean
example: true
- name: sub_option_2
description: words
value:
type: string
example: foo.bar_none
"""
)

files = consumer.render()
contents, errors = files['test.yaml.example']
assert not errors
assert contents == normalize_yaml(
"""
## Every instance is scheduled independent of the others.
#
instances:

## @param enabled_option - boolean - required
## Description of enabled option
#
- enabled_option: true

## Description of parent option
#
# parent_option:

## @param sub_option_1 - boolean - optional - default: true
## words
#
# sub_option_1: true

## @param sub_option_2 - string - optional - default: foo.bar_none
## words
#
# sub_option_2: foo.bar_none
"""
)


def test_parent_option_enabled():
consumer = get_example_consumer(
"""
name: foo
version: 0.0.0
files:
- name: test.yaml
example_name: test.yaml.example
options:
- template: instances
options:
- name: enabled_option
required: true
description: Description of enabled option
value:
type: boolean
example: true
- name: parent_option
enabled: true
description: Description of parent option
options:
- name: enabled_sub_option
enabled: true
description: words
value:
type: boolean
example: true
- name: disabled_sub_option
description: words
value:
type: string
example: foo.bar_none
"""
)

files = consumer.render()
contents, errors = files['test.yaml.example']
assert not errors
assert contents == normalize_yaml(
"""
## Every instance is scheduled independent of the others.
#
instances:

## @param enabled_option - boolean - required
## Description of enabled option
#
- enabled_option: true

## Description of parent option
#
parent_option:

## @param enabled_sub_option - boolean - optional - default: true
## words
#
enabled_sub_option: true

## @param disabled_sub_option - string - optional - default: foo.bar_none
## words
#
# disabled_sub_option: foo.bar_none
"""
)