Skip to content

Commit

Permalink
Reset, small fixes, test when no loading.
Browse files Browse the repository at this point in the history
  • Loading branch information
emarinier committed Feb 10, 2025
1 parent 307ca6d commit ff3d000
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ class IridaNextJSONOutput {
return this.instance
}

@Synchronized
public void reset() {
this.files = ["global": [], (SAMPLES): [:]]
this.metadata = [(SAMPLES): [:]]
this.scopeIds = [(SAMPLES): [] as Set<String>]
}

public void setMetadataPostProcessor(MetadataPostProcessor processor) {
this.metadataPostProcessor = processor
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import nextflow.Session
import nextflow.plugin.extension.Operator
import nextflow.plugin.extension.PluginExtensionPoint
import nextflow.iridanext.IridaNextJSONOutput
import groovy.util.logging.Slf4j


@Slf4j
class SamplesheetParser extends PluginExtensionPoint {
private String id_key

Expand All @@ -27,21 +28,21 @@ class SamplesheetParser extends PluginExtensionPoint {

final next = { it ->
def meta = it[0]
def id = meta[this.id_key]

if(meta instanceof Map<String,Object>)
{
if(meta.containsKey(this.id_key))
{
def id = meta[this.id_key]
iridaNextJSONOutput.addId(scope, id)
}
else {
throw new Exception("The expected key (${this.id_key}) was not found in the meta map.")
log.warn("The expected key (${this.id_key}) was not found in the meta map (${meta}).")
}

}
else {
throw new Exception("Expected a Map object in channel, but found ${meta}.")
log.warn("Expected a Map object in channel, but found ${meta}.")
}

target.bind(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ class SamplesheetParserTest extends Dsl2Spec {
.of([["id":"sample1"]], [["id":"sample2"]], [["id":"sample3"]])
.loadIridaSampleIds()
'''

final IridaNextJSONOutput iridaNextJSONOutput = IridaNextJSONOutput.getInstance()
iridaNextJSONOutput.reset() // Otherwise singleton class attributes persist across tests.

and:
def result = new MockScriptRunner([:]).setScript(SCRIPT).execute()
Expand Down Expand Up @@ -118,6 +119,7 @@ class SamplesheetParserTest extends Dsl2Spec {
'''

final IridaNextJSONOutput iridaNextJSONOutput = IridaNextJSONOutput.getInstance()
iridaNextJSONOutput.reset() // Otherwise singleton class attributes persist across tests.

and:
def result = new MockScriptRunner([:]).setScript(SCRIPT).execute()
Expand All @@ -128,4 +130,35 @@ class SamplesheetParserTest extends Dsl2Spec {
iridaNextJSONOutput.isValidId(iridaNextJSONOutput.SAMPLES, "sample3")
iridaNextJSONOutput.isValidId(iridaNextJSONOutput.SAMPLES, "sample4") == false
}
}

def 'Test no loadIridaSampleIds' () {
when:
def config = [
iridanext: [
enabled: true,
output: [
path: "/tmp/output/output.json.gz"
]
]
]
def session = Spy(Session) {
getConfig() >> config
}
def SCRIPT = '''
include { loadIridaSampleIds } from 'plugin/nf-iridanext'
channel.of([["id":"sample1"], "data1"], [["id":"sample2"], "data2"], [["id":"sample3"], "data3"])
'''

final IridaNextJSONOutput iridaNextJSONOutput = IridaNextJSONOutput.getInstance()
iridaNextJSONOutput.reset() // Otherwise singleton class attributes persist across tests.

and:
def result = new MockScriptRunner([:]).setScript(SCRIPT).execute()

then:
iridaNextJSONOutput.isValidId(iridaNextJSONOutput.SAMPLES, "sample1") == false
iridaNextJSONOutput.isValidId(iridaNextJSONOutput.SAMPLES, "sample2") == false
iridaNextJSONOutput.isValidId(iridaNextJSONOutput.SAMPLES, "sample3") == false
iridaNextJSONOutput.isValidId(iridaNextJSONOutput.SAMPLES, "sample4") == false
}
}

0 comments on commit ff3d000

Please sign in to comment.