File: test_ext.py

package info (click to toggle)
cwltool 1.0.20181217162649%2Bdfsg-10
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,632 kB
  • sloc: python: 11,008; makefile: 153; sh: 22
file content (218 lines) | stat: -rw-r--r-- 6,799 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
from __future__ import absolute_import

import os
import shutil
import tempfile
import sys
import re
from io import StringIO

import pytest

from cwltool.main import main
import cwltool.process


from .util import get_data, needs_docker, temp_dir, windows_needs_docker, get_main_output


@needs_docker
def test_missing_enable_ext():
    # Require that --enable-ext is provided.
    assert main([get_data('tests/wf/listing_deep.cwl'), get_data('tests/listing-job.yml')]) != 0

@needs_docker
def test_listing_deep():
    params = ["--enable-ext", get_data('tests/wf/listing_deep.cwl'),
              get_data('tests/listing-job.yml')]
    assert main(params) == 0

@needs_docker
def test_listing_shallow():
    # This fails on purpose, because it tries to access listing in a subdirectory
    # the same way that listing_deep does, but it shouldn't be expanded.
    params = ["--enable-ext", get_data('tests/wf/listing_shallow.cwl'),
              get_data('tests/listing-job.yml')]
    assert main(params) != 0

@needs_docker
def test_listing_none():
    # This fails on purpose, because it tries to access listing but it shouldn't be there.
    params = ["--enable-ext", get_data('tests/wf/listing_none.cwl'),
              get_data('tests/listing-job.yml')]
    assert main(params) != 0

@needs_docker
def test_listing_v1_0():
    # Default behavior in 1.0 is deep expansion.
    assert main([get_data('tests/wf/listing_v1_0.cwl'), get_data('tests/listing-job.yml')]) == 0

@pytest.mark.skip(reason="This is not the default behaviour yet")
@needs_docker
def test_listing_v1_1():
    # Default behavior in 1.1 will be no expansion
    assert main([get_data('tests/wf/listing_v1_1.cwl'), get_data('tests/listing-job.yml')]) != 0

@needs_docker
def test_double_overwrite(tmpdir):
    try:
        tmp = tempfile.mkdtemp()
        tmp_name = os.path.join(tmp, "value")

        before_value, expected_value = "1", "3"

        with open(tmp_name, "w") as f:
            f.write(before_value)

        assert main(["--enable-ext", "--outdir", str(tmpdir),
                     get_data('tests/wf/mut2.cwl'), "-a", tmp_name]) == 0

        with open(tmp_name, "r") as f:
            actual_value = f.read()

        assert actual_value == expected_value
    finally:
        shutil.rmtree(tmp)

@needs_docker
def test_disable_file_overwrite_without_ext():
    try:
        tmp = tempfile.mkdtemp()
        out = tempfile.mkdtemp()

        tmp_name = os.path.join(tmp, "value")
        out_name = os.path.join(out, "value")

        before_value, expected_value = "1", "2"

        with open(tmp_name, "w") as f:
            f.write(before_value)

        assert main(["--outdir", out, get_data('tests/wf/updateval.cwl'), "-r", tmp_name]) == 0

        with open(tmp_name, "r") as f:
            tmp_value = f.read()
        with open(out_name, "r") as f:
            out_value = f.read()

        assert tmp_value == before_value
        assert out_value == expected_value
    finally:
        shutil.rmtree(tmp)
        shutil.rmtree(out)

@needs_docker
def test_disable_dir_overwrite_without_ext():
    try:
        tmp = tempfile.mkdtemp()
        out = tempfile.mkdtemp()

        assert main(["--outdir", out, get_data('tests/wf/updatedir.cwl'), "-r", tmp]) == 0

        assert not os.listdir(tmp)
        assert os.listdir(out)
    finally:
        shutil.rmtree(tmp)
        shutil.rmtree(out)

@needs_docker
def test_disable_file_creation_in_outdir_with_ext():
    try:
        tmp = tempfile.mkdtemp()
        out = tempfile.mkdtemp()

        tmp_name = os.path.join(tmp, "value")
        out_name = os.path.join(out, "value")

        before_value, expected_value = "1", "2"

        with open(tmp_name, "w") as f:
            f.write(before_value)

        params = ["--enable-ext", "--leave-outputs", "--outdir",
                  out, get_data('tests/wf/updateval_inplace.cwl'), "-r", tmp_name]
        assert main(params) == 0

        with open(tmp_name, "r") as f:
            tmp_value = f.read()

        assert tmp_value == expected_value
        assert not os.path.exists(out_name)
    finally:
        shutil.rmtree(tmp)
        shutil.rmtree(out)

@needs_docker
def test_disable_dir_creation_in_outdir_with_ext():
    try:
        tmp = tempfile.mkdtemp()
        out = tempfile.mkdtemp()
        params = ["--enable-ext", "--leave-outputs", "--outdir",
                  out, get_data('tests/wf/updatedir_inplace.cwl'), "-r", tmp]
        assert main(params) == 0

        assert os.listdir(tmp)
        assert not os.listdir(out)
    finally:
        shutil.rmtree(tmp)
        shutil.rmtree(out)

@needs_docker
def test_write_write_conflict():
    with temp_dir('tmp') as tmp:
        tmp = tempfile.mkdtemp()
        tmp_name = os.path.join(tmp, "value")

        before_value, expected_value = "1", "2"

        with open(tmp_name, "w") as f:
            f.write(before_value)

        assert main(["--enable-ext", get_data('tests/wf/mut.cwl'), "-a", tmp_name]) != 0

        with open(tmp_name, "r") as f:
            tmp_value = f.read()

        assert tmp_value == expected_value

@pytest.mark.skip(reason="This test is non-deterministic")
def test_read_write_conflict():
    with temp_dir('tmp') as tmp:
        tmp = tempfile.mkdtemp()
        tmp_name = os.path.join(tmp, "value")

        with open(tmp_name, "w") as f:
            f.write("1")

        assert main(["--enable-ext", get_data('tests/wf/mut3.cwl'), "-a", tmp_name]) != 0

@needs_docker
def test_require_prefix_networkaccess():
    assert main(["--enable-ext", get_data('tests/wf/networkaccess.cwl')]) == 0
    assert main([get_data('tests/wf/networkaccess.cwl')]) != 0
    assert main(["--enable-ext", get_data('tests/wf/networkaccess-fail.cwl')]) != 0

@needs_docker
def test_require_prefix_workreuse(tmpdir):
    assert main(["--enable-ext", '--outdir', str(tmpdir), get_data('tests/wf/workreuse.cwl')]) == 0
    assert main([get_data('tests/wf/workreuse.cwl')]) != 0
    assert main(["--enable-ext", get_data('tests/wf/workreuse-fail.cwl')]) != 0

@windows_needs_docker
def test_require_prefix_timelimit():
    assert main(["--enable-ext", get_data('tests/wf/timelimit.cwl')]) == 0
    assert main([get_data('tests/wf/timelimit.cwl')]) != 0
    assert main(["--enable-ext", get_data('tests/wf/timelimit-fail.cwl')]) != 0

def test_warn_large_inputs():
    was = cwltool.process.FILE_COUNT_WARNING
    try:
        stream = StringIO()

        cwltool.process.FILE_COUNT_WARNING = 3
        main([get_data('tests/wf/listing_v1_0.cwl'), get_data('tests/listing2-job.yml')],
             stderr=stream)

        assert "Recursive directory listing has resulted in a large number of File objects" in re.sub("\n  *", " ", stream.getvalue())
    finally:
        cwltool.process.FILE_COUNT_WARNING = was