nf-core_modules/tests/test_versions_yml.py

61 lines
2.3 KiB
Python
Raw Normal View History

from pathlib import Path
import pytest
import yaml
import re
from textwrap import dedent
def _get_workflow_names():
"""Get all names of all workflows which have a test.yml in the tests directory.
To do so, recursively finds all test.yml files and parses their content.
"""
here = Path(__file__).parent.resolve()
Subworkflow Infrastructure (#662) * feat(subworkflows): Add align_bowtie2 subworkflow For testing CI setup * test(align_bowtie2): Add initial list of changes to test * test(align_bowtie2): Add initial test * refactor: Use tags to run subworkflows ci For every underlying module used by workflow and allow the modules pytest-modules definition be the source of truth. * refactor: Use individual directories for subworkflows * docs(align_bowtie2): Add initial meta.yml Copied most of it from the bowtie2/align module. * fix(align_bowtie2): Fix module include paths * test(bam_sort_samtools): Add initial test * ci(bam_sort_samtools): Add modules that trigger the tag * test(bam_stats_samtools): Add initial test * ci(bam_stats_samtools): Add keys to pick up changes * docs(bam_samtools): Add initial meta.yml * test(align_bowtie2): Fix path to subworkflow * test(align_bowtie2): Update entry point * fix(bam_sort_samtools): Update include paths * test(bam_sort_samtools): Fix path * style: Clean up addParams * test(samtools_sort): Add suffix for test * test(align_bowtie2): Add samtools_options for suffix * test(bam_stats_samtools): Update path * test(bam_stats_samtools): Use stats input Otherwise it's just an example of how it's used in the bam_sort_samtools subworkflow * ci(linting): Skip module linting of subworkflows * ci(linting): Clean up startsWith statement * test(bam_stats_samtools): Use single end test data for single end test * test(bam_stats_samtools): Add expected files * test(align_bowtie2): Add paired-end test * test(align_bowtie2): Sort order of output * test(align_bowtie2): Update hashes * docs(align_bowtie2): Fix typo * test(align_bowtie2): Update samtools output names * test(align_bowtie2): Remove md5sums for bam/bai * feat(subworkflows): Add nextflow.configs These can be used for default settings in the future. They can then be included in the conf/modules.config so that the params don't have to be duplicated in the root nextflow.config. * docs(subworkflows): Include modules instead of tools * fix: Update to versions * chore(align_bowtie2): Remove duplicate tag * style: Format yamls * test(subworkflows): Only check versions for modules * chore: Update subworkflows to match rnaseq dev * fix(subworkflows): Update paths * fix(bam_sort_samtools): Fix sort parameters for testing * Apply suggestions from code review Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com> * docs: Update TODOs with a message * ci: Try using a matrix for strategy * ci: Try passing an array * Revert "ci: Try passing an array" This reverts commit d3611fcd8332bbb9a8501e8dd299d0a623aaecaa. Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com>
2021-10-08 15:02:42 +00:00
pytest_workflow_files = here.glob("modules/**/test.yml")
for f in pytest_workflow_files:
# test_config = yaml.safe_load(f.read_text())
test_config = yaml.load(f.read_text(), Loader=yaml.BaseLoader)
for workflow in test_config:
# https://github.com/nf-core/modules/pull/1242 - added to cover tests
# that expect an error and therefore will not generate a versions.yml
if 'exit_code' not in workflow:
yield workflow["name"]
@pytest.mark.workflow(*_get_workflow_names())
def test_ensure_valid_version_yml(workflow_dir):
workflow_dir = Path(workflow_dir)
software_name = workflow_dir.name.split("_")[0].lower()
try:
versions_yml_file = workflow_dir / f"output/{software_name}/versions.yml"
versions_yml = versions_yml_file.read_text()
except FileNotFoundError:
raise AssertionError(
dedent(
f"""\
`versions.yml` not found in the output directory.
Expected path: `{versions_yml_file}`
This can have multiple reasons:
* The test-workflow failed before a `versions.yml` could be generated.
* The workflow name in `test.yml` does not start with the tool name.
"""
)
)
assert (
"END_VERSIONS" not in versions_yml
), "END_VERSIONS detected in versions.yml. This is a sign of an ill-formatted HEREDOC"
# Raises an exception if yaml is not valid
versions = yaml.safe_load(versions_yml)
assert (
len(versions) == 1
), "The top-level of versions.yml must contain exactly one entry: the process name as dict key"
software_versions = next(iter(versions.values()))
assert len(software_versions), "There must be at least one version emitted."
for tool, version in software_versions.items():
assert re.match(
2022-06-10 10:56:56 +00:00
r"^\d.*|^[a-f0-9]{40}$", str(version)
2022-06-10 11:01:40 +00:00
), f"Version number for {tool} must start with a number, or be a Git SHA commit id. "