Skip to content

Commit

Permalink
Add custom pytest-workflow test to ensure versions.yml is valid
Browse files Browse the repository at this point in the history
  • Loading branch information
grst committed Aug 16, 2021
1 parent 3abdf96 commit 5f1aa4c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ output/
*.code-workspace
.screenrc
.*.sw?
__pycache__
*.pyo
*.pyc
4 changes: 3 additions & 1 deletion modules/fastqc/functions.nf
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def getPathFromList(path_list) {
// Function to save/publish module results
//
def saveFiles(Map args) {
if (!args.filename.equals('versions.yml')) {
// TODO better way to detect that we are in a test and want to emit `versions.yml`
// or a least use a dedicated, unique environment variable.
if (!args.filename.equals('versions.yml') || System.getenv("PROFILE")) {
def ioptions = initOptions(args.options)
def path_list = [ ioptions.publish_dir ?: args.publish_dir ]
if (ioptions.publish_by_meta) {
Expand Down
2 changes: 2 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Makes the tests directory a python module
# (required to obtain resources from this folder from within Python)
23 changes: 23 additions & 0 deletions tests/test_versions_yml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from pathlib import Path
import pytest
import yaml


def _get_workflow_names():
here = Path(__file__).parent.resolve()
pytest_workflow_files = here.glob("**/test.yml")
for f in pytest_workflow_files:
test_config = yaml.safe_load(f.read_text())
for workflow in test_config:
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()
versions_yml = Path(
workflow_dir, f"output/{software_name}/versions.yml"
).read_text()
assert "END_VERSIONS" not in versions_yml
yaml.safe_load(versions_yml)

0 comments on commit 5f1aa4c

Please sign in to comment.