|
1 | 1 | import urllib.parse |
| 2 | +from io import BytesIO |
2 | 3 | from pathlib import Path |
3 | | -from typing import cast |
| 4 | +from typing import IO, Any, List, cast |
4 | 5 |
|
5 | 6 | import pytest |
6 | 7 | from ruamel.yaml.comments import CommentedMap |
|
9 | 10 | from cwltool.command_line_tool import CommandLineTool |
10 | 11 | from cwltool.context import LoadingContext, RuntimeContext |
11 | 12 | from cwltool.main import main |
| 13 | +from cwltool.stdfsaccess import StdFsAccess |
12 | 14 | from cwltool.update import INTERNAL_VERSION |
13 | 15 | from cwltool.utils import CWLObjectType |
14 | 16 |
|
@@ -105,6 +107,26 @@ def test_unicode_in_output_files(tmp_path: Path, filename: str) -> None: |
105 | 107 | assert main(params) == 0 |
106 | 108 |
|
107 | 109 |
|
| 110 | +class TestFsAccess(StdFsAccess): |
| 111 | + """Stub fs access object that doesn't rely on the filesystem.""" |
| 112 | + |
| 113 | + def glob(self, pattern: str) -> List[str]: |
| 114 | + """glob.""" |
| 115 | + return [pattern] |
| 116 | + |
| 117 | + def open(self, fn: str, mode: str) -> IO[Any]: |
| 118 | + """open.""" |
| 119 | + return BytesIO(b"aoeu") |
| 120 | + |
| 121 | + def isfile(self, fn: str) -> bool: |
| 122 | + """isfile.""" |
| 123 | + return True |
| 124 | + |
| 125 | + def size(self, fn: str) -> int: |
| 126 | + """size.""" |
| 127 | + return 4 |
| 128 | + |
| 129 | + |
108 | 130 | def test_clt_returns_specialchar_names(tmp_path: Path) -> None: |
109 | 131 | """Confirm that special characters in filenames do not cause problems.""" |
110 | 132 | loading_context = LoadingContext( |
@@ -167,3 +189,30 @@ def test_clt_returns_specialchar_names(tmp_path: Path) -> None: |
167 | 189 | assert result["basename"] == special |
168 | 190 | assert result["nameroot"] == special |
169 | 191 | assert str(result["location"]).endswith(urllib.parse.quote(special)) |
| 192 | + |
| 193 | + # Now test when outdir is a URI, make sure it doesn't get |
| 194 | + # incorrectly quoted as a file. |
| 195 | + builder = clt._init_job({}, RuntimeContext()) |
| 196 | + builder.pathmapper = clt.make_path_mapper( |
| 197 | + builder.files, builder.stagedir, RuntimeContext(), True |
| 198 | + ) |
| 199 | + builder.outdir = "/var/spool/cwl" |
| 200 | + fs_access = TestFsAccess("") |
| 201 | + |
| 202 | + result = cast( |
| 203 | + CWLObjectType, |
| 204 | + clt.collect_output( |
| 205 | + output_schema, |
| 206 | + builder, |
| 207 | + "keep:ae755cd1b3cff63152ff4200f4dea7e9+52", |
| 208 | + fs_access, |
| 209 | + ), |
| 210 | + ) |
| 211 | + |
| 212 | + assert result["class"] == "File" |
| 213 | + assert result["basename"] == special |
| 214 | + assert result["nameroot"] == special |
| 215 | + assert ( |
| 216 | + result["location"] |
| 217 | + == "keep:ae755cd1b3cff63152ff4200f4dea7e9+52/%3A%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D" |
| 218 | + ) |
0 commit comments