Skip to content

Commit 823b687

Browse files
committed
test: add missing URI
1 parent 74d4e7a commit 823b687

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

cwl_utils/parser/__init__.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,24 +160,27 @@ def load_document_by_uri(
160160
load_all: bool = False,
161161
) -> Any:
162162
"""Load a CWL object from a URI or a path."""
163+
base_uri = ""
164+
real_uri = ""
163165
if isinstance(path, str):
164166
uri = urlparse(path)
165167
id_ = uri.fragment or None
166168
if not uri.scheme or uri.scheme == "file":
167-
real_path = Path(unquote_plus(uri.path)).resolve().as_uri()
169+
real_uri = Path(unquote_plus(uri.path)).resolve().as_uri()
170+
base_uri = Path(unquote_plus(uri.path)).resolve().parent.as_uri()
168171
else:
169-
real_path = path
172+
real_uri = path
173+
base_uri = os.path.dirname(path)
170174
else:
171-
real_path = path.resolve().as_uri()
175+
real_uri = path.resolve().as_uri()
176+
base_uri = path.resolve().parent.as_uri()
172177
id_ = path.resolve().name.split("#")[1] if "#" in path.resolve().name else None
173178

174-
baseuri = str(real_path)
175-
176179
if loadingOptions is None:
177-
loadingOptions = cwl_v1_2.LoadingOptions(fileuri=baseuri)
180+
loadingOptions = cwl_v1_2.LoadingOptions(fileuri=real_uri, baseuri=base_uri)
178181

179-
doc = loadingOptions.fetcher.fetch_text(real_path)
180-
return load_document_by_string(doc, baseuri, loadingOptions, id_, load_all)
182+
doc = loadingOptions.fetcher.fetch_text(real_uri)
183+
return load_document_by_string(doc, real_uri, loadingOptions, id_, load_all)
181184

182185

183186
def load_document(

tests/test_parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def test_load_document() -> None:
3939
"""Test load_document for a CommandLineTool."""
4040
with open(TEST_v1_0_CWL) as cwl_h:
4141
yaml_obj = yaml.load(cwl_h)
42-
cwl_obj = load_document(yaml_obj)
42+
cwl_obj = load_document(yaml_obj, Path(TEST_v1_0_CWL).resolve().as_uri())
4343
assert cwl_obj.cwlVersion == "v1.0"
4444
assert cwl_obj.inputs[0].id.endswith("input_file")
4545

@@ -64,12 +64,12 @@ def test_save() -> None:
6464
"""Test save for a list of Process objects with different cwlVersions."""
6565
with open(TEST_v1_0_CWL) as cwl_h:
6666
yaml_obj10 = yaml.load(cwl_h)
67-
cwl_obj10 = load_document(yaml_obj10)
67+
cwl_obj10 = load_document(yaml_obj10, Path(TEST_v1_0_CWL).resolve().as_uri())
6868
assert cwl_obj10.cwlVersion == "v1.0"
6969

7070
with open(TEST_v1_2_CWL) as cwl_h:
7171
yaml_obj12 = yaml.load(cwl_h)
72-
cwl_obj12 = load_document(yaml_obj12)
72+
cwl_obj12 = load_document(yaml_obj12, Path(TEST_v1_2_CWL).resolve().as_uri())
7373
assert cwl_obj12.cwlVersion == "v1.2"
7474

7575
saved_obj = save([cwl_obj10, cwl_obj12])

0 commit comments

Comments
 (0)