|
3 | 3 | import os
|
4 | 4 | import shutil
|
5 | 5 | import sys
|
6 |
| -import tempfile |
7 |
| -import unittest |
8 | 6 | from io import BytesIO, StringIO
|
9 | 7 | import pytest
|
10 | 8 |
|
|
19 | 17 | from cwltool.context import RuntimeContext
|
20 | 18 | from cwltool.errors import WorkflowException
|
21 | 19 | 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 | + |
23 | 25 |
|
24 |
| -from .util import (get_data, get_windows_safe_factory, needs_docker, |
25 |
| - needs_singularity, windows_needs_docker) |
26 | 26 | try:
|
27 | 27 | reload
|
28 | 28 | except: # pylint: disable=bare-except
|
@@ -349,13 +349,11 @@ def test_dedupe():
|
349 | 349 |
|
350 | 350 | record = {
|
351 | 351 | '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' |
355 | 354 | },
|
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' |
359 | 357 | }],
|
360 | 358 | 'type': 'record',
|
361 | 359 | '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():
|
394 | 392 |
|
395 | 393 | @pytest.mark.parametrize('name, source, sink, expected', source_to_sink)
|
396 | 394 | 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 |
398 | 396 |
|
399 | 397 | source_to_sink_strict = [
|
400 | 398 | ('0',
|
@@ -423,7 +421,7 @@ def test_compare_types(name, source, sink, expected):
|
423 | 421 |
|
424 | 422 | @pytest.mark.parametrize('name, source, sink, expected', source_to_sink_strict)
|
425 | 423 | 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 |
427 | 425 |
|
428 | 426 | typechecks = [
|
429 | 427 | (['string', 'int'], ['string', 'int', 'null'],
|
@@ -618,121 +616,94 @@ def test_var_spool_cwl_checker3():
|
618 | 616 | def test_print_dot():
|
619 | 617 | assert main(["--print-dot", get_data('tests/wf/revsort.cwl')]) == 0
|
620 | 618 |
|
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)]) |
637 | 623 |
|
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 |
640 | 626 |
|
641 |
| - assert error_code == 0, stderr |
| 627 | + assert error_code == 0, stderr |
642 | 628 |
|
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)]) |
647 | 633 |
|
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 |
650 | 636 |
|
651 | 637 | @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( |
657 | 642 | ["--record-container-id", "--cidfile-dir", cid_dir,
|
658 | 643 | get_data("tests/wf/" + test_file)])
|
659 | 644 | assert "completed success" in stderr
|
660 | 645 | assert error_code == 0
|
661 | 646 | assert len(os.listdir(cid_dir)) == 2
|
662 |
| - shutil.rmtree(cid_dir) |
663 | 647 |
|
664 | 648 |
|
665 | 649 | @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, |
677 | 655 | get_data("tests/wf/" + test_file),
|
678 | 656 | "--usermessage",
|
679 | 657 | "hello"]
|
680 | 658 | )
|
681 | 659 |
|
682 |
| - assert "completed success" in stderr |
683 |
| - assert error_code == 0 |
| 660 | + assert "completed success" in stderr |
| 661 | + assert error_code == 0 |
684 | 662 |
|
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)]) |
689 | 669 |
|
690 | 670 | assert "completed success" in stderr
|
691 | 671 | assert error_code == 0
|
692 | 672 |
|
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)]) |
695 | 675 |
|
696 | 676 | assert "Output of job will be cached in" not in stderr
|
697 | 677 | assert error_code == 0
|
698 | 678 |
|
699 | 679 |
|
700 | 680 | @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" |
722 | 692 |
|
| 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 |
723 | 702 |
|
724 | 703 | @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 |
0 commit comments