-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Parameter application logic #31998
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
Draft
dschwen
wants to merge
3
commits into
idaholab:next
Choose a base branch
from
dschwen:parameter-application-logic
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Parameter application logic #31998
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,7 +56,19 @@ def parse(self, filename, default_values = None): | |
| self.root = root(0) # make the [Tests] block the root | ||
|
|
||
| self.check() | ||
| self._parseNode(filename, self.root, default_values) | ||
|
|
||
| # Convert any provided default values (from the testroot file) into a | ||
| # simple dictionary so that we can merge values without relying on | ||
| # pyhit.Node's type conversion rules. | ||
| if default_values is not None: | ||
| if isinstance(default_values, dict): | ||
| defaults = default_values | ||
| else: | ||
| defaults = {k: v for k, v in default_values.params()} | ||
| else: | ||
| defaults = {} | ||
|
|
||
| self._parseNode(filename, self.root, defaults) | ||
|
|
||
| def check(self): | ||
| """Perform error checking on the loaded hit tree""" | ||
|
|
@@ -143,6 +155,19 @@ def checkParams(self, params, node): | |
| # private: | ||
| def _parseNode(self, filename, node, default_values): | ||
|
|
||
| # Build a new set of default values for any child blocks by combining | ||
| # the inherited defaults with parameters defined on this node. This | ||
| # allows values supplied in the [Tests] block to propagate to every | ||
| # test contained within it. | ||
| child_defaults = dict(default_values) if default_values is not None else {} | ||
| for key, value in node.params(): | ||
| if key == 'type': | ||
| continue | ||
| if key == 'cli_args' and key in child_defaults: | ||
| child_defaults[key] = child_defaults[key] + ' ' + value | ||
| else: | ||
| child_defaults[key] = value | ||
|
|
||
| if 'type' in node: | ||
| moose_type = node['type'] | ||
|
|
||
|
|
@@ -153,12 +178,20 @@ def _parseNode(self, filename, node, default_values): | |
| params.addParam('hit_path', node.fullpath, 'HIT path to test in spec file') | ||
|
|
||
| # Apply any new defaults | ||
| for key, value in default_values.params(): | ||
| for key, value in default_values.items(): | ||
| if key in params.keys(): | ||
| if key == 'cli_args': | ||
| params[key].append(value) | ||
| params[key].append(value) | ||
| elif params.type(key) == list: | ||
| if isinstance(value, str): | ||
| value = value.replace('\n', ' ') | ||
| params[key] = re.split(r'\s+', value) | ||
| elif isinstance(value, (list, tuple)): | ||
| params[key] = list(value) | ||
| else: | ||
| params[key] = [str(value)] | ||
|
Comment on lines
+186
to
+192
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this now needed? |
||
| else: | ||
| params[key] = value | ||
| params[key] = value | ||
|
|
||
| # Extract the parameters from the hit node | ||
| self.extractParams(params, node) | ||
|
|
@@ -201,9 +234,11 @@ def _parseNode(self, filename, node, default_values): | |
| elif node.parent.fullpath == 'Tests' and self._check_for_type and not self._looksLikeValidSubBlock(node): | ||
| self.error('missing "type" parameter in block "{}"'.format(node.fullpath), node=node) | ||
|
|
||
| # Loop over the section names and parse them | ||
| # Loop over the section names and parse them using the newly | ||
| # constructed defaults which include any parameters defined at this | ||
| # level. | ||
| for child in node: | ||
| self._parseNode(filename, child, default_values) | ||
| self._parseNode(filename, child, child_defaults) | ||
|
|
||
| # This routine returns a Boolean indicating whether a given block | ||
| # looks like a valid subblock. In the Testing system, a valid subblock | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| #* This file is part of the MOOSE framework | ||
| #* https://mooseframework.inl.gov | ||
| #* | ||
| #* All rights reserved, see COPYRIGHT for full restrictions | ||
| #* https://github.com/idaholab/moose/blob/master/COPYRIGHT | ||
| #* | ||
| #* Licensed under LGPL 2.1, please see LICENSE for details | ||
| #* https://www.gnu.org/licenses/lgpl-2.1.html | ||
|
|
||
| from TestHarnessTestCase import TestHarnessTestCase | ||
|
|
||
| class TestHarnessTester(TestHarnessTestCase): | ||
| def testGlobalCapabilitiesPropagated(self): | ||
| result = self.runTests('-i', 'global_capabilities', '--dry-run') | ||
| test_results = result.results['tests']['tests/test_harness']['tests']['always_ok'] | ||
| self.assertEqual(test_results['capabilities'], 'foo') | ||
|
|
||
| def testGlobalPrereqPropagated(self): | ||
| result = self.runTests('-i', 'global_prereq', '--dry-run') | ||
| test_results = result.results['tests']['tests/test_harness']['tests']['parent']['tests']['child'] | ||
| self.assertEqual(test_results['prereq'], ['pre']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| [Tests] | ||
| capabilities = 'foo' | ||
| [./always_ok] | ||
| type = RunApp | ||
| input = good.i | ||
| [../] | ||
| [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| [Tests] | ||
| [parent] | ||
| prereq = pre | ||
| [pre] | ||
| type = RunCommand | ||
| command = 'true' | ||
| [] | ||
| [child] | ||
| type = RunCommand | ||
| command = 'true' | ||
| [] | ||
| [] | ||
| [] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when would this be a dict and when would it not be?