Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate component create to nf test #2490

Merged
merged 119 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
119 commits
Select commit Hold shift + click to select a range
5283677
generalize nextflow_cmd to run_cmd to use the same structure for nf-test
mashehu Oct 24, 2023
0081766
initial changes for nf-test
mashehu Oct 24, 2023
d9126e5
move tags.yml to correct position
mashehu Oct 24, 2023
ecda687
Update nf_core/utils.py
mashehu Oct 24, 2023
955321b
convert all cmds
mashehu Oct 24, 2023
0a4afac
first running version
mashehu Oct 24, 2023
ca233d1
Merge branch 'migrate-component-create-to-nf_test' of github.com:mash…
mashehu Oct 24, 2023
86613b6
replace params
mashehu Oct 24, 2023
e0c30cd
fix typing errors
mashehu Oct 24, 2023
a9f55ba
add TODO comments to main.nf.test and fix tags.yml template rendering
mirpedrol Oct 25, 2023
865d613
add todo comment for chained modules
mirpedrol Oct 25, 2023
d767c78
add real example to main.nf.test
mirpedrol Oct 26, 2023
876eab3
add tags.yml to prettierignore
mirpedrol Oct 26, 2023
3b9f031
add main.nf.test to template instead of using nf-test
mirpedrol Oct 26, 2023
79215fb
generalize nextflow_cmd to run_cmd to use the same structure for nf-test
mashehu Oct 24, 2023
7cab286
initial changes for nf-test
mashehu Oct 24, 2023
f41d410
move tags.yml to correct position
mashehu Oct 24, 2023
cbc398a
convert all cmds
mashehu Oct 24, 2023
8d7794a
first running version
mashehu Oct 24, 2023
1a58690
replace params
mashehu Oct 24, 2023
86db72b
fix typing errors
mashehu Oct 24, 2023
7a7fd93
add TODO comments to main.nf.test and fix tags.yml template rendering
mirpedrol Oct 25, 2023
11773ef
add todo comment for chained modules
mirpedrol Oct 25, 2023
eafb3b5
add real example to main.nf.test
mirpedrol Oct 26, 2023
56086c6
add tags.yml to prettierignore
mirpedrol Oct 26, 2023
63c3188
add main.nf.test to template instead of using nf-test
mirpedrol Oct 26, 2023
4038131
modules create tests check for main.nf.test
mirpedrol Oct 31, 2023
43bf218
remove outputDir from the modules template
mirpedrol Oct 31, 2023
4ffc3cf
add nf-test to subworkflows
mirpedrol Oct 31, 2023
db10253
subworkflows create tests check for main.nf.test
mirpedrol Oct 31, 2023
a3eae4d
Merge branch 'migrate-component-create-to-nf_test' of https://github.…
mirpedrol Oct 31, 2023
80ddddb
fix tags for subtools, add version assertion to template
mashehu Nov 1, 2023
617010e
fix quotes in templates
mashehu Nov 1, 2023
04efb40
add first version of the `create-snapshot` command
mashehu Nov 1, 2023
71c441c
install all type specific dependencies in CI step
mashehu Nov 1, 2023
a7cfdd5
add new command 🙃
mashehu Nov 2, 2023
d6b9f6c
remove tests for modules create_test_yml
mashehu Nov 2, 2023
6b0ff49
remove more mentions of test_yml_builder
mashehu Nov 2, 2023
0045d4d
add types to create-snapshot and use component_type
mirpedrol Nov 2, 2023
61459f5
add subworkflows create-snapshot
mirpedrol Nov 2, 2023
6b63566
add linting for snapshot file
mashehu Nov 6, 2023
73487dd
add correct tags to subworkflow template
mashehu Nov 6, 2023
cdf5f63
fix smaller things according to mypy
mashehu Nov 6, 2023
a1743cd
Merge branch 'migrate-component-create-to-nf_test' of github.com:mash…
mashehu Nov 6, 2023
bff7e89
add pytests for components snapshot generator
mirpedrol Nov 7, 2023
2f5312a
add more typing
mashehu Nov 7, 2023
ef52c75
Merge branch 'migrate-component-create-to-nf_test' of github.com:mash…
mashehu Nov 7, 2023
f42fe20
run create-snapshot tests from modules root directory
mirpedrol Nov 7, 2023
6ef6268
Merge branch 'migrate-component-create-to-nf_test' of github.com:mash…
mashehu Nov 7, 2023
e79d4d3
fix checking if PROFILE exists
mirpedrol Nov 7, 2023
c7bc5b7
add new environment.yml setup to template according to #2495
mashehu Nov 8, 2023
3f46c16
Merge branch 'migrate-component-create-to-nf_test' of github.com:mash…
mashehu Nov 8, 2023
53b23b7
use set_wd for tests
mirpedrol Nov 8, 2023
c4683f0
check md5sums and add snapshot test for a subworkflow
mirpedrol Nov 8, 2023
2a640cc
append error messages to self.errors
mashehu Nov 8, 2023
fa0c6f3
add --dir option to create-snapshot command
mirpedrol Nov 8, 2023
f5ddc64
add no test found error and test for this
mirpedrol Nov 9, 2023
163019d
add test for unstable snapshot
mirpedrol Nov 9, 2023
8ebf36a
don't assert run() function from snapshot generator
mirpedrol Nov 9, 2023
749ba53
Update tests/components/create_snapshot.py
mirpedrol Nov 9, 2023
b1b57d3
add linting code for environemnt.yml
mashehu Nov 13, 2023
5aad9c4
add hint for language server, update to new new for schema file
mashehu Nov 13, 2023
aaa5945
add types
mashehu Nov 13, 2023
9fe1c3e
add schema based validation to environment yaml linting, add tests
mashehu Nov 13, 2023
92fd677
Merge branch 'dev' into migrate-component-create-to-nf_test
mashehu Nov 13, 2023
2d51ff8
fix mypy
mashehu Nov 13, 2023
74139bd
Merge branch 'migrate-component-create-to-nf_test' of github.com:mash…
mashehu Nov 13, 2023
54bb5b6
fix type error
mashehu Nov 13, 2023
28c1c76
add nf-test dependency
mashehu Nov 13, 2023
dc7a330
install nf-test for ci
mashehu Nov 13, 2023
1ce81c0
switch bump_version to use environemt.yml
mashehu Nov 14, 2023
32ef61b
update modules in pipeline template
mashehu Nov 14, 2023
ab113c7
fix test for updated snapshot
mashehu Nov 14, 2023
bec4bb3
test for name mismatch in environment.yml
mashehu Nov 14, 2023
0622fbc
make nicer diff for nf-test error
mashehu Nov 14, 2023
4c30da3
fix error in download test
mashehu Nov 14, 2023
2ca1764
don't convert arrays to strings in licence field
mashehu Nov 14, 2023
6e2dc70
add nf-test to CI
mashehu Nov 14, 2023
cb175e7
fix environment.yml linting
mashehu Nov 14, 2023
38d9db7
rely on environment.yml for bioconda versions
mashehu Nov 14, 2023
91c24e6
fix tests
mashehu Nov 14, 2023
dc6d033
fix types
mashehu Nov 14, 2023
d82bf66
remove subworkflows test_yml_builder and fix subworkflow tests
mirpedrol Nov 15, 2023
24ff636
fix nf-test setup in CI
mashehu Nov 15, 2023
20ae7b1
Merge branch 'migrate-component-create-to-nf_test' of github.com:mash…
mashehu Nov 15, 2023
72a78c0
fix assertion value
mashehu Nov 15, 2023
d687430
handle local modules without nf-test
mashehu Nov 15, 2023
f673a89
add linting for nf-test and remove linting for pytests
mirpedrol Nov 15, 2023
bb070c6
fix linting components errors
mirpedrol Nov 15, 2023
e19a4a2
remove tmp dir manually if we find a PermissionError
mirpedrol Nov 16, 2023
5e02619
fix launch tests, move tmp pipeline creation to utils to share betwee…
mashehu Nov 16, 2023
316055f
Merge branch 'migrate-component-create-to-nf_test' of github.com:mash…
mashehu Nov 16, 2023
7b0683e
fix tests by correcting raised error type
mashehu Nov 16, 2023
22a9071
fix tests, switch to pdiff instead of icdiff, because it handles widt…
mashehu Nov 16, 2023
a8f6332
revert e19a4a250bf7a8a4ebd484f94cc39b324642081f
mirpedrol Nov 16, 2023
5347b56
Apply suggestions from code review
mashehu Nov 16, 2023
fc0a3fc
remove debugging raise introduced by mistake
mirpedrol Nov 16, 2023
d12560d
move create-snapshot command to test command
mirpedrol Nov 20, 2023
300289e
move modules and subworkflows test tests to components
mirpedrol Nov 20, 2023
c254699
add test for generate snapshot once
mirpedrol Nov 20, 2023
bb640bb
update README
mashehu Nov 20, 2023
c550823
Apply suggestions from code review
mashehu Nov 20, 2023
2b15177
fix typing errors
mashehu Nov 20, 2023
8d5550e
Merge branch 'migrate-component-create-to-nf_test' of github.com:mash…
mashehu Nov 20, 2023
f4a48b5
remove last traces of create-snapshot or create-test-yml
mashehu Nov 20, 2023
9f2f905
fix parameters
mashehu Nov 20, 2023
f288520
update changelog
mashehu Nov 20, 2023
7722d52
rename create_snapshot functions and files
mashehu Nov 20, 2023
71c0b08
simplify obsolete check
mashehu Nov 21, 2023
d29643e
add back option to handle pytest based modules in bump_version
mashehu Nov 21, 2023
4d08f6d
rename generator to test to make it hopefully less confusing
mashehu Nov 21, 2023
0c120ab
automatically sort dependencies in environment.yml while linting
mashehu Nov 21, 2023
dc5c7cb
fix types
mashehu Nov 21, 2023
bcf22a1
Merge branch 'migrate-component-create-to-nf_test' of github.com:mash…
mashehu Nov 21, 2023
a5a3fd4
fix typo
mashehu Nov 21, 2023
41b61c1
fix import statement
mashehu Nov 21, 2023
d2df78a
Update nf_core/components/components_test.py
mashehu Nov 21, 2023
75a07c4
remove self.run_tests
mashehu Nov 21, 2023
b4ff558
Merge branch 'migrate-component-create-to-nf_test' of github.com:mash…
mashehu Nov 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions .github/workflows/lint-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,29 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-python@v3
with:
python-version: "3.11"
- run: pip install mypy types-PyYAML
python-version: 3.11
cache: "pip"

- name: Install dependencies
run: |
python -m pip install --upgrade pip -r requirements-dev.txt
pip install -e .

- name: Cache nf-test installation
id: cache-software
uses: actions/cache@v3
with:
path: |
/usr/local/bin/nf-test
/home/runner/.nf-test/nf-test.jar
key: ${{ runner.os }}-${{ env.NFTEST_VER }}-nftest

- name: Install nf-test
if: steps.cache-software.outputs.cache-hit != 'true'
run: |
wget -qO- https://code.askimed.com/install/nf-test | bash
sudo mv nf-test /usr/local/bin/

- name: Get Python changed files
id: changed-py-files
uses: tj-actions/changed-files@v23
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ jobs:
with:
version: "latest-everything"

- name: Cache nf-test installation
id: cache-software
uses: actions/cache@v3
with:
path: |
/usr/local/bin/nf-test
/home/runner/.nf-test/nf-test.jar
key: ${{ runner.os }}-${{ env.NFTEST_VER }}-nftest

- name: Install nf-test
if: steps.cache-software.outputs.cache-hit != 'true'
run: |
wget -qO- https://code.askimed.com/install/nf-test | bash
sudo mv nf-test /usr/local/bin/

- name: Test with pytest
run: python3 -m pytest tests/ --color=yes --cov-report=xml --cov-config=.github/.coveragerc --cov=nf_core

Expand Down
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ slackreport.json
docs/api/_build
testing
nf_core/module-template/modules/meta.yml
nf_core/module-template/tests/test.yml
nf_core/module-template/modules/tests/tags.yml
mashehu marked this conversation as resolved.
Show resolved Hide resolved
nf_core/subworkflow-template/subworkflows/tests/tags.yml
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

### General

- Change testing framework for modules and subworkflows from pytest to nf-test ([#2490](https://github.com/nf-core/tools/pull/2490))
- `bump_version` keeps now the indentation level of the updated version entries ([#2514](https://github.com/nf-core/tools/pull/2514))

# [v2.10 - Nickel Ostrich](https://github.com/nf-core/tools/releases/tag/2.10) + [2023-09-25]
Expand Down
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ ENV NXF_VER ${NXF_VER}
RUN curl -s https://get.nextflow.io | bash \
&& mv nextflow /usr/local/bin \
&& chmod a+rx /usr/local/bin/nextflow
# Install nf-test
RUN curl -fsSL https://code.askimed.com/install/nf-test | bash \
&& mv nf-test /usr/local/bin \
&& chmod a+rx /usr/local/bin/nf-test

# Add the nf-core source files to the image
COPY . /usr/src/nf_core
WORKDIR /usr/src/nf_core
Expand Down
76 changes: 28 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ A python package with helper tools for the nf-core community.
- [`modules remove` - Remove a module from a pipeline](#remove-a-module-from-a-pipeline)
- [`modules patch` - Create a patch file for a module](#create-a-patch-file-for-a-module)
- [`modules create` - Create a module from the template](#create-a-new-module)
- [`modules create-test-yml` - Create the `test.yml` file for a module](#create-a-module-test-config-file)
- [`modules lint` - Check a module against nf-core guidelines](#check-a-module-against-nf-core-guidelines)
- [`modules test` - Run the tests for a module](#run-the-tests-for-a-module-using-pytest)
- [`modules bump-versions` - Bump software versions of modules](#bump-bioconda-and-container-versions-of-modules-in)
Expand All @@ -53,7 +52,6 @@ A python package with helper tools for the nf-core community.
- [`subworkflows update` - Update subworkflows in a pipeline](#update-subworkflows-in-a-pipeline)
- [`subworkflows remove` - Remove a subworkflow from a pipeline](#remove-a-subworkflow-from-a-pipeline)
- [`subworkflows create` - Create a subworkflow from the template](#create-a-new-subworkflow)
- [`subworkflows create-test-yml` - Create the `test.yml` file for a subworkflow](#create-a-subworkflow-test-config-file)
- [`subworkflows lint` - Check a subworkflow against nf-core guidelines](#check-a-subworkflow-against-nf-core-guidelines)
- [`subworkflows test` - Run the tests for a subworkflow](#run-the-tests-for-a-subworkflow-using-pytest)
- [Citation](#citation)
Expand Down Expand Up @@ -947,20 +945,6 @@ fake_command: nf-core modules create fastqc --author @nf-core-bot --label proce

![`cd modules && nf-core modules create fastqc --author @nf-core-bot --label process_low --meta --force`](docs/images/nf-core-modules-create.svg)

### Create a module test config file

All modules on [nf-core/modules](https://github.com/nf-core/modules) have a strict requirement of being unit tested using minimal test data.
To help developers build new modules, the `nf-core modules create-test-yml` command automates the creation of the yaml file required to document the output file `md5sum` and other information generated by the testing.
After you have written a minimal Nextflow script to test your module `tests/modules/<tool>/<subtool>/main.nf`, this command will run the tests for you and create the `tests/modules/<tool>/<subtool>/test.yml` file.

<!-- RICH-CODEX
working_dir: tmp/modules
extra_env:
PROFILE: 'conda'
-->

![`nf-core modules create-test-yml fastqc --no-prompts --force`](docs/images/nf-core-modules-create-test.svg)

### Check a module against nf-core guidelines

Run the `nf-core modules lint` command to check modules in the current working directory (pipeline or nf-core/modules clone) against nf-core guidelines.
Expand All @@ -974,15 +958,12 @@ before_command: sed 's/1.13a/1.10/g' modules/multiqc/main.nf > modules/multiqc/m

![`nf-core modules lint multiqc`](docs/images/nf-core-modules-lint.svg)

### Run the tests for a module using pytest

To run unit tests of a module that you have installed or the test created by the command [`nf-core modules create-test-yml`](#create-a-module-test-config-file), you can use `nf-core modules test` command. This command runs the tests specified in `modules/tests/software/<tool>/<subtool>/test.yml` file using [pytest](https://pytest-workflow.readthedocs.io/en/stable/).
### Create a test for a module

:::info
This command uses the pytest argument `--git-aware` to avoid copying the whole `.git` directory and files ignored by `git`. This means that it will only include files listed by `git ls-files`. Remember to **commit your changes** after adding a new module to add the new files to your git index.
:::
All modules on [nf-core/modules](https://github.com/nf-core/modules) have a strict requirement of being unit tested using minimal test data. We use [nf-test](https://code.askimed.com/nf-test/) as our testing framework.
Each module comes already with a template for the test file in `test/main.nf.test`. Replace the placeholder code in that file with your specific input, output and proces. In order to generate the corresponding snapshot after writing your test, you can use the `nf-core modules test` command. This command will run `nf-test test` twice, to also check for snapshot stability, i.e. that the same snapshot is generated on multiple runs.

You can specify the module name in the form TOOL/SUBTOOL in command line or provide it later by prompts.
You can specify the module name in the form TOOL/SUBTOOL in the command or provide it later through interactive prompts.

<!-- RICH-CODEX
working_dir: tmp/modules
Expand All @@ -991,7 +972,15 @@ extra_env:
PROFILE: 'conda'
-->

![`nf-core modules test samtools/view --no-prompts`](docs/images/nf-core-modules-test.svg)
![`nf-core modules test fastqc --no-prompts --force`](docs/images/nf-core-modules-test.svg)

In case you changed something in the test and want to update the snapshot, run

```bash
nf-core modules test --update
```

If you want to run the test only once without checking for snapshot stability, you can use the `--once` flag.

### Bump bioconda and container versions of modules in

Expand Down Expand Up @@ -1221,19 +1210,29 @@ fake_command: nf-core subworkflows create bam_stats_samtools --author @nf-core-b

![`nf-core subworkflows create bam_stats_samtools --author @nf-core-bot --force`](docs/images/nf-core-subworkflows-create.svg)

### Create a subworkflow test config file
### Create a test for a subworkflow

All subworkflows on [nf-core/modules](https://github.com/nf-core/modules) have a strict requirement of being unit tested using minimal test data. We use [nf-test](https://code.askimed.com/nf-test/) as our testing framework.
Each subworkflow comes already with a template for the test file in `test/main.nf.test`. Replace the placeholder code in that file with your specific input, output and proces. In order to generate the corresponding snapshot after writing your test, you can use the `nf-core subworkflows test` command. This command will run `nf-test test` twice, to also check for snapshot stability, i.e. that the same snapshot is generated on multiple runs.

All subworkflows on [nf-core/modules](https://github.com/nf-core/modules) have a strict requirement of being unit tested using minimal test data.
To help developers build new subworkflows, the `nf-core subworkflows create-test-yml` command automates the creation of the yaml file required to document the output file `md5sum` and other information generated by the testing.
After you have written a minimal Nextflow script to test your subworkflow in `/tests/subworkflow/<subworkflow_name>/main.nf`, this command will run the tests for you and create the `/tests/subworkflow/<tool>/<subtool>/test.yml` file.
You can specify the subworkflow name in the command or provide it later through interactive prompts.

<!-- RICH-CODEX
working_dir: tmp/modules
timeout: 30
extra_env:
PROFILE: 'conda'
-->

![`nf-core subworkflows create-test-yml bam_stats_samtools --no-prompts --force`](docs/images/nf-core-subworkflows-create-test.svg)
![`nf-core subworkflows test bam_rseqc --no-prompts`](docs/images/nf-core-subworkflows-test.svg)

In case you changed something in the test and want to update the snapshot, run

```bash
nf-core subworkflows test --update
```

If you want to run the test only once without checking for snapshot stability, you can use the `--once` flag.

### Check a subworkflow against nf-core guidelines

Expand All @@ -1249,25 +1248,6 @@ extra_env:

![`nf-core subworkflows lint bam_stats_samtools`](docs/images/nf-core-subworkflows-lint.svg)

### Run the tests for a subworkflow using pytest

To run unit tests of a subworkflow that you have installed or the test created by the command [`nf-core subworkflow create-test-yml`](#create-a-subworkflow-test-config-file), you can use `nf-core subworkflows test` command. This command runs the tests specified in `tests/subworkflows/<subworkflow_name>/test.yml` file using [pytest](https://pytest-workflow.readthedocs.io/en/stable/).

:::info
This command uses the pytest argument `--git-aware` to avoid copying the whole `.git` directory and files ignored by `git`. This means that it will only include files listed by `git ls-files`. Remember to **commit your changes** after adding a new subworkflow to add the new files to your git index.
:::

You can specify the subworkflow name in the form TOOL/SUBTOOL in command line or provide it later by prompts.

<!-- RICH-CODEX
working_dir: tmp/modules
timeout: 30
extra_env:
PROFILE: 'conda'
-->

![`nf-core subworkflows test bam_rseqc --no-prompts`](docs/images/nf-core-subworkflows-test.svg)

## Citation

If you use `nf-core tools` in your work, please cite the `nf-core` publication as follows:
Expand Down
Loading
Loading