|
| 1 | +"""Test that files marked as 'streamable' when 'streaming_allowed' can be named pipes.""" |
| 2 | +import os |
| 3 | + |
| 4 | +import pytest |
| 5 | +from pathlib import Path |
| 6 | +from typing import cast |
| 7 | + |
| 8 | +from ruamel.yaml.comments import CommentedMap |
| 9 | +from schema_salad.sourceline import cmap |
| 10 | + |
| 11 | +from cwltool.command_line_tool import CommandLineTool |
| 12 | +from cwltool.context import LoadingContext, RuntimeContext |
| 13 | +from cwltool.errors import WorkflowException |
| 14 | +from cwltool.job import JobBase |
| 15 | +from cwltool.update import INTERNAL_VERSION |
| 16 | +from cwltool.utils import CWLObjectType |
| 17 | +from .util import get_data |
| 18 | + |
| 19 | +toolpath_object = cast( |
| 20 | + CommentedMap, |
| 21 | + cmap( |
| 22 | + { |
| 23 | + "cwlVersion": INTERNAL_VERSION, |
| 24 | + "class": "CommandLineTool", |
| 25 | + "inputs": [ |
| 26 | + { |
| 27 | + "type": "File", |
| 28 | + "id": "inp", |
| 29 | + "streamable": True, |
| 30 | + } |
| 31 | + ], |
| 32 | + "outputs": [], |
| 33 | + "requirements": [], |
| 34 | + } |
| 35 | + ), |
| 36 | +) |
| 37 | + |
| 38 | +loading_context = LoadingContext( |
| 39 | + { |
| 40 | + "metadata": { |
| 41 | + "cwlVersion": INTERNAL_VERSION, |
| 42 | + "http://commonwl.org/cwltool#original_cwlVersion": INTERNAL_VERSION, |
| 43 | + } |
| 44 | + } |
| 45 | +) |
| 46 | + |
| 47 | + |
| 48 | +def test_regular_file() -> None: |
| 49 | + """Test that regular files do not raise any exception when they are checked in job._setup.""" |
| 50 | + clt = CommandLineTool( |
| 51 | + toolpath_object, |
| 52 | + loading_context, |
| 53 | + ) |
| 54 | + runtime_context = RuntimeContext() |
| 55 | + |
| 56 | + joborder: CWLObjectType = { |
| 57 | + "inp": { |
| 58 | + "class": "File", |
| 59 | + "location": get_data("tests/wf/whale.txt"), |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + job = next(clt.job(joborder, None, runtime_context)) |
| 64 | + assert isinstance(job, JobBase) |
| 65 | + |
| 66 | + job._setup(runtime_context) |
| 67 | + |
| 68 | + |
| 69 | +streaming = [ |
| 70 | + (True, True, False), |
| 71 | + (True, False, True), |
| 72 | + (False, True, True), |
| 73 | + (False, False, True), |
| 74 | +] |
| 75 | + |
| 76 | + |
| 77 | +@pytest.mark.parametrize("streamable,streaming_allowed,raise_exception", streaming) |
| 78 | +def test_input_can_be_named_pipe( |
| 79 | + tmp_path: Path, streamable: bool, streaming_allowed: bool, raise_exception: bool |
| 80 | +) -> None: |
| 81 | + """Test that input can be a named pipe.""" |
| 82 | + clt = CommandLineTool( |
| 83 | + toolpath_object, |
| 84 | + loading_context, |
| 85 | + ) |
| 86 | + |
| 87 | + runtime_context = RuntimeContext() |
| 88 | + runtime_context.streaming_allowed = streaming_allowed |
| 89 | + |
| 90 | + path = tmp_path / "tmp" |
| 91 | + os.mkfifo(path) |
| 92 | + |
| 93 | + joborder: CWLObjectType = { |
| 94 | + "inp": { |
| 95 | + "class": "File", |
| 96 | + "location": str(path), |
| 97 | + "streamable": streamable, |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + job = next(clt.job(joborder, None, runtime_context)) |
| 102 | + assert isinstance(job, JobBase) |
| 103 | + |
| 104 | + if raise_exception: |
| 105 | + with pytest.raises(WorkflowException): |
| 106 | + job._setup(runtime_context) |
| 107 | + else: |
| 108 | + job._setup(runtime_context) |
0 commit comments