Skip to content

Commit

Permalink
Merge branch 'main' into fixes/gzip-check
Browse files Browse the repository at this point in the history
  • Loading branch information
lukfor authored Jan 30, 2024
2 parents bcf59e0 + 17ffed3 commit b9e87f8
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 11 deletions.
69 changes: 69 additions & 0 deletions docs/docs/testcases/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ run("WorkflowName") {
}
```

If you need to run the same process multiple times, you can set the alias of the process:

```groovy
run("GENERATE_DATA", alias: "MY_PROCESS") {
script "./generate_data.nf"
process {
...
}
}
```

!!! warning

Please keep in mind that changes in procsses or workflows, which are executed in the setup method, can result in a failed test run.
Expand Down Expand Up @@ -153,3 +164,61 @@ nextflow_process {
}
```
### 3. Aliasing of Dependencies

In this example, the process `UNTAR` is used multiple times in the setup method:

```groovy
nextflow_process {
...
setup {
run("UNTAR", alias: "UNTAR1") {
script "modules/nf-core/untar/main.nf"
process {
"""
input[0] = Channel.fromList(...)
"""
}
}
run("UNTAR", alias: "UNTAR2") {
script "modules/nf-core/untar/main.nf"
process {
"""
input[0] = Channel.fromList(...)
"""
}
}
run("UNTAR", alias: "UNTAR3") {
script "modules/nf-core/untar/main.nf"
process {
"""
input[0] = Channel.fromList(...)
"""
}
}
}
test("Test with three different inputs") {
when {
process {
"""
input[0] = UNTAR1.out.untar.map{ it[1] }
input[1] = UNTAR2.out.untar.map{ it[1] }
input[2] = UNTAR3.out.untar.map{ it[1] }
"""
}
}
then {
...
}
}
}
```
23 changes: 22 additions & 1 deletion src/main/java/com/askimed/nf/test/lang/Dependency.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,25 @@

import groovy.lang.Closure;

import java.util.Map;

public class Dependency {

private String script;

private String name;

private String alias;

private String mapping;

public Dependency(String name, Closure closure) {
public static final String ATTRIBUTE_ALIAS = "alias";

public Dependency(String name, Map<String, Object> attributes, Closure closure) {
this.name = name;
if (attributes.containsKey(ATTRIBUTE_ALIAS)) {
this.alias = attributes.get(ATTRIBUTE_ALIAS).toString();
}
closure.setDelegate(this);
closure.setResolveStrategy(Closure.DELEGATE_FIRST);
closure.call();
Expand Down Expand Up @@ -54,6 +63,18 @@ public void setName(String name) {
this.name = name;
}

public String getAlias() {
return alias;
}

public void setAlias(String alias) {
this.alias = alias;
}

public boolean hasAlias() {
return alias != null;
}

public String getMapping() {
return mapping;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public Object convert(Object value, String key) {
if (!path.toFile().exists()) {
throw new RuntimeException("Path " + path.toString() + " not found.");
}
} else if (value instanceof File) {
path = ((File) value).toPath();
if (!path.toFile().exists()) {
throw new RuntimeException("Path " + path.toString() + " not found.");
}
} else {
path = new File(value.toString()).toPath();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.askimed.nf.test.lang.process;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;

import com.askimed.nf.test.core.ITest;
Expand Down Expand Up @@ -50,11 +52,15 @@ public void evaluateProcessClosure() {

}

public void run(String process, Closure closure) {
Dependency dependency = new Dependency(process, closure);
public void run(Map<String, Object> attributes, String process, Closure closure) {
Dependency dependency = new Dependency(process, attributes, closure);
dependencies.add(dependency);
}

public void run(String process, Closure closure) {
run(new LinkedHashMap<String, Object>(), process, closure);
}

public List<Dependency> getDependencies() {
return dependencies;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.askimed.nf.test.lang.workflow;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;

import com.askimed.nf.test.core.ITest;
Expand Down Expand Up @@ -46,11 +48,15 @@ public void setWorkflow(Workflow workflow) {
this.workflow = workflow;
}

public void run(String process, Closure closure) {
Dependency dependency = new Dependency(process, closure);
public void run(Map<String, Object> attributes, String process, Closure closure) {
Dependency dependency = new Dependency(process, attributes, closure);
dependencies.add(dependency);
}

public void run(String process, Closure closure) {
run(new LinkedHashMap<String, Object>(), process, closure);
}

public List<Dependency> getDependencies() {
return dependencies;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ params.nf_test_output = ""

// include dependencies
<% for (dependency in dependencies) { %>
include { ${dependency.name} } from '${dependency.script}'
include { ${dependency.name} ${dependency.hasAlias() ? " as " + dependency.alias : "" } } from '${dependency.script}'
<% } %>

// include test process
Expand All @@ -29,7 +29,7 @@ workflow {
{
def input = []
${dependency.mapping}
${dependency.name}(*input)
${dependency.hasAlias() ? dependency.alias : dependency.name}(*input)
}
<% } %>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ params.nf_test_output = ""

// include dependencies
<% for (dependency in dependencies) { %>
include { ${dependency.name} } from '${dependency.script}'
include { ${dependency.name} ${dependency.hasAlias() ? " as " + dependency.alias : "" } } from '${dependency.script}'
<% } %>

// include test workflow
Expand All @@ -29,7 +29,7 @@ workflow {
{
def input = []
${dependency.mapping}
${dependency.name}(*input)
${dependency.hasAlias() ? dependency.alias : dependency.name}(*input)
}
<% } %>

Expand Down
12 changes: 10 additions & 2 deletions src/test/java/com/askimed/nf/test/lang/ProcessTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,17 @@ public void testScriptWithRelativePathInSubfolder() throws Exception {
public void testDependencies() throws Exception {

App app = new App();
int exitCode = app.run(new String[] { "test", "test-data/process/dependencies/process_data.nf.test" });
int exitCode = app.run(new String[] { "test", "test-data/process/dependencies/process_data.nf.test", "--verbose" });

}
}

@Test
public void testDependenciesWithAlias() throws Exception {

App app = new App();
int exitCode = app.run(new String[] { "test", "test-data/process/dependencies/process_data_alias.nf.test", "--verbose" });

}

@Test
public void testDependenciesAbricate() throws Exception {
Expand Down
36 changes: 36 additions & 0 deletions test-data/process/dependencies/process_data_alias.nf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
nextflow_process {

name "Test process data"

script "./process_data.nf"
process "PROCESS_DATA"

test("Should use process GENERATE_DATA with alias PROCESS_ALIAS to generate input data") {

setup {
run("GENERATE_DATA", alias: "LUKAS") {
script "./generate_data.nf"
process {
"""
input[0] = "nf-core"
"""
}
}
}

when {
process {
"""
input[0] = "lukas"
input[1] = LUKAS.out.results
"""
}
}

then {
assert process.success
assert snapshot(process.out.results).match()
}
}

}

0 comments on commit b9e87f8

Please sign in to comment.