Repository navigation
Cast the command line values of nested parameters #234
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
Merged
pinin4fjords
merged 3 commits into
nextflow-io:master
from
pinin4fjords:fix/nested-cli-cast
Oct 5, 2026
Merged
Changes from 1 commit
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
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
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
74 changes: 74 additions & 0 deletions
74
src/test/groovy/nextflow/validation/ValidateCliParamsTest.groovy
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,74 @@ | ||
| /* groovylint-disable LineLength, MethodName */ | ||
| package nextflow.validation | ||
|
|
||
| import groovy.transform.CompileDynamic | ||
| import nextflow.Session | ||
| import nextflow.validation.config.ValidationConfig | ||
| import nextflow.validation.exceptions.SchemaValidationException | ||
| import nextflow.validation.parameters.ParameterValidator | ||
| import spock.lang.Specification | ||
|
|
||
| import java.nio.file.Path | ||
|
|
||
| /** | ||
| * Validation of the values given on the command line, which are cast to the type they have. | ||
| * The session is mocked so that the command line params can be set directly. | ||
| */ | ||
| @CompileDynamic | ||
| class ValidateCliParamsTest extends Specification { | ||
|
|
||
| private static final String SCHEMA = 'src/testResources/nextflow_schema_nested_parameters.json' | ||
|
|
||
| void 'should accept a nested value given on the command line'() { | ||
| given: | ||
| Session session = mockSession([map: [is: [so: [deep: 'true']]]], [map: [is: [so: [deep: 'true']]]]) | ||
|
|
||
| when: | ||
| validate(session) | ||
|
|
||
| then: | ||
| noExceptionThrown() | ||
| } | ||
|
|
||
| void 'should reject a nested value given on the command line that is not of the type of the schema'() { | ||
| given: | ||
| Session session = mockSession([map: [is: [so: [deep: 'maybe']]]], [map: [is: [so: [deep: 'maybe']]]]) | ||
|
|
||
| when: | ||
| validate(session) | ||
|
|
||
| then: | ||
| SchemaValidationException error = thrown(SchemaValidationException) | ||
| error.message.contains('--map.is.so.deep (maybe): Value is [string] but should be [boolean]') | ||
| } | ||
|
|
||
| void 'should not cast a nested value that was not given on the command line'() { | ||
| given: | ||
| Session session = mockSession([map: [is: [so: [deep: 'true']]]], [:]) | ||
|
|
||
| when: | ||
| validate(session) | ||
|
|
||
| then: | ||
| SchemaValidationException error = thrown(SchemaValidationException) | ||
| error.message.contains('--map.is.so.deep (true): Value is [string] but should be [boolean]') | ||
| } | ||
|
|
||
| private Session mockSession(Map params, Map cliParams) { | ||
| Session session = Mock(Session) | ||
| session.params >> params | ||
| session.cliParams >> cliParams | ||
| session.config >> [params: params] | ||
| session.baseDir >> Path.of('.').toAbsolutePath() | ||
| return session | ||
| } | ||
|
|
||
| private void validate(Session session) { | ||
| ValidationConfig config = new ValidationConfig([monochromeLogs: true], session) | ||
| new ParameterValidator(config).validateParametersMap( | ||
| [parameters_schema: Path.of(SCHEMA).toAbsolutePath().toString(), cast_cli_params: true], | ||
| session | ||
| ) | ||
| } | ||
|
|
||
| } |
47 changes: 47 additions & 0 deletions
47
src/test/groovy/nextflow/validation/utils/TypesTest.groovy
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,47 @@ | ||
| /* groovylint-disable LineLength, MethodName */ | ||
| package nextflow.validation.utils | ||
|
|
||
| import static nextflow.validation.utils.Types.castCliValues | ||
|
|
||
| import groovy.transform.CompileDynamic | ||
| import spock.lang.Specification | ||
|
|
||
| /** | ||
| * Casting of the values given on the command line. | ||
| */ | ||
| @CompileDynamic | ||
| class TypesTest extends Specification { | ||
|
|
||
| void 'should cast the values given on the command line'() { | ||
| expect: | ||
| castCliValues(params, cliParams) == expected | ||
|
|
||
| where: | ||
| params | cliParams | expected | ||
| [flag: 'true', count: '3'] | [flag: 'true', count: '3'] | [flag: true, count: 3] | ||
| [ratio: '0.5', name: 'abc'] | [ratio: '0.5', name: 'abc'] | [ratio: 0.5, name: 'abc'] | ||
| [flag: 'true'] | [:] | [flag: 'true'] | ||
| [flag: 'true'] | null | [flag: 'true'] | ||
| [flag: 'true', other: 'false'] | [flag: 'true'] | [flag: true, other: 'false'] | ||
| [flag: true, count: 3] | [flag: 'true', count: '3'] | [flag: true, count: 3] | ||
| } | ||
|
|
||
| void 'should cast the nested values given on the command line'() { | ||
| expect: | ||
| castCliValues(params, cliParams) == expected | ||
|
|
||
| where: | ||
| params | cliParams | expected | ||
| [group: [flag: 'true', count: '3']] | [group: [flag: 'true', count: '3']] | [group: [flag: true, count: 3]] | ||
| [group: [flag: 'true', other: 'false']] | [group: [flag: 'true']] | [group: [flag: true, other: 'false']] | ||
| [group: [is: [so: [deep: 'true']]]] | [group: [is: [so: [deep: 'true']]]] | [group: [is: [so: [deep: true]]]] | ||
| [group: [flag: 'true']] | [:] | [group: [flag: 'true']] | ||
| [group: [flag: 'true']] | [other: 'true'] | [group: [flag: 'true']] | ||
| } | ||
|
|
||
| void 'should not cast a nested value with the name of a top-level command line parameter'() { | ||
| expect: | ||
| castCliValues([flag: 'true', group: [flag: 'true']], [flag: 'true']) == [flag: true, group: [flag: 'true']] | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.