Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GlassOfWhiskey committed Feb 12, 2023
1 parent 5f1886d commit 90f4b86
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 1 deletion.
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ include cwl_utils/cwlNodeEngineJSConsole.js
include cwl_utils/cwlNodeEngineWithContext.js
include testdata/*.cwl
include testdata/*.yaml
include testdata/*.yml
include testdata/*.input
include testdata/*.json
include testdata/*.ttl
include testdata/*.owl
include testdata/checker_wf/*.cwl
Expand Down
9 changes: 9 additions & 0 deletions testdata/dir4-job.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
inf:
class: File
location: hello.tar
secondaryFiles:
- class: File
location: index.py
- class: Directory
basename: xtestdir
location: testdir
6 changes: 6 additions & 0 deletions testdata/env-job3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
in: "hello test env"
cwl:requirements:
- class: EnvVarRequirement
envDef:
- envName: TEST_ENV
envValue: $(inputs.in)
7 changes: 7 additions & 0 deletions testdata/formattest-job.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"input": {
"class": "File",
"location": "whale.txt",
"format": "edam:format_2330"
}
}
1 change: 1 addition & 0 deletions testdata/nested-array-job.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
letters: [[a]]
109 changes: 108 additions & 1 deletion tests/test_parser_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import cwl_utils.parser.utils
from cwl_utils.errors import WorkflowException
from cwl_utils.parser import load_document_by_uri

from .util import get_data


Expand Down Expand Up @@ -144,6 +143,36 @@ def test_v1_0_file_content_larger_than_64_kB() -> None:
assert content == text[0 : cwl_utils.parser.cwl_v1_0_utils.CONTENT_LIMIT]


def test_v_1_0_load_inputfile_with_format() -> None:
"""Test that File object with the `format` field is correctly loaded with CWL v1.0."""
uri = Path(get_data("testdata/formattest2_v1_0.cwl")).resolve().as_uri()
cwl_obj = load_document_by_uri(uri)
uri = Path(get_data("testdata/formattest-job.json")).resolve().as_uri()
jobfile = cwl_utils.parser.utils.load_inputfile_by_uri(
"v1.0", uri, cwl_obj.loadingOptions
)
assert jobfile["input"].format == cwl_obj.inputs[0].format


def test_v_1_0_load_inputfile_with_nested_array() -> None:
"""Test that nested arrays are preserved when loading an input file with CWL v1.0."""
uri = Path(get_data("testdata/nested-array-job.yml")).resolve().as_uri()
jobfile = cwl_utils.parser.utils.load_inputfile_by_uri("v1.0", uri)
assert isinstance(jobfile["letters"], MutableSequence)
assert isinstance(jobfile["letters"][0], MutableSequence)
assert jobfile["letters"][0][0] == "a"


def test_v_1_0_load_inputfile_with_secondary_files() -> None:
"""Test that secondary files are treated as objects when loading an input file with CWL v1.0."""
uri = Path(get_data("testdata/dir4-job.yml")).resolve().as_uri()
jobfile = cwl_utils.parser.utils.load_inputfile_by_uri("v1.0", uri)
assert isinstance(jobfile["inf"].secondaryFiles[0], cwl_utils.parser.cwl_v1_0.File)
assert isinstance(
jobfile["inf"].secondaryFiles[1], cwl_utils.parser.cwl_v1_0.Directory
)


def test_v1_0_stdout_to_file() -> None:
"""Test that stdout shortcut is converted to stdout parameter with CWL v1.0."""
clt = cwl_utils.parser.cwl_v1_0.CommandLineTool(
Expand Down Expand Up @@ -423,6 +452,45 @@ def test_v1_1_file_content_larger_than_64_kB() -> None:
assert content == text[0 : cwl_utils.parser.cwl_v1_1_utils.CONTENT_LIMIT]


def test_v_1_1_load_inputfile_with_format() -> None:
"""Test that File object with the `format` field is correctly loaded with CWL v1.1."""
uri = Path(get_data("testdata/formattest2_v1_1.cwl")).resolve().as_uri()
cwl_obj = load_document_by_uri(uri)
uri = Path(get_data("testdata/formattest-job.json")).resolve().as_uri()
jobfile = cwl_utils.parser.utils.load_inputfile_by_uri(
"v1.1", uri, cwl_obj.loadingOptions
)
assert jobfile["input"].format == cwl_obj.inputs[0].format


def test_v_1_1_load_inputfile_with_nested_array() -> None:
"""Test that nested arrays are preserved when loading an input file with CWL v1.1."""
uri = Path(get_data("testdata/nested-array-job.yml")).resolve().as_uri()
jobfile = cwl_utils.parser.utils.load_inputfile_by_uri("v1.1", uri)
assert isinstance(jobfile["letters"], MutableSequence)
assert isinstance(jobfile["letters"][0], MutableSequence)
assert jobfile["letters"][0][0] == "a"


def test_v_1_1_load_inputfile_with_requirements() -> None:
"""Test that an input file with the cwl:requirements directive is correctly loaded with CWL v1.1."""
uri = Path(get_data("testdata/env-job3.yaml")).resolve().as_uri()
jobfile = cwl_utils.parser.utils.load_inputfile_by_uri("v1.1", uri)
assert isinstance(
jobfile["cwl:requirements"][0], cwl_utils.parser.cwl_v1_1.EnvVarRequirement
)


def test_v_1_1_load_inputfile_with_secondary_files() -> None:
"""Test that secondary files are treated as objects when loading an input file with CWL v1.1."""
uri = Path(get_data("testdata/dir4-job.yml")).resolve().as_uri()
jobfile = cwl_utils.parser.utils.load_inputfile_by_uri("v1.1", uri)
assert isinstance(jobfile["inf"].secondaryFiles[0], cwl_utils.parser.cwl_v1_1.File)
assert isinstance(
jobfile["inf"].secondaryFiles[1], cwl_utils.parser.cwl_v1_1.Directory
)


def test_v1_1_stdout_to_file() -> None:
"""Test that stdout shortcut is converted to stdout parameter with CWL v1.1."""
clt = cwl_utils.parser.cwl_v1_1.CommandLineTool(
Expand Down Expand Up @@ -746,6 +814,45 @@ def test_v1_2_file_content_larger_than_64_kB() -> None:
cwl_utils.parser.cwl_v1_2_utils.content_limit_respected_read(f)


def test_v_1_2_load_inputfile_with_format() -> None:
"""Test that File object with the `format` field is correctly loaded with CWL v1.2."""
uri = Path(get_data("testdata/formattest2.cwl")).resolve().as_uri()
cwl_obj = load_document_by_uri(uri)
uri = Path(get_data("testdata/formattest-job.json")).resolve().as_uri()
jobfile = cwl_utils.parser.utils.load_inputfile_by_uri(
"v1.2", uri, cwl_obj.loadingOptions
)
assert jobfile["input"].format == cwl_obj.inputs[0].format


def test_v_1_2_load_inputfile_with_nested_array() -> None:
"""Test that nested arrays are preserved when loading an input file with CWL v1.2."""
uri = Path(get_data("testdata/nested-array-job.yml")).resolve().as_uri()
jobfile = cwl_utils.parser.utils.load_inputfile_by_uri("v1.2", uri)
assert isinstance(jobfile["letters"], MutableSequence)
assert isinstance(jobfile["letters"][0], MutableSequence)
assert jobfile["letters"][0][0] == "a"


def test_v_1_2_load_inputfile_with_requirements() -> None:
"""Test that an input file with the cwl:requirements directive is correctly loaded with CWL v1.2."""
uri = Path(get_data("testdata/env-job3.yaml")).resolve().as_uri()
jobfile = cwl_utils.parser.utils.load_inputfile_by_uri("v1.2", uri)
assert isinstance(
jobfile["cwl:requirements"][0], cwl_utils.parser.cwl_v1_2.EnvVarRequirement
)


def test_v_1_2_load_inputfile_with_secondary_files() -> None:
"""Test that secondary files are treated as objects when loading an input file with CWL v1.2."""
uri = Path(get_data("testdata/dir4-job.yml")).resolve().as_uri()
jobfile = cwl_utils.parser.utils.load_inputfile_by_uri("v1.2", uri)
assert isinstance(jobfile["inf"].secondaryFiles[0], cwl_utils.parser.cwl_v1_2.File)
assert isinstance(
jobfile["inf"].secondaryFiles[1], cwl_utils.parser.cwl_v1_2.Directory
)


def test_v1_2_stdout_to_file() -> None:
"""Test that stdout shortcut is converted to stdout parameter with CWL v1.2."""
clt = cwl_utils.parser.cwl_v1_2.CommandLineTool(
Expand Down

0 comments on commit 90f4b86

Please sign in to comment.