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

parsers: don't sort entries when processing ID Maps #343

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion cwl_utils/parser/cwl_v1_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ def load(
) -> Any:
if isinstance(doc, MutableMapping):
r: list[Any] = []
for k in sorted(doc.keys()):
for k in doc.keys():
val = doc[k]
if isinstance(val, CommentedMap):
v = copy.copy(val)
Expand Down
2 changes: 1 addition & 1 deletion cwl_utils/parser/cwl_v1_0_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from collections import namedtuple
from collections.abc import MutableMapping, MutableSequence
from io import StringIO
from typing import Any, IO, Optional, Union, cast
from typing import IO, Any, Optional, Union, cast
from urllib.parse import urldefrag

from schema_salad.exceptions import ValidationException
Expand Down
2 changes: 1 addition & 1 deletion cwl_utils/parser/cwl_v1_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ def load(
) -> Any:
if isinstance(doc, MutableMapping):
r: list[Any] = []
for k in sorted(doc.keys()):
for k in doc.keys():
val = doc[k]
if isinstance(val, CommentedMap):
v = copy.copy(val)
Expand Down
2 changes: 1 addition & 1 deletion cwl_utils/parser/cwl_v1_1_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from collections import namedtuple
from collections.abc import MutableMapping, MutableSequence
from io import StringIO
from typing import Any, IO, Optional, Union, cast
from typing import IO, Any, Optional, Union, cast
from urllib.parse import urldefrag

from schema_salad.exceptions import ValidationException
Expand Down
2 changes: 1 addition & 1 deletion cwl_utils/parser/cwl_v1_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ def load(
) -> Any:
if isinstance(doc, MutableMapping):
r: list[Any] = []
for k in sorted(doc.keys()):
for k in doc.keys():
val = doc[k]
if isinstance(val, CommentedMap):
v = copy.copy(val)
Expand Down
2 changes: 1 addition & 1 deletion cwl_utils/parser/cwl_v1_2_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from collections import namedtuple
from collections.abc import MutableMapping, MutableSequence
from io import StringIO
from typing import Any, IO, Optional, Union, cast
from typing import IO, Any, Optional, Union, cast
from urllib.parse import urldefrag

from schema_salad.exceptions import ValidationException
Expand Down
37 changes: 37 additions & 0 deletions testdata/map-ordering-v1_0.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
cwlVersion: v1.0
class: Workflow
inputs:
09first_input: string
05second_input: int
01third_input: File
steps:
zz_step_one:
run:
class: ExpressionTool
inputs: []
outputs: []
expression: ${return {}; }
requirements:
InlineJavascriptRequirement: {}
in: []
out: []
00_step_two:
out: []
run:
inputs: []
requirements:
InlineJavascriptRequirement: {}
outputs: []
expression: ${return {}; }
class: ExpressionTool
in: []
outputs:
zz_first_output:
type: File
outputSource: 01third_input
ll_second_output:
type: string
outputSource: 09first_input
aa_third_output:
type: int
outputSource: 05second_input
37 changes: 37 additions & 0 deletions testdata/map-ordering-v1_1.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
cwlVersion: v1.1
class: Workflow
inputs:
09first_input: string
05second_input: int
01third_input: File
steps:
zz_step_one:
run:
class: ExpressionTool
inputs: []
outputs: []
expression: ${return {}; }
requirements:
InlineJavascriptRequirement: {}
in: []
out: []
00_step_two:
out: []
run:
inputs: []
requirements:
InlineJavascriptRequirement: {}
outputs: []
expression: ${return {}; }
class: ExpressionTool
in: []
outputs:
zz_first_output:
type: File
outputSource: 01third_input
ll_second_output:
type: string
outputSource: 09first_input
aa_third_output:
type: int
outputSource: 05second_input
37 changes: 37 additions & 0 deletions testdata/map-ordering-v1_2.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
cwlVersion: v1.2
class: Workflow
inputs:
09first_input: string
05second_input: int
01third_input: File
steps:
zz_step_one:
run:
class: ExpressionTool
inputs: []
outputs: []
expression: ${return {}; }
requirements:
InlineJavascriptRequirement: {}
in: []
out: []
00_step_two:
out: []
run:
inputs: []
requirements:
InlineJavascriptRequirement: {}
outputs: []
expression: ${return {}; }
class: ExpressionTool
in: []
outputs:
zz_first_output:
type: File
outputSource: 01third_input
ll_second_output:
type: string
outputSource: 09first_input
aa_third_output:
type: int
outputSource: 05second_input
42 changes: 42 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,45 @@ def test_graph_load_all() -> None:
uri = Path(get_data("testdata/js-expr-req-wf.cwl")).resolve().as_uri()
cwl_objs = load_document_by_uri(uri, load_all=True)
assert len(cwl_objs) == 2


def test_map_ordering_v1_0() -> None:
"""Confirm that ID map entries are not sorted during parsing, CWL v1.0."""
uri = Path(get_data("testdata/map-ordering-v1_0.cwl")).resolve().as_uri()
cwl_obj = load_document_by_uri(uri)
assert cwl_obj.inputs[0].id == f"{uri}#09first_input"
assert cwl_obj.inputs[1].id == f"{uri}#05second_input"
assert cwl_obj.inputs[2].id == f"{uri}#01third_input"
assert cwl_obj.steps[0].id == f"{uri}#zz_step_one"
assert cwl_obj.steps[1].id == f"{uri}#00_step_two"
assert cwl_obj.outputs[0].id == f"{uri}#zz_first_output"
assert cwl_obj.outputs[1].id == f"{uri}#ll_second_output"
assert cwl_obj.outputs[2].id == f"{uri}#aa_third_output"


def test_map_ordering_v1_1() -> None:
"""Confirm that ID map entries are not sorted during parsing, CWL v1.1."""
uri = Path(get_data("testdata/map-ordering-v1_1.cwl")).resolve().as_uri()
cwl_obj = load_document_by_uri(uri)
assert cwl_obj.inputs[0].id == f"{uri}#09first_input"
assert cwl_obj.inputs[1].id == f"{uri}#05second_input"
assert cwl_obj.inputs[2].id == f"{uri}#01third_input"
assert cwl_obj.steps[0].id == f"{uri}#zz_step_one"
assert cwl_obj.steps[1].id == f"{uri}#00_step_two"
assert cwl_obj.outputs[0].id == f"{uri}#zz_first_output"
assert cwl_obj.outputs[1].id == f"{uri}#ll_second_output"
assert cwl_obj.outputs[2].id == f"{uri}#aa_third_output"


def test_map_ordering_v1_2() -> None:
"""Confirm that ID map entries are not sorted during parsing, CWL v1.2."""
uri = Path(get_data("testdata/map-ordering-v1_2.cwl")).resolve().as_uri()
cwl_obj = load_document_by_uri(uri)
assert cwl_obj.inputs[0].id == f"{uri}#09first_input"
assert cwl_obj.inputs[1].id == f"{uri}#05second_input"
assert cwl_obj.inputs[2].id == f"{uri}#01third_input"
assert cwl_obj.steps[0].id == f"{uri}#zz_step_one"
assert cwl_obj.steps[1].id == f"{uri}#00_step_two"
assert cwl_obj.outputs[0].id == f"{uri}#zz_first_output"
assert cwl_obj.outputs[1].id == f"{uri}#ll_second_output"
assert cwl_obj.outputs[2].id == f"{uri}#aa_third_output"
Loading