Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Sherman <bentshermann@gmail.com>
  • Loading branch information
bentsherman committed Dec 11, 2024
1 parent f2e675d commit 3de3275
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import java.nio.file.Path
import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import groovyx.gpars.dataflow.DataflowReadChannel
import nextflow.Global
import nextflow.Session
import nextflow.processor.PublishDir
import nextflow.util.CsvWriter
Expand All @@ -35,6 +34,8 @@ import nextflow.util.CsvWriter
@CompileStatic
class PublishOp {

private Session session

private DataflowReadChannel source

private Map opts
Expand All @@ -49,9 +50,8 @@ class PublishOp {

private volatile boolean complete

private Session getSession() { Global.session as Session }

PublishOp(DataflowReadChannel source, Map opts) {
PublishOp(Session session, DataflowReadChannel source, Map opts) {
this.session = session
this.source = source
this.opts = opts
this.path = opts.path as String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ abstract class BaseScript extends Script implements ExecutionContext {
final ret = entryFlow.invoke_a(BaseScriptConsts.EMPTY_ARGS)
if( !publisher )
publisher = new OutputDef()
publisher.run(session.publishTargets)
publisher.run(session)
session.notifyAfterWorkflowExecution()
return ret
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package nextflow.script
import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import groovyx.gpars.dataflow.DataflowWriteChannel
import nextflow.Session
/**
* Models the workflow output definition
*
Expand All @@ -38,7 +39,7 @@ class OutputDef {
this.closure = null
}

void run(Map<DataflowWriteChannel,String> targets) {
void run(Session session) {
final dsl = new OutputDsl()
if( closure ) {
final cl = (Closure)closure.clone()
Expand All @@ -47,7 +48,7 @@ class OutputDef {
cl.call()
}

dsl.build(targets)
dsl.build(session)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import java.nio.file.Path
import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import groovyx.gpars.dataflow.DataflowWriteChannel
import nextflow.Global
import nextflow.Session
import nextflow.exception.ScriptRuntimeException
import nextflow.extension.CH
Expand All @@ -37,8 +36,6 @@ import nextflow.file.FileHelper
@CompileStatic
class OutputDsl {

private Session session = Global.session as Session

private Map<String,Map> targetConfigs = [:]

private volatile List<PublishOp> ops = []
Expand All @@ -56,7 +53,8 @@ class OutputDsl {
targetConfigs[name] = dsl.getOptions()
}

void build(Map<DataflowWriteChannel,String> targets) {
void build(Session session) {
final targets = session.publishTargets
final defaults = session.config.navigate('workflow.output', Collections.emptyMap()) as Map

// construct mapping of target name -> source channels
Expand Down Expand Up @@ -86,7 +84,7 @@ class OutputDsl {
final opts = publishOptions(name, defaults, overrides)

if( opts.enabled == null || opts.enabled )
ops << new PublishOp(CH.getReadChannel(mixed), opts).apply()
ops << new PublishOp(session, CH.getReadChannel(mixed), opts).apply()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ class BaseScriptTest extends Dsl2Spec {
given:
def script = Files.createTempFile('test',null)
and:
def session = Mock(Session)
def session = Mock(Session) {
getPublishTargets() >> [:]
getConfig() >> [:]
}
def binding = new ScriptBinding([:])
def parser = new ScriptParser(session)

Expand Down Expand Up @@ -115,7 +118,10 @@ class BaseScriptTest extends Dsl2Spec {
def module = folder.resolve('module.nf')
def script = folder.resolve('main.nf')
and:
def session = Mock(Session)
def session = Mock(Session) {
getPublishTargets() >> [:]
getConfig() >> [:]
}
def binding = new ScriptBinding([:])
def parser = new ScriptParser(session)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class OutputDslTest extends Specification {
def file2 = work2.resolve('file2.txt'); file2.text = 'world'
and:
def session = Mock(Session) {
getPublishTargets() >> [:]
getConfig() >> [
workflow: [
output: [
Expand All @@ -47,10 +48,8 @@ class OutputDslTest extends Specification {
ch2.bind(file2)
ch2.bind(Channel.STOP)
and:
def targets = [
(ch1): 'foo',
(ch2): 'bar'
]
session.publishTargets.put(ch1, 'foo')
session.publishTargets.put(ch2, 'bar')
def dsl = new OutputDsl()
and:
SysEnv.push(NXF_FILE_ROOT: root.toString())
Expand All @@ -62,7 +61,7 @@ class OutputDslTest extends Specification {
path 'index.csv'
}
}
dsl.build(targets)
dsl.build(session)

def now = System.currentTimeMillis()
while( !dsl.complete ) {
Expand All @@ -74,13 +73,13 @@ class OutputDslTest extends Specification {
then:
outputDir.resolve('foo/file1.txt').text == 'Hello'
outputDir.resolve('barbar/file2.txt').text == 'world'
outputDir.resolve('barbar/index.csv').text == """\
outputDir.resolve('index.csv').text == """\
"file2","${outputDir}/barbar/file2.txt"
""".stripIndent()
and:
1 * session.notifyFilePublish(outputDir.resolve('foo/file1.txt'), file1)
1 * session.notifyFilePublish(outputDir.resolve('barbar/file2.txt'), file2)
1 * session.notifyFilePublish(outputDir.resolve('barbar/index.csv'))
1 * session.notifyFilePublish(outputDir.resolve('index.csv'))

cleanup:
SysEnv.pop()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class ParamsDsl2Test extends Dsl2Spec {
def 'should allow unqualified stdin and stdout' () {

given:
new Session()
def session = new Session()
and:
def config = new CompilerConfiguration()
config.setScriptBaseClass(BaseScript.class.name)
Expand All @@ -131,7 +131,7 @@ class ParamsDsl2Test extends Dsl2Spec {
'''

when:
def binding = new ScriptBinding().setSession(Mock(Session))
def binding = new ScriptBinding().setSession(session)
def script = (BaseScript)new GroovyShell(binding,config).parse(SCRIPT); script.run()
and:
def process = ScriptMeta.get(script).getProcess('alpha'); process.initialize()
Expand All @@ -151,7 +151,7 @@ class ParamsDsl2Test extends Dsl2Spec {
def 'should allow unqualified tuple stdin and stdout' () {

given:
new Session()
def session = new Session()
and:
def config = new CompilerConfiguration()
config.setScriptBaseClass(BaseScript.class.name)
Expand All @@ -172,7 +172,7 @@ class ParamsDsl2Test extends Dsl2Spec {
'''

when:
def binding = new ScriptBinding().setSession(Mock(Session))
def binding = new ScriptBinding().setSession(session)
def script = (BaseScript)new GroovyShell(binding,config).parse(SCRIPT); script.run()
and:
def process = ScriptMeta.get(script).getProcess('beta'); process.initialize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ class PublishOpS3Test extends BaseSpec {
getWorkDir() >> BASE
getBucketDir() >> BUCKET_DIR
}
Global.session = sess

def op = new PublishOp(Mock(DataflowReadChannel), [to:'/target'])
def op = new PublishOp(sess, Mock(DataflowReadChannel), [to:'/target'])

when:
def result = op.getTaskDir( BASE.resolve('xx/yyyy/this/and/that.txt') )
Expand Down

0 comments on commit 3de3275

Please sign in to comment.