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

Commit

Permalink
feat: add tests for arrays in YAML/JSON. Add new test data.
Browse files Browse the repository at this point in the history
  • Loading branch information
awgymer committed Dec 21, 2023
1 parent 0644b53 commit 90d2053
Show file tree
Hide file tree
Showing 7 changed files with 372 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,96 @@ class SamplesheetConverterTest extends Dsl2Spec{
stdout.contains("[[string1:extraField, string2:extraField, integer1:10, integer2:10, boolean1:true, boolean2:true], string1, 25, false, ${this.getRootString()}/src/testResources/test.txt, ${this.getRootString()}/src/testResources/testDir, ${this.getRootString()}/src/testResources/testDir, unique3, 1, itDoesExist]" as String)
}

def 'arrays should work fine - YAML' () {
given:
def SCRIPT_TEXT = '''
include { fromSamplesheet } from 'plugin/nf-validation'
params.input = 'src/testResources/correct_arrays.yaml'
workflow {
Channel.fromSamplesheet("input", parameters_schema:"src/testResources/nextflow_schema_with_samplesheet_converter_arrays.json").view()
}
'''

when:
dsl_eval(SCRIPT_TEXT)
def stdout = capture
.toString()
.readLines()
.findResults {it.startsWith('[[') ? it : null }

then:
noExceptionThrown()
stdout.contains("[[${this.getRootString()}/src/testResources/testDir/testFile.txt, ${this.getRootString()}/src/testResources/testDir2/testFile2.txt], [${this.getRootString()}/src/testResources/testDir, ${this.getRootString()}/src/testResources/testDir2], [${this.getRootString()}/src/testResources/testDir, ${this.getRootString()}/src/testResources/testDir2/testFile2.txt], [string1, string2], [25, 26], [25, 26.5], [false, true], [1, 2, 3], [true], [${this.getRootString()}/src/testResources/testDir/testFile.txt], [[${this.getRootString()}/src/testResources/testDir/testFile.txt]]]" as String)
stdout.contains("[[], [], [], [string1, string2], [25, 26], [25, 26.5], [], [1, 2, 3], [false, true, false], [${this.getRootString()}/src/testResources/testDir/testFile.txt], [[${this.getRootString()}/src/testResources/testDir/testFile.txt]]]" as String)
stdout.contains("[[], [], [], [string1, string2], [25, 26], [25, 26.5], [], [1, 2, 3], [false, true, false], [${this.getRootString()}/src/testResources/testDir/testFile.txt], [[${this.getRootString()}/src/testResources/testDir/testFile.txt], [${this.getRootString()}/src/testResources/testDir/testFile.txt, ${this.getRootString()}/src/testResources/testDir2/testFile2.txt]]]" as String)
}

def 'arrays should work fine - JSON' () {
given:
def SCRIPT_TEXT = '''
include { fromSamplesheet } from 'plugin/nf-validation'
params.input = 'src/testResources/correct_arrays.json'
workflow {
Channel.fromSamplesheet("input", parameters_schema:"src/testResources/nextflow_schema_with_samplesheet_converter_arrays.json").view()
}
'''

when:
dsl_eval(SCRIPT_TEXT)
def stdout = capture
.toString()
.readLines()
.findResults {it.startsWith('[[') ? it : null }

then:
noExceptionThrown()
stdout.contains("[[${this.getRootString()}/src/testResources/testDir/testFile.txt, ${this.getRootString()}/src/testResources/testDir2/testFile2.txt], [${this.getRootString()}/src/testResources/testDir, ${this.getRootString()}/src/testResources/testDir2], [${this.getRootString()}/src/testResources/testDir, ${this.getRootString()}/src/testResources/testDir2/testFile2.txt], [string1, string2], [25, 26], [25, 26.5], [false, true], [1, 2, 3], [true], [${this.getRootString()}/src/testResources/testDir/testFile.txt], [[${this.getRootString()}/src/testResources/testDir/testFile.txt]]]" as String)
stdout.contains("[[], [], [], [string1, string2], [25, 26], [25, 26.5], [], [1, 2, 3], [false, true, false], [${this.getRootString()}/src/testResources/testDir/testFile.txt], [[${this.getRootString()}/src/testResources/testDir/testFile.txt]]]" as String)
stdout.contains("[[], [], [], [string1, string2], [25, 26], [25, 26.5], [], [1, 2, 3], [false, true, false], [${this.getRootString()}/src/testResources/testDir/testFile.txt], [[${this.getRootString()}/src/testResources/testDir/testFile.txt], [${this.getRootString()}/src/testResources/testDir/testFile.txt, ${this.getRootString()}/src/testResources/testDir2/testFile2.txt]]]" as String)
}

def 'array errors before channel conversion - YAML' () {
given:
def SCRIPT_TEXT = '''
include { fromSamplesheet } from 'plugin/nf-validation'
params.input = 'src/testResources/error_arrays.yaml'
workflow {
Channel.fromSamplesheet("input", parameters_schema:"src/testResources/nextflow_schema_with_samplesheet_converter_arrays.json").view()
}
'''

when:
dsl_eval(SCRIPT_TEXT)
def stdout = capture
.toString()
.readLines()
.findResults {it.startsWith('[[') ? it : null }

then:
def error = thrown(SchemaValidationException)
def errorMessages = error.message.readLines()
errorMessages[0] == "\033[0;31mThe following errors have been detected:"
errorMessages[2] == "* -- Entry 1 - field_3: the file or directory 'src/testResources/testDir3' does not exist."
errorMessages[3] == "* -- Entry 1 - field_3: the file or directory 'src/testResources/testDir2/testFile3.txt' does not exist."
errorMessages[4] == "* -- Entry 1 - field_2: the file or directory 'src/testResources/testDir3' does not exist."
errorMessages[5] == "* -- Entry 1 - field_1: the file or directory 'src/testResources/testDir/testFile.fasta' does not exist."
errorMessages[6] == "* -- Entry 1 - field_1: the file or directory 'src/testResources/testDir2/testFile3.txt' does not exist."
errorMessages[7] == '* -- Entry 1 - field_4: array items are not unique (["string2","string2","string1"])'
errorMessages[8] == '* -- Entry 1 - field_1: string [src/testResources/testDir/testFile.fasta] does not match pattern ^.*\\.txt$ (["src/testResources/testDir/testFile.fasta","src/testResources/testDir2/testFile3.txt"])'
errorMessages[9] == "* -- Entry 1 - field_5: expected maximum item count: 3, found: 4 ([25,25,27,28])"
errorMessages[10] == "* -- Entry 1 - field_6: array items are not unique ([25,25])"
errorMessages[11] == "* -- Entry 2: Missing required value: field_4"
errorMessages[12] == "* -- Entry 2 - field_5: expected minimum item count: 2, found: 1 ([25])"
errorMessages[13] == "* -- Entry 3 - field_4: expected type: JSONArray, found: String (abc)"
!stdout
}

def 'no header - CSV' () {
given:
def SCRIPT_TEXT = '''
Expand Down
72 changes: 72 additions & 0 deletions plugins/nf-validation/src/testResources/correct_arrays.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
[
{
"field_1": [
"src/testResources/testDir/testFile.txt",
"src/testResources/testDir2/testFile2.txt"
],
"field_2": [
"src/testResources/testDir",
"src/testResources/testDir2"
],
"field_3": [
"src/testResources/testDir",
"src/testResources/testDir2/testFile2.txt"
],
"field_4": [
"string1",
"string2"
],
"field_5": [
25,
26
],
"field_6": [
25,
26.5
],
"field_7": [
false,
true
],
"field_9": [
true
]
},
{
"field_4": [
"string1",
"string2"
],
"field_5": [
25,
26
],
"field_6": [
25,
26.5
]
},
{
"field_4": [
"string1",
"string2"
],
"field_5": [
25,
26
],
"field_6": [
25,
26.5
],
"field_11": [
[
"src/testResources/testDir/testFile.txt"
],
[
"src/testResources/testDir/testFile.txt",
"src/testResources/testDir2/testFile2.txt"
]
]
}
]
45 changes: 45 additions & 0 deletions plugins/nf-validation/src/testResources/correct_arrays.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
- field_1:
- src/testResources/testDir/testFile.txt
- src/testResources/testDir2/testFile2.txt
field_2:
- src/testResources/testDir
- src/testResources/testDir2
field_3:
- src/testResources/testDir
- src/testResources/testDir2/testFile2.txt
field_4:
- string1
- string2
field_5:
- 25
- 26
field_6:
- 25
- 26.5
field_7:
- false
- true
field_9:
- true
- field_4:
- string1
- string2
field_5:
- 25
- 26
field_6:
- 25
- 26.5
- field_4:
- string1
- string2
field_5:
- 25
- 26
field_6:
- 25
- 26.5
field_11:
- - src/testResources/testDir/testFile.txt
- - src/testResources/testDir/testFile.txt
- src/testResources/testDir2/testFile2.txt
35 changes: 35 additions & 0 deletions plugins/nf-validation/src/testResources/error_arrays.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
- field_1:
- src/testResources/testDir/testFile.fasta
- src/testResources/testDir2/testFile3.txt
field_2:
- src/testResources/testDir
- src/testResources/testDir3
field_3:
- src/testResources/testDir3
- src/testResources/testDir2/testFile3.txt
field_4:
- string2
- string2
- string1
field_5:
- 25
- 25
- 27
- 28
field_6:
- 25
- 25.0
field_7:
- null
- true
field_9:
- true
- field_5:
- 25
field_6:
- 25
- 26.5
- field_4: 'abc'
field_6:
- 25
- 26.5
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"$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"],
"properties": {
"input": {
"type": "string",
"format": "file-path",
"mimetype": "text/csv",
"pattern": "^\\S+\\.csv$",
"schema": "src/testResources/schema_input_with_arrays.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"
}
}
}
}
}
102 changes: 102 additions & 0 deletions plugins/nf-validation/src/testResources/schema_input_with_arrays.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "https://raw.githubusercontent.com/nextflow-io/nf-validation/master/plugins/nf-validation/src/testResources/schema_input.json",
"title": "Samplesheet validation schema",
"description": "Schema for the samplesheet used in this pipeline",
"type": "array",
"items": {
"type": "object",
"properties": {
"field_1": {
"type": "array",
"items": {
"type": "string",
"format": "file-path",
"pattern": "^.*\\.txt$",
"exists": true
}
},
"field_2": {
"type": "array",
"items": {
"type": "string",
"format": "directory-path",
"exists": true
}
},
"field_3": {
"type": "array",
"items": {
"type": "string",
"format": "path",
"exists": true
}
},
"field_4": {
"type": "array",
"items": {
"type": "string"
},
"uniqueItems": true
},
"field_5": {
"type": "array",
"items": {
"type": "integer"
},
"minItems": 2,
"maxItems": 3
},
"field_6": {
"type": "array",
"items": {
"type": "number"
},
"uniqueItems": true
},
"field_7": {
"type": "array",
"items": {
"type": "boolean"
}
},
"field_8": {
"type": "array",
"items": {
"type": "string"
},
"default": ["1", "2", "3"]
},
"field_9": {
"type": "array",
"items": {
"type": "boolean"
},
"default": [false, true, false]
},
"field_10": {
"type": "array",
"items": {
"type": "string",
"format": "file-path",
"pattern": "^.*\\.txt$",
"exists": true
},
"default": ["src/testResources/testDir/testFile.txt"]
},
"field_11": {
"type": "array",
"items": {
"type": "array",
"items": {
"format": "file-path",
"pattern": "^.*\\.txt$",
"exists": true
}
},
"default": [["src/testResources/testDir/testFile.txt"]]
}
},
"required": ["field_4", "field_6"]
}
}
Empty file.

0 comments on commit 90d2053

Please sign in to comment.