Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
lukfor committed Oct 11, 2023
1 parent b89f845 commit a5186cd
Show file tree
Hide file tree
Showing 2 changed files with 191 additions and 40 deletions.
151 changes: 151 additions & 0 deletions docs/docs/testcases/setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# Setup Method

The setup method allows you to specify processes or workflows that need to be executed before the primary `when` block. It serves as a mechanism to prepare the required input data or set up essential steps prior to the primary processing block.

## Syntax

The setup method is typically used within the context of a test case. The basic syntax for the setup method is as follows:

```groovy
test("my test"){
setup {
// Define and execute dependent processes or workflows here
}
}
```

Within the setup block, you can use the `run` method to define and execute dependent processes or workflows.

The `run` method syntax for a process is as follows:

```groovy
run("ProcessName") {
script "path/to/process/script.nf"
process {
// Define the process inputs here
}
}
```

The `run` method syntax for a workflow is as follows:

```groovy
run("WorkflowName") {
script "path/to/workflow/script.nf"
workflow {
// Define the workflow inputs here
}
}
```

## Example Usage

### 1. Local Setup Method

In this example, we create a setup method within a Nextflow process definition to execute a dependent process named "ABRICATE_RUN." This process generates input data that is required for the primary process "ABRICATE_SUMMARY." The `setup` block specifies the execution of "ABRICATE_RUN," and the `when` block defines the processing logic for "ABRICATE_SUMMARY."

```groovy
nextflow_process {
name "Test process data"
script "../main.nf"
process "ABRICATE_SUMMARY"
config "./nextflow.config"
test("Should use process ABRICATE_RUN to generate input data") {
setup {
run("ABRICATE_RUN") {
script "../../run/main.nf"
process {
"""
input[0] = Channel.fromList([
tuple([ id:'test1', single_end:false ], // meta map
file(params.test_data['bacteroides_fragilis']['genome']['genome_fna_gz'], checkIfExists: true)),
tuple([ id:'test2', single_end:false ],
file(params.test_data['haemophilus_influenzae']['genome']['genome_fna_gz'], checkIfExists: true))
])
"""
}
}
}
when {
process {
"""
input[0] = ABRICATE_RUN.out.report.collect{ meta, report -> report }.map{ report -> [[ id: 'test_summary'], report]}
"""
}
}
then {
assert process.success
assert snapshot(process.out).match()
}
}
}
```

### 2. Global Setup Method

In this example, a global setup method is defined for all tests within a Nextflow process definition. The setup method is applied to multiple test cases, ensuring consistent setup for each test. This approach is useful when multiple tests share the same setup requirements.

```groovy
nextflow_process {
name "Test process data"
script "../main.nf"
process "ABRICATE_SUMMARY"
config "./nextflow.config"
setup {
run("ABRICATE_RUN") {
script "../../run/main.nf"
process {
"""
input[0] = Channel.fromList([
tuple([ id:'test1', single_end:false ], // meta map
file(params.test_data['bacteroides_fragilis']['genome']['genome_fna_gz'], checkIfExists: true)),
tuple([ id:'test2', single_end:false ],
file(params.test_data['haemophilus_influenzae']['genome']['genome_fna_gz'], checkIfExists: true))
])
"""
}
}
}
test("first test") {
when {
process {
"""
input[0] = ABRICATE_RUN.out.report.collect{ meta, report -> report }.map{ report -> [[ id: 'test_summary'], report]}
"""
}
}
then {
assert process.success
assert snapshot(process.out).match()
}
}
test("second test") {
when {
process {
"""
input[0] = ABRICATE_RUN.out.report.collect{ meta, report -> report }.map{ report -> [[ id: 'test_summary'], report]}
"""
}
}
then {
assert process.success
assert snapshot(process.out).match()
}
}
}
```
80 changes: 40 additions & 40 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ copyright: "© 2021 - 2023 Lukas Forer and Sebastian Schönherr"
theme:
name: material
features:
- content.tooltips
#- navigation.expand
- navigation.footer
- navigation.tabs
#- navigation.tabs.sticky
- search.highlight
- search.share
- search.suggest
- toc.integrate
- content.tabs.link
- content.tooltips
#- navigation.expand
- navigation.footer
- navigation.tabs
#- navigation.tabs.sticky
- search.highlight
- search.share
- search.suggest
- toc.integrate
- content.tabs.link
font:
text: Segoe UI

Expand All @@ -36,44 +36,44 @@ nav:
- Home: index.md
- Installation: installation.md
- Documentation:
- Getting Started: docs/getting-started.md
- Writing Tests:
- Pipeline Testing: docs/testcases/nextflow_pipeline.md
- Workflow Testing: docs/testcases/nextflow_workflow.md
- Process Testing: docs/testcases/nextflow_process.md
- Function Testing: docs/testcases/nextflow_function.md
- Params Dictionary: docs/testcases/params.md
- Global Variables: docs/testcases/global_variables.md
- Running Tests: docs/running-tests.md
- Writing Assertions:
- Power Assertions: docs/assertions/assertions.md
- Files: docs/assertions/files.md
- Snapshots: docs/assertions/snapshots.md
- Regular Expressions: docs/assertions/regular-expressions.md
- FASTA Files: docs/assertions/fasta.md
- Using Third-Party Libraries: docs/assertions/libraries.md
- Command Line Interface (CLI):
- init: docs/cli/init.md
- generate: docs/cli/generate.md
- test: docs/cli/test.md
- list: docs/cli/list.md
- clean: docs/cli/clean.md
- Configuration: docs/configuration.md
- Plugins:
- Available Plugins: https://code.askimed.com/nf-test-plugins
- Using Plugins: docs/plugins/using-plugins.md
- Developing Plugins: docs/plugins/developing-plugins.md
- Getting Started: docs/getting-started.md
- Writing Tests:
- Pipeline Testing: docs/testcases/nextflow_pipeline.md
- Workflow Testing: docs/testcases/nextflow_workflow.md
- Process Testing: docs/testcases/nextflow_process.md
- Function Testing: docs/testcases/nextflow_function.md
- Params Dictionary: docs/testcases/params.md
- Setup Method: docs/testcases/setup.md
- Global Variables: docs/testcases/global_variables.md
- Running Tests: docs/running-tests.md
- Writing Assertions:
- Power Assertions: docs/assertions/assertions.md
- Files: docs/assertions/files.md
- Snapshots: docs/assertions/snapshots.md
- Regular Expressions: docs/assertions/regular-expressions.md
- FASTA Files: docs/assertions/fasta.md
- Using Third-Party Libraries: docs/assertions/libraries.md
- Command Line Interface (CLI):
- init: docs/cli/init.md
- generate: docs/cli/generate.md
- test: docs/cli/test.md
- list: docs/cli/list.md
- clean: docs/cli/clean.md
- Configuration: docs/configuration.md
- Plugins:
- Available Plugins: https://code.askimed.com/nf-test-plugins
- Using Plugins: docs/plugins/using-plugins.md
- Developing Plugins: docs/plugins/developing-plugins.md
- Resources: resources.md
- About: about.md


markdown_extensions:
- admonition
- pymdownx.details
- pymdownx.superfences
- pymdownx.tabbed:
alternate_style: true
alternate_style: true
- attr_list
- pymdownx.emoji:
emoji_index: !!python/name:materialx.emoji.twemoji
emoji_generator: !!python/name:materialx.emoji.to_svg
emoji_generator: !!python/name:materialx.emoji.to_svg

0 comments on commit a5186cd

Please sign in to comment.