Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #143 from awgymer/137-nf-validation-fails-when-num…
Browse files Browse the repository at this point in the history
…ber-parameters-are-set-to-0

Don't remove numeric 0 values from validation
  • Loading branch information
awgymer authored Dec 22, 2023
2 parents bcb92d8 + 46a47f1 commit dac66fa
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ class SchemaValidator extends PluginExtensionPoint {
def Map new_params = (Map) params.getClass().newInstance(params)
for (p in params) {
// remove anything evaluating to false
if (!p['value']) {
if (!p['value'] && p['value'] != 0) {
new_params.remove(p.key)
}
// Cast MemoryUnit to String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,57 @@ class PluginExtensionMethodsTest extends Dsl2Spec{
!stdout
}

def 'correct validation of numerics - 0' () {
given:
def schema = Path.of('src/testResources/nextflow_schema_required_numerics.json').toAbsolutePath().toString()
def SCRIPT_TEXT = """
params.monochrome_logs = true
params.input = 'src/testResources/correct.csv'
params.outdir = 'src/testResources/testDir'
params.integer = 0
params.number = 0
include { validateParameters } from 'plugin/nf-validation'
validateParameters(parameters_schema: '$schema', monochrome_logs: params.monochrome_logs)
"""

when:
dsl_eval(SCRIPT_TEXT)
def stdout = capture
.toString()
.readLines()
.findResults {it.contains('WARN nextflow.validation.SchemaValidator') || it.startsWith('* --') ? it : null }

then:
noExceptionThrown()
!stdout
}

def 'fail validation of numerics - null' () {
given:
def schema = Path.of('src/testResources/nextflow_schema_required_numerics.json').toAbsolutePath().toString()
def SCRIPT_TEXT = """
params.monochrome_logs = true
params.input = 'src/testResources/correct.csv'
params.outdir = 'src/testResources/testDir'
include { validateParameters } from 'plugin/nf-validation'
validateParameters(parameters_schema: '$schema', monochrome_logs: params.monochrome_logs)
"""

when:
dsl_eval(SCRIPT_TEXT)
def stdout = capture
.toString()
.readLines()
.findResults {it.contains('WARN nextflow.validation.SchemaValidator') || it.startsWith('* --') ? it : null }

then:
def error = thrown(SchemaValidationException)
error.message == "The following invalid input values have been detected:\n\n* Missing required parameter: --integer\n* Missing required parameter: --number\n\n"
!stdout
}

def 'correct validation of file-path-pattern - glob' () {
given:
def schema = Path.of('src/testResources/nextflow_schema_file_path_pattern.json').toAbsolutePath().toString()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "https://raw.githubusercontent.com/nf-core/testpipeline/master/nextflow_schema.json",
"title": "nf-core/testpipeline pipeline parameters",
"description": "this is a test",
"type": "object",
"definitions": {
"input_output_options": {
"title": "Input/output options",
"type": "object",
"fa_icon": "fas fa-terminal",
"description": "Define where the pipeline should find input data and save output data.",
"required": ["input", "outdir"],
"properties": {
"input": {
"type": "string",
"format": "file-path",
"mimetype": "text/csv",
"pattern": "^\\S+\\.(csv|tsv|yaml|json)$",
"description": "Path to comma-separated file containing information about the samples in the experiment.",
"help_text": "You will need to create a design file with information about the samples in your experiment before running the pipeline. Use this parameter to specify its location. It has to be a comma-separated file with 3 columns, and a header row. See [usage docs](https://nf-co.re/testpipeline/usage#samplesheet-input).",
"fa_icon": "fas fa-file-csv"
},
"outdir": {
"type": "string",
"format": "directory-path",
"description": "The output directory where the results will be saved. You have to use absolute paths to storage on Cloud infrastructure.",
"fa_icon": "fas fa-folder-open"
}
}
},
"numeric_options": {
"title": "Numeric pipeline options",
"type": "object",
"fa_icon": "fas fa-dna",
"description": "Numeric options to be tested",
"required": ["integer", "number"],
"properties": {
"integer": {
"type": "integer",
"description": "An integer parameter.",
"fa_icon": "fas fa-users-cog",
"help_text": "Integer value"
},
"number": {
"type": "number",
"description": "A number parameter.",
"fa_icon": "fas fa-users-cog",
"help_text": "Number value"
}
}
}
},
"allOf": [
{
"$ref": "#/definitions/input_output_options"
},
{
"$ref": "#/definitions/numeric_options"
}
]
}

0 comments on commit dac66fa

Please sign in to comment.