Skip to content

Commit

Permalink
Fixed up structure of returned empty tables
Browse files Browse the repository at this point in the history
  • Loading branch information
apetkau committed Jun 3, 2024
1 parent ef1aa49 commit 0e85c66
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
7 changes: 4 additions & 3 deletions modules/local/report.nf
Original file line number Diff line number Diff line change
Expand Up @@ -813,8 +813,8 @@ def table_values(file_path, header_p, seperator, headers=null){
} else if (!header_p) {
if (file_lines.size() == 0) {
// headers were not in the file, and file size is 0, so return missing data based
// on passed headers
rows_list = headers.collectEntries { [(it): null] }
// on passed headers (i.e., single row of empty values)
rows_list = [headers.collectEntries { [(it): null] }]
} else {
// verify that passed headers and rows have same number
def row_line = file_lines[0].replaceAll('(\n|\r\n)$', '')
Expand Down Expand Up @@ -846,7 +846,8 @@ def table_values(file_path, header_p, seperator, headers=null){

if (file_lines.size() == 1) {
// There is no row lines, only headers, so return missing data
rows_list = headers_from_file.collectEntries { [(it): null] }
// (single row of empty values)
rows_list = [headers_from_file.collectEntries { [(it): null] }]
} else {
// If there exists a row line, then make sure rows + headers match

Expand Down
23 changes: 23 additions & 0 deletions tests/functions/report.nf.test
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ nextflow_function {
}

test("Test empty file"){
tag "test_empty"

when {
function {
Expand All @@ -223,9 +224,31 @@ nextflow_function {
}
then{
assert function.failed
assert function.stdout.any { it.contains("ERROR ~ Attempting to parse empty file") }
}
}

test("Test empty file pass header"){
tag "test_empty_pass_header"

when {
function {
"""
input[0] = file("$baseDir/tests/data/tables/empty.csv")
input[1] = false
input[2] = ','
input[3] = ['header1', 'header2']
"""
}
params {
outdir = "results"
}
}
then{
assert function.success
assert function.result == ['0':['header1':'NoData', 'header2':'NoData']]
}
}

test("Test more values than columns"){

Expand Down

0 comments on commit 0e85c66

Please sign in to comment.