Skip to content

Commit

Permalink
put example under test (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-c authored Oct 11, 2021
1 parent 7fd8ca5 commit 8cc5de7
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 3 deletions.
13 changes: 13 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[run]
branch = True
source = cwl_utils

[report]
exclude_lines =
if self.debug:
pragma: no cover
raise NotImplementedError
if __name__ == .__main__.:
ignore_errors = True
omit =
tests/*
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ docker_extract.py --singularity DIRECTORY path_to_my_workflow.cwl

### Using the CWL Parsers

[//]: # "Please keep the below synchronized with load_cwl_by_path.py"
```python
# Imports
from pathlib import Path
from ruamel import yaml
import sys

from cwl_utils.parser load_document_by_path, save
from cwl_utils.parser import load_document_by_path, save

# File Input - This is the only thing you will need to adjust or take in as an input to your function:
cwl_file = Path("/path/to/wf.cwl") # or a plain string works as well
cwl_file = Path("testdata/md5sum.cwl") # or a plain string works as well

# Import CWL Object
cwl_obj = load_document_by_path(cwl_file)
Expand All @@ -71,6 +71,7 @@ print("List of object attributes:\n{}".format("\n".join(map(str, dir(cwl_obj))))

# Export CWL Object into a built-in typed object
saved_obj = save(cwl_obj)
print(f"Export of the loaded CWL object: {saved_obj}.")
```

## Development
Expand Down
1 change: 1 addition & 0 deletions load_cwl_by_path.py
20 changes: 20 additions & 0 deletions tests/load_cwl_by_path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""This is the example from README.md, please synchronize all changes between the two."""
# SPDX-License-Identifier: Apache-2.0
from pathlib import Path
from ruamel import yaml
import sys

from cwl_utils.parser import load_document_by_path, save

# File Input - This is the only thing you will need to adjust or take in as an input to your function:
cwl_file = Path("testdata/md5sum.cwl") # or a plain string works as well

# Import CWL Object
cwl_obj = load_document_by_path(cwl_file)

# View CWL Object
print("List of object attributes:\n{}".format("\n".join(map(str, dir(cwl_obj)))))

# Export CWL Object into a built-in typed object
saved_obj = save(cwl_obj)
print(f"Export of the loaded CWL object: {saved_obj}.")
18 changes: 18 additions & 0 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Tests of example Python scripts."""
import os
from pathlib import Path


def test_load_example() -> None:
"""Test the load_cwl_by_path.py script."""
cwd = Path.cwd()
parent = Path(__file__).resolve().parent
os.chdir(parent.parent)
exec(
open(parent / "load_cwl_by_path.py").read(),
globals(),
locals(),
)
os.chdir(cwd)
result = locals()["saved_obj"]
assert result["class"] == "Workflow"

0 comments on commit 8cc5de7

Please sign in to comment.