Skip to content

Commit 07b295e

Browse files
committed
maintenance: remove unittest from test_dependencies and test_ext
Also added some code in util to clean up tests, also in test_ext
1 parent 72e44b3 commit 07b295e

File tree

4 files changed

+130
-144
lines changed

4 files changed

+130
-144
lines changed

tests/test_dependencies.py

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,33 @@
1-
from __future__ import absolute_import
1+
import pytest
22

33
import pytest
44

55
from cwltool.utils import onWindows
66

7-
from .test_examples import TestCmdLine
8-
from .util import get_data, needs_docker
7+
from .util import get_data, get_main_output, needs_docker
8+
99

1010
try:
11-
from galaxy.tools.deps.requirements import ToolRequirement, ToolRequirements
1211
from galaxy.tools import deps
1312
except ImportError:
1413
deps = None
1514

16-
class TestBetaDependenciesResolver(TestCmdLine):
17-
18-
@needs_docker
19-
def test_biocontainers(self):
20-
if not deps:
21-
pytest.skip("galaxy-lib is not installed.")
22-
wflow = get_data("tests/seqtk_seq.cwl")
23-
job = get_data("tests/seqtk_seq_job.json")
24-
error_code, stdout, stderr = self.get_main_output(
25-
["--beta-use-biocontainers", wflow, job])
26-
print(stderr)
27-
print(stdout)
28-
assert error_code is 0
29-
30-
def test_bioconda(self):
31-
if onWindows() or not deps:
32-
pytest.skip("bioconda currently not working on MS Windows.")
33-
elif not deps:
34-
pytest.skip("galaxy-lib is not installed.")
35-
wflow = get_data("tests/seqtk_seq.cwl")
36-
job = get_data("tests/seqtk_seq_job.json")
37-
error_code, stdout, stderr = self.get_main_output(
38-
["--beta-conda-dependencies", "--debug", wflow, job])
39-
print(stderr)
40-
print(stdout)
41-
assert error_code is 0
15+
@needs_docker
16+
@pytest.mark.skipif(not deps, reason="galaxy-lib is not installed")
17+
def test_biocontainers():
18+
wflow = get_data("tests/seqtk_seq.cwl")
19+
job = get_data("tests/seqtk_seq_job.json")
20+
error_code, _, _ = get_main_output(
21+
["--beta-use-biocontainers", wflow, job])
22+
23+
assert error_code == 0
24+
25+
@pytest.mark.skipif(onWindows(), reason="bioconda currently not working on MS Windows")
26+
@pytest.mark.skipif(not deps, reason="galaxy-lib is not installed")
27+
def test_bioconda():
28+
wflow = get_data("tests/seqtk_seq.cwl")
29+
job = get_data("tests/seqtk_seq_job.json")
30+
error_code, _, stderr = get_main_output(
31+
["--beta-conda-dependencies", "--debug", wflow, job])
32+
33+
assert error_code == 0, stderr

tests/test_examples.py

Lines changed: 69 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import os
44
import shutil
55
import sys
6-
import tempfile
7-
import unittest
86
from io import BytesIO, StringIO
97
import pytest
108

@@ -19,10 +17,12 @@
1917
from cwltool.context import RuntimeContext
2018
from cwltool.errors import WorkflowException
2119
from cwltool.main import main
22-
from cwltool.utils import onWindows, subprocess
20+
from cwltool.utils import onWindows
21+
22+
from .util import (get_data, get_main_output, get_windows_safe_factory, needs_docker,
23+
needs_singularity, temp_dir, windows_needs_docker)
24+
2325

24-
from .util import (get_data, get_windows_safe_factory, needs_docker,
25-
needs_singularity, windows_needs_docker)
2626
try:
2727
reload
2828
except: # pylint: disable=bare-except
@@ -349,13 +349,11 @@ def test_dedupe():
349349

350350
record = {
351351
'fields': [
352-
{
353-
'type': {'items': 'string', 'type': 'array'},
354-
'name': u'file:///home/chapmanb/drive/work/cwl/test_bcbio_cwl/run_info-cwl-workflow/wf-variantcall.cwl#vc_rec/vc_rec/description'
352+
{'type': {'items': 'string', 'type': 'array'},
353+
'name': u'file:///home/chapmanb/drive/work/cwl/test_bcbio_cwl/run_info-cwl-workflow/wf-variantcall.cwl#vc_rec/vc_rec/description'
355354
},
356-
{
357-
'type': {'items': 'File', 'type': 'array'},
358-
'name': u'file:///home/chapmanb/drive/work/cwl/test_bcbio_cwl/run_info-cwl-workflow/wf-variantcall.cwl#vc_rec/vc_rec/vrn_file'
355+
{'type': {'items': 'File', 'type': 'array'},
356+
'name': u'file:///home/chapmanb/drive/work/cwl/test_bcbio_cwl/run_info-cwl-workflow/wf-variantcall.cwl#vc_rec/vc_rec/vrn_file'
359357
}],
360358
'type': 'record',
361359
'name': u'file:///home/chapmanb/drive/work/cwl/test_bcbio_cwl/run_info-cwl-workflow/wf-variantcall.cwl#vc_rec/vc_rec'
@@ -394,7 +392,7 @@ def test_dedupe():
394392

395393
@pytest.mark.parametrize('name, source, sink, expected', source_to_sink)
396394
def test_compare_types(name, source, sink, expected):
397-
assert cwltool.workflow.can_assign_src_to_sink(source, sink) == expected
395+
assert cwltool.workflow.can_assign_src_to_sink(source, sink) == expected, name
398396

399397
source_to_sink_strict = [
400398
('0',
@@ -423,7 +421,7 @@ def test_compare_types(name, source, sink, expected):
423421

424422
@pytest.mark.parametrize('name, source, sink, expected', source_to_sink_strict)
425423
def test_compare_types_strict(name, source, sink, expected):
426-
assert cwltool.workflow.can_assign_src_to_sink(source, sink, strict=True) == expected
424+
assert cwltool.workflow.can_assign_src_to_sink(source, sink, strict=True) == expected, name
427425

428426
typechecks = [
429427
(['string', 'int'], ['string', 'int', 'null'],
@@ -618,121 +616,94 @@ def test_var_spool_cwl_checker3():
618616
def test_print_dot():
619617
assert main(["--print-dot", get_data('tests/wf/revsort.cwl')]) == 0
620618

621-
class TestCmdLine(unittest.TestCase):
622-
def get_main_output(self, new_args):
623-
process = subprocess.Popen(
624-
[sys.executable, "-m", "cwltool"] + new_args,
625-
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
626-
627-
stdout, stderr = process.communicate()
628-
return process.returncode, stdout.decode('utf-8'), stderr.decode('utf-8')
629-
630-
631-
class TestJsConsole(TestCmdLine):
632-
633-
def test_js_console_cmd_line_tool(self):
634-
for test_file in ("js_output.cwl", "js_output_workflow.cwl"):
635-
error_code, _, stderr = self.get_main_output(
636-
["--js-console", "--no-container", get_data("tests/wf/" + test_file)])
619+
def test_js_console_cmd_line_tool():
620+
for test_file in ("js_output.cwl", "js_output_workflow.cwl"):
621+
error_code, _, stderr = get_main_output(
622+
["--js-console", "--no-container", get_data("tests/wf/" + test_file)])
637623

638-
assert "[log] Log message" in stderr
639-
assert "[err] Error message" in stderr
624+
assert "[log] Log message" in stderr
625+
assert "[err] Error message" in stderr
640626

641-
assert error_code == 0, stderr
627+
assert error_code == 0, stderr
642628

643-
def test_no_js_console(self):
644-
for test_file in ("js_output.cwl", "js_output_workflow.cwl"):
645-
error_code, _, stderr = self.get_main_output(
646-
["--no-container", get_data("tests/wf/" + test_file)])
629+
def test_no_js_console():
630+
for test_file in ("js_output.cwl", "js_output_workflow.cwl"):
631+
_, _, stderr = get_main_output(
632+
["--no-container", get_data("tests/wf/" + test_file)])
647633

648-
assert "[log] Log message" not in stderr
649-
assert "[err] Error message" not in stderr
634+
assert "[log] Log message" not in stderr
635+
assert "[err] Error message" not in stderr
650636

651637
@needs_docker
652-
class TestRecordContainerId(TestCmdLine):
653-
def test_record_container_id(self):
654-
test_file = "cache_test_workflow.cwl"
655-
cid_dir = tempfile.mkdtemp("cwltool_test_cid")
656-
error_code, _, stderr = self.get_main_output(
638+
def test_record_container_id():
639+
test_file = "cache_test_workflow.cwl"
640+
with temp_dir('cidr') as cid_dir:
641+
error_code, _, stderr = get_main_output(
657642
["--record-container-id", "--cidfile-dir", cid_dir,
658643
get_data("tests/wf/" + test_file)])
659644
assert "completed success" in stderr
660645
assert error_code == 0
661646
assert len(os.listdir(cid_dir)) == 2
662-
shutil.rmtree(cid_dir)
663647

664648

665649
@needs_docker
666-
class TestCache(TestCmdLine):
667-
def setUp(self):
668-
self.cache_dir = tempfile.mkdtemp("cwltool_cache")
669-
670-
def tearDown(self):
671-
shutil.rmtree(self.cache_dir)
672-
673-
def test_wf_without_container(self):
674-
test_file = "hello-workflow.cwl"
675-
error_code, _, stderr = self.get_main_output(
676-
["--cachedir", self.cache_dir,
650+
def test_wf_without_container():
651+
test_file = "hello-workflow.cwl"
652+
with temp_dir("cwltool_cache") as cache_dir:
653+
error_code, _, stderr = get_main_output(
654+
["--cachedir", cache_dir,
677655
get_data("tests/wf/" + test_file),
678656
"--usermessage",
679657
"hello"]
680658
)
681659

682-
assert "completed success" in stderr
683-
assert error_code == 0
660+
assert "completed success" in stderr
661+
assert error_code == 0
684662

685-
def test_issue_740_fixed(self):
686-
test_file = "cache_test_workflow.cwl"
687-
error_code, _, stderr = self.get_main_output(
688-
["--cachedir", self.cache_dir, get_data("tests/wf/" + test_file)])
663+
@needs_docker
664+
def test_issue_740_fixed():
665+
test_file = "cache_test_workflow.cwl"
666+
with temp_dir("cwltool_cache") as cache_dir:
667+
error_code, _, stderr = get_main_output(
668+
["--cachedir", cache_dir, get_data("tests/wf/" + test_file)])
689669

690670
assert "completed success" in stderr
691671
assert error_code == 0
692672

693-
error_code, stdout, stderr = self.get_main_output(
694-
["--cachedir", self.cache_dir, get_data("tests/wf/" + test_file)])
673+
error_code, _, stderr = get_main_output(
674+
["--cachedir", cache_dir, get_data("tests/wf/" + test_file)])
695675

696676
assert "Output of job will be cached in" not in stderr
697677
assert error_code == 0
698678

699679

700680
@needs_docker
701-
class TestChecksum(TestCmdLine):
702-
def test_compute_checksum(self):
703-
runtime_context = RuntimeContext()
704-
runtime_context.compute_checksum = True
705-
runtime_context.use_container = onWindows()
706-
factory = cwltool.factory.Factory(runtime_context=runtime_context)
707-
echo = factory.make(get_data("tests/wf/cat-tool.cwl"))
708-
output = echo(
709-
file1={"class": "File",
710-
"location": get_data("tests/wf/whale.txt")},
711-
reverse=False)
712-
assert output['output']["checksum"] == "sha1$327fc7aedf4f6b69a42a7c8b808dc5a7aff61376"
713-
714-
def test_no_compute_checksum(self):
715-
test_file = "tests/wf/wc-tool.cwl"
716-
job_file = "tests/wf/wc-job.json"
717-
error_code, stdout, stderr = self.get_main_output(
718-
["--no-compute-checksum", get_data(test_file), get_data(job_file)])
719-
assert "completed success" in stderr
720-
assert error_code == 0
721-
assert "checksum" not in stdout
681+
def test_compute_checksum():
682+
runtime_context = RuntimeContext()
683+
runtime_context.compute_checksum = True
684+
runtime_context.use_container = onWindows()
685+
factory = cwltool.factory.Factory(runtime_context=runtime_context)
686+
echo = factory.make(get_data("tests/wf/cat-tool.cwl"))
687+
output = echo(
688+
file1={"class": "File",
689+
"location": get_data("tests/wf/whale.txt")},
690+
reverse=False)
691+
assert output['output']["checksum"] == "sha1$327fc7aedf4f6b69a42a7c8b808dc5a7aff61376"
722692

693+
@needs_docker
694+
def test_no_compute_checksum():
695+
test_file = "tests/wf/wc-tool.cwl"
696+
job_file = "tests/wf/wc-job.json"
697+
error_code, stdout, stderr = get_main_output(
698+
["--no-compute-checksum", get_data(test_file), get_data(job_file)])
699+
assert "completed success" in stderr
700+
assert error_code == 0
701+
assert "checksum" not in stdout
723702

724703
@needs_singularity
725-
class TestChecksumSingularity(TestCmdLine):
726-
727-
def setUp(self):
728-
self.cache_dir = tempfile.mkdtemp("cwltool_cache")
729-
730-
def tearDown(self):
731-
shutil.rmtree(self.cache_dir)
732-
733-
def test_singularity_workflow(self):
734-
error_code, _, stderr = self.get_main_output(
735-
['--singularity', '--default-container', 'debian',
736-
get_data("tests/wf/hello-workflow.cwl"), "--usermessage", "hello"])
737-
assert "completed success" in stderr
738-
assert error_code == 0
704+
def test_singularity_workflow():
705+
error_code, _, stderr = get_main_output(
706+
['--singularity', '--default-container', 'debian',
707+
get_data("tests/wf/hello-workflow.cwl"), "--usermessage", "hello"])
708+
assert "completed success" in stderr
709+
assert error_code == 0

tests/test_ext.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from cwltool.main import main
1010

11-
from .util import get_data, needs_docker, windows_needs_docker
11+
from .util import get_data, needs_docker, temp_dir, windows_needs_docker
1212

1313

1414
@needs_docker
@@ -18,18 +18,24 @@ def test_missing_enable_ext():
1818

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

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

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

3440
@needs_docker
3541
def test_listing_v1_0():
@@ -117,7 +123,9 @@ def test_disable_file_creation_in_outdir_with_ext():
117123
with open(tmp_name, "w") as f:
118124
f.write(before_value)
119125

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

122130
with open(tmp_name, "r") as f:
123131
tmp_value = f.read()
@@ -133,8 +141,9 @@ def test_disable_dir_creation_in_outdir_with_ext():
133141
try:
134142
tmp = tempfile.mkdtemp()
135143
out = tempfile.mkdtemp()
136-
137-
assert main(["--enable-ext", "--leave-outputs", "--outdir", out, get_data('tests/wf/updatedir_inplace.cwl'), "-r", tmp]) == 0
144+
params = ["--enable-ext", "--leave-outputs", "--outdir",
145+
out, get_data('tests/wf/updatedir_inplace.cwl'), "-r", tmp]
146+
assert main(params) == 0
138147

139148
assert os.listdir(tmp)
140149
assert not os.listdir(out)
@@ -144,7 +153,7 @@ def test_disable_dir_creation_in_outdir_with_ext():
144153

145154
@needs_docker
146155
def test_write_write_conflict():
147-
try:
156+
with temp_dir('tmp') as tmp:
148157
tmp = tempfile.mkdtemp()
149158
tmp_name = os.path.join(tmp, "value")
150159

@@ -159,21 +168,17 @@ def test_write_write_conflict():
159168
tmp_value = f.read()
160169

161170
assert tmp_value == expected_value
162-
finally:
163-
shutil.rmtree(tmp)
164171

165172
@pytest.mark.skip(reason="This test is non-deterministic")
166173
def test_read_write_conflict():
167-
try:
174+
with temp_dir('tmp') as tmp:
168175
tmp = tempfile.mkdtemp()
169176
tmp_name = os.path.join(tmp, "value")
170177

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

174181
assert main(["--enable-ext", get_data('tests/wf/mut3.cwl'), "-a", tmp_name]) != 0
175-
finally:
176-
shutil.rmtree(tmp)
177182

178183
@needs_docker
179184
def test_require_prefix_networkaccess():

0 commit comments

Comments
 (0)