Example #1
0
def test_packed_workflow_execution(wf_path, job_path, namespaced, tmpdir):
    loadingContext = LoadingContext()
    loadingContext.resolver = tool_resolver
    loadingContext, workflowobj, uri = fetch_document(
        get_data(wf_path), loadingContext)
    loadingContext.do_update = False
    loadingContext, uri = resolve_and_validate_document(
        loadingContext, workflowobj, uri)
    processobj = loadingContext.loader.resolve_ref(uri)[0]
    packed = json.loads(print_pack(loadingContext.loader, processobj, uri, loadingContext.metadata))

    assert not namespaced or "$namespaces" in packed

    wf_packed_handle, wf_packed_path = tempfile.mkstemp()
    with open(wf_packed_path, 'w') as temp_file:
        json.dump(packed, temp_file)

    normal_output = StringIO()
    packed_output = StringIO()

    normal_params = ['--outdir', str(tmpdir), get_data(wf_path), get_data(job_path)]
    packed_params = ['--outdir', str(tmpdir), '--debug', get_data(wf_packed_path), get_data(job_path)]

    assert main(normal_params, stdout=normal_output) == 0
    assert main(packed_params, stdout=packed_output) == 0

    assert json.loads(packed_output.getvalue()) == json.loads(normal_output.getvalue())

    os.close(wf_packed_handle)
    os.remove(wf_packed_path)
Example #2
0
 def test_trick_scandeps(self):
     if sys.version_info[0] < 3:
         stream = BytesIO()
     else:
         stream = StringIO()
     main(["--print-deps", "--debug", get_data("tests/wf/trick_defaults.cwl")], stdout=stream)
     self.assertNotEquals(json.loads(stream.getvalue())["secondaryFiles"][0]["location"][:2], "_:")
Example #3
0
def test_packed_workflow_execution(wf_path, job_path, namespaced, tmpdir):
    load_tool.loaders = {}

    document_loader, workflowobj, uri = fetch_document(
        get_data(wf_path), resolver=tool_resolver)

    document_loader, _, processobj, metadata, uri = validate_document(
        document_loader, workflowobj, uri, [], {})

    packed = json.loads(print_pack(document_loader, processobj, uri, metadata))

    assert not namespaced or "$namespaces" in packed

    wf_packed_handle, wf_packed_path = tempfile.mkstemp()
    with open(wf_packed_path, 'w') as temp_file:
        json.dump(packed, temp_file)

    normal_output = StringIO()
    packed_output = StringIO()

    normal_params = ['--outdir', str(tmpdir), get_data(wf_path), get_data(job_path)]
    packed_params = ['--outdir', str(tmpdir), '--debug', get_data(wf_packed_path), get_data(job_path)]

    assert main(normal_params, stdout=normal_output) == 0
    assert main(packed_params, stdout=packed_output) == 0

    assert json.loads(packed_output.getvalue()) == json.loads(normal_output.getvalue())

    os.close(wf_packed_handle)
    os.remove(wf_packed_path)
Example #4
0
 def test_help(self):
     with NamedTemporaryFile() as f:
         f.write(self.script)
         f.flush()
         self.assertEquals(main(["--debug", f.name, '--input',
             get_data('tests/echo.cwl')]), 0)
         self.assertEquals(main(["--debug", f.name, '--input',
             get_data('tests/echo.cwl')]), 0)
Example #5
0
def test_secret_workflow_log_singularity():
    stream = StringIO()
    tmpdir = tempfile.mkdtemp()
    main(["--debug", "--outdir", tmpdir, "--singularity",
          get_data("tests/wf/secret_wf.cwl"), "--pw", "Hoopla!"],
         stderr=stream)

    shutil.rmtree(tmpdir)
    assert "Hoopla!" not in stream.getvalue()
Example #6
0
def test_secret_workflow_log_override():
    stream = StringIO()
    tmpdir = tempfile.mkdtemp()
    main(["--debug", "--outdir", tmpdir, "--enable-ext", "--overrides",
          get_data("tests/wf/override-no-secrets.yml"),
          get_data("tests/wf/secret_wf.cwl"), "--pw", "Hoopla!"],
         stderr=stream)
    shutil.rmtree(tmpdir)

    assert "Hoopla!" in stream.getvalue()
 def test_spaces_in_input_files(self):
     with NamedTemporaryFile() as f:
         f.write(self.script)
         f.flush()
         with NamedTemporaryFile(prefix="test with spaces") as spaces:
             self.assertEquals(
                 main(["--debug", f.name, '--input', spaces.name]), 1)
             self.assertEquals(
                 main(["--debug", "--relax-path-checks", f.name, '--input',
                       spaces.name]), 0)
Example #8
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
def test_spaces_in_input_files(tmpdir):
    try:
        script_file = NamedTemporaryFile(mode='w', delete=False)
        script_file.write(script)
        script_file.flush()
        script_file.close()

        spaces = NamedTemporaryFile(prefix="test with spaces", delete=False)
        spaces.close()

        params = ["--debug", "--outdir", str(tmpdir), script_file.name, '--input', spaces.name]
        assert main(params) == 1
        assert main(["--relax-path-checks"] + params) == 0
    finally:
        os.remove(script_file.name)
        os.remove(spaces.name)
Example #10
0
def test_target_packed():
    """Test --target option with packed workflow schema."""
    test_file = "tests/wf/scatter-wf4.json"
    exit_code = main(['--target', 'out',
                     get_data(test_file),
                     '--inp1', 'INP1', '--inp2', 'INP2'])
    assert exit_code == 0
Example #11
0
def test_wrong_target():
    """Test --target option when value is wrong."""
    test_file = "tests/wf/scatter-wf4.cwl"
    exit_code = main(['--target', 'dummy_target',
                     get_data(test_file),
                     '--inp1', 'INP1', '--inp2', 'INP2'])
    assert exit_code == 1
Example #12
0
def test_overrides_fails(parameters, expected_error):
    load_tool.loaders = {}
    sio = StringIO()

    assert main(parameters, stderr=sio) == 1
    stderr = sio.getvalue()
    assert expected_error in stderr, stderr
Example #13
0
def test_iwdr_permutations_inplace():
    load_tool.loaders = {}
    saved_tempdir = tempfile.tempdir
    with temp_dir() as misc:
        tempfile.tempdir = os.path.realpath(misc)
        with temp_dir() as fifth:
            with temp_dir() as sixth:
                with temp_dir() as seventh:
                    with temp_dir() as eighth:
                        with tempfile.NamedTemporaryFile() as first:
                            with tempfile.NamedTemporaryFile() as second:
                                with tempfile.NamedTemporaryFile() as third:
                                    with tempfile.NamedTemporaryFile() as fourth:
                                        with temp_dir() as outdir:
                                            assert(main(
                                                ['--outdir', outdir,
                                                 '--enable-ext',
                                                 '--overrides',
                                                 get_data("tests/wf/iwdr_permutations_inplace.yml"),
                                                 get_data("tests/wf/iwdr_permutations.cwl"),
                                                 '--first', first.name,
                                                 '--second', second.name,
                                                 '--third', third.name,
                                                 '--fourth', fourth.name,
                                                 '--fifth', fifth,
                                                 '--sixth', sixth,
                                                 '--seventh', seventh,
                                                 '--eighth', eighth]) == 0)
    tempfile.tempdir = saved_tempdir
Example #14
0
def test_iwdr_permutations_singularity_inplace():
    with temp_dir() as fifth:
        with temp_dir() as sixth:
            with temp_dir() as seventh:
                with temp_dir() as eighth:
                    with tempfile.NamedTemporaryFile() as first:
                        with tempfile.NamedTemporaryFile() as second:
                            with tempfile.NamedTemporaryFile() as third:
                                with tempfile.NamedTemporaryFile() as fourth:
                                    with temp_dir() as outdir:
                                        assert(main(
                                            ['--outdir', outdir,
                                             '--singularity',
                                             '--enable-ext',
                                             '--overrides',
                                             get_data("tests/wf/iwdr_permutations_inplace.yml"),
                                             get_data("tests/wf/iwdr_permutations.cwl"),
                                             '--first', first.name,
                                             '--second', second.name,
                                             '--third', third.name,
                                             '--fourth', fourth.name,
                                             '--fifth', fifth,
                                             '--sixth', sixth,
                                             '--seventh', seventh,
                                             '--eighth', eighth]) == 0)
Example #15
0
def test_target():
    load_tool.loaders = {}
    """Test --target option successful."""
    test_file = "tests/wf/scatter-wf4.cwl"
    exit_code = main(['--target', 'out', get_data(test_file),
                     '--inp1', 'INP1', '--inp2', 'INP2'])
    assert exit_code == 0
Example #16
0
def test_read_write_conflict():
    with temp_dir('tmp') as tmp:
        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
Example #17
0
def cwltool(folder, *args):
    new_args = ['--provenance', folder]
    new_args.extend(args)
    # Run within a temporary directory to not pollute git checkout
    with temp_dir("cwltool-run") as tmp_dir:
        with working_directory(tmp_dir):
            status = main(new_args)
            assert status == 0, "Failed: cwltool.main(%r)" % (args)
Example #18
0
def test_disable_dir_overwrite_without_ext():
    with temp_dir() as tmp:
        with temp_dir() as out:

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

            assert not os.listdir(tmp)
            assert os.listdir(out)
 def test_record_help(self):
     with NamedTemporaryFile() as f:
         f.write(self.script3)
         f.flush()
         try:
             self.assertEquals(main([f.name, '--help']), 0)
         except SystemExit as e:
             self.assertEquals(e.code, 0)
Example #20
0
def test_input_deps_cmdline_opts():
    if sys.version_info[0] < 3:
        stream = BytesIO()
    else:
        stream = StringIO()

    main(["--print-input-deps",
          get_data("tests/wf/count-lines1-wf.cwl"),
          "--file1", get_data("tests/wf/whale.txt")], stdout=stream)
    expected = {"class": "File",
                "location": "",
                "format": CWL_IANA,
                "secondaryFiles": [{"class": "File",
                                    "location": "whale.txt",
                                    "basename": "whale.txt",
                                    "nameroot": "whale",
                                    "nameext": ".txt"}]}
    assert json.loads(stream.getvalue()) == expected
Example #21
0
def test_docker_iwdr():
    result_code = main(
        ['--default-container', 'debian',
         get_data("tests/wf/iwdr-entry.cwl"), "--message", "hello"])
    docker_installed = bool(spawn.find_executable('docker'))
    if docker_installed:
        assert result_code == 0
    else:
        assert result_code != 0
Example #22
0
def test_disable_dir_creation_in_outdir_with_ext():
    with temp_dir() as tmp:
        with temp_dir() as out:
            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)
Example #23
0
def test_singularity_iwdr():
    result_code = main(
        ['--singularity', '--default-container', 'debian',
         get_data("tests/wf/iwdr-entry.cwl"), "--message", "hello"])
    singularity_installed = bool(distutils.spawn.find_executable('singularity'))
    if singularity_installed:
        assert result_code == 0
    else:
        assert result_code != 0
 def test_record(self):
     with NamedTemporaryFile() as f:
         f.write(self.script3)
         f.flush()
         try:
             self.assertEquals(main([f.name, '--foo.one', 'README.rst',
             '--foo.two', 'test']), 0)
         except SystemExit as e:
             self.assertEquals(e.code, 0)
Example #25
0
 def test_bool(self):
     with NamedTemporaryFile(mode='w', delete=False) as f:
         f.write(self.script2)
         f.flush()
         f.close()
         try:
             self.assertEquals(main([f.name, '--help']), 0)
         except SystemExit as e:
             self.assertEquals(e.code, 0)
Example #26
0
 def test_record(self):
     with NamedTemporaryFile(mode='w', delete=False) as f:
         f.write(self.script3)
         f.flush()
         f.close()
         try:
             self.assertEquals(main([f.name, '--foo.one',
                 get_data('tests/echo.cwl'), '--foo.two', 'test']), 0)
         except SystemExit as e:
             self.assertEquals(e.code, 0)
Example #27
0
def test_empty_input():
    empty_json = '{}'
    empty_input = StringIO(empty_json)

    with temp_dir() as tmpdir:
        params = ['--outdir', tmpdir, get_data('tests/wf/no-parameters-echo.cwl'), '-']

        try:
            assert main(params, stdin=empty_input) == 0
        except SystemExit as err:
            assert err.code == 0
Example #28
0
    def test_sequencing(self):
        try:
            tmp = tempfile.mkdtemp()
            with open(os.path.join(tmp, "value"), "w") as f:
                f.write("1")

            self.assertEquals(main(["--enable-ext", get_data('tests/wf/mut2.cwl'), "-a", os.path.join(tmp, "value")]), 0)
            with open(os.path.join(tmp, "value"), "r") as f:
                self.assertEquals("3", f.read())
        finally:
            shutil.rmtree(tmp)
Example #29
0
def test_input_deps_cmdline_opts_relative_deps_cwd():
    if sys.version_info[0] < 3:
        stream = BytesIO()
    else:
        stream = StringIO()

    data_path = get_data("tests/wf/whale.txt")
    main(["--print-input-deps", "--relative-deps", "cwd",
          get_data("tests/wf/count-lines1-wf.cwl"),
          "--file1", data_path], stdout=stream)

    goal = {"class": "File",
            "location": "",
            "format": CWL_IANA,
            "secondaryFiles": [{"class": "File",
                                "location": str(
                                    Path(os.path.relpath(
                                        data_path, os.path.curdir))),
                                "basename": "whale.txt",
                                "nameroot": "whale",
                                "nameext": ".txt"}]}
    assert json.loads(stream.getvalue()) == goal
Example #30
0
def run_cwltool(ctx, path, job_path, **kwds):
    if main is None:
        raise Exception("cwltool dependency not found.")

    args = []
    if kwds.get("conformance_test", False):
        args.append("--conformance-test")
    if ctx.verbose:
        args.append("--verbose")

    args.extend([path, job_path])
    ctx.vlog("Calling cwltool with arguments %s" % args)
    return main(args)
Example #31
0
def test_missing_enable_ext():
    # Requires --enable-ext and --enable-dev
    try:
        opt = os.environ.get("CWLTOOL_OPTIONS")

        if "CWLTOOL_OPTIONS" in os.environ:
            del os.environ["CWLTOOL_OPTIONS"]
        assert main(
            [get_data('tests/wf/generator/zing.cwl'), "--zing", "zipper"]) == 1

        assert main([
            "--enable-ext", "--enable-dev",
            get_data('tests/wf/generator/zing.cwl'), "--zing", "zipper"
        ]) == 0

        os.environ["CWLTOOL_OPTIONS"] = "--enable-ext --enable-dev"
        assert main(
            [get_data('tests/wf/generator/zing.cwl'), "--zing", "zipper"]) == 0
    finally:
        if opt is not None:
            os.environ["CWLTOOL_OPTIONS"] = opt
        else:
            del os.environ["CWLTOOL_OPTIONS"]
Example #32
0
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)
Example #33
0
    def test_updateval_inplace(self):
        try:
            tmp = tempfile.mkdtemp()
            with open(os.path.join(tmp, "value"), "w") as f:
                f.write("1")
            out = tempfile.mkdtemp()
            self.assertEquals(main(["--enable-ext", "--leave-outputs", "--outdir", out, get_data('tests/wf/updateval_inplace.cwl'), "-r", os.path.join(tmp, "value")]), 0)

            with open(os.path.join(tmp, "value"), "r") as f:
                self.assertEquals("2", f.read())
            self.assertFalse(os.path.exists(os.path.join(out, "value")))
        finally:
            shutil.rmtree(tmp)
            shutil.rmtree(out)
Example #34
0
def test_spaces_in_input_files(tmpdir: py.path.local) -> None:
    try:
        script_file = NamedTemporaryFile(mode="w", delete=False)
        script_file.write(script)
        script_file.flush()
        script_file.close()

        spaces = NamedTemporaryFile(prefix="test with spaces", delete=False)
        spaces.close()

        params = [
            "--debug",
            "--outdir",
            str(tmpdir),
            script_file.name,
            "--input",
            spaces.name,
        ]
        assert main(params) == 1
        assert main(["--relax-path-checks"] + params) == 0
    finally:
        os.remove(script_file.name)
        os.remove(spaces.name)
def test_empty_input():
    empty_json = '{}'
    empty_input = StringIO(empty_json)

    with temp_dir() as tmpdir:
        params = [
            '--outdir', tmpdir,
            get_data('tests/wf/no-parameters-echo.cwl'), '-'
        ]

        try:
            assert main(params, stdin=empty_input) == 0
        except SystemExit as err:
            assert err.code == 0
Example #36
0
def test_cwltool_options() -> None:
    try:
        opt = os.environ.get("CWLTOOL_OPTIONS")
        os.environ["CWLTOOL_OPTIONS"] = "--enable-ext"
        params = [
            get_data("tests/wf/listing_deep.cwl"),
            get_data("tests/listing-job.yml"),
        ]
        assert main(params) == 0
    finally:
        if opt is not None:
            os.environ["CWLTOOL_OPTIONS"] = opt
        else:
            del os.environ["CWLTOOL_OPTIONS"]
def test_argparse(
    name: str, script_contents: str, params: Callable[[str], str], tmp_path: Path
) -> None:
    script_name = tmp_path / "script"
    try:
        with script_name.open(mode="w") as script:
            script.write(script_contents)

        my_params = ["--outdir", str(tmp_path / "outdir"), "--debug"]
        my_params.extend(params(script.name))
        assert main(my_params) == 0, name

    except SystemExit as err:
        assert err.code == 0, name
Example #38
0
def test_empty_input():
    empty_json = "{}"
    empty_input = StringIO(empty_json)

    with temp_dir() as tmpdir:
        params = [
            "--outdir", tmpdir,
            get_data("tests/wf/no-parameters-echo.cwl"), "-"
        ]

        try:
            assert main(params, stdin=empty_input) == 0
        except SystemExit as err:
            assert err.code == 0
Example #39
0
def test_input_deps_cmdline_opts_relative_deps_cwd() -> None:
    stream = StringIO()

    data_path = get_data("tests/wf/whale.txt")
    main(
        [
            "--print-input-deps",
            "--relative-deps",
            "cwd",
            get_data("tests/wf/count-lines1-wf.cwl"),
            "--file1",
            data_path,
        ],
        stdout=stream,
    )

    goal = {
        "class":
        "File",
        "location":
        "",
        "format":
        CWL_IANA,
        "secondaryFiles": [{
            "class":
            "File",
            "location":
            str(Path(os.path.relpath(data_path, os.path.curdir))),
            "basename":
            "whale.txt",
            "nameroot":
            "whale",
            "nameext":
            ".txt",
        }],
    }
    assert json.loads(stream.getvalue()) == goal
Example #40
0
def test_for_conflict_file_names(tmp_path: Path) -> None:
    stream = StringIO()

    assert (main(
        [
            "--debug", "--outdir",
            str(tmp_path),
            get_data("tests/wf/conflict.cwl")
        ],
        stdout=stream,
    ) == 0)

    out = json.loads(stream.getvalue())
    assert out["b1"]["basename"] == out["b2"]["basename"]
    assert out["b1"]["location"] != out["b2"]["location"]
Example #41
0
def test_wrong_target() -> None:
    """Test --target option when value is wrong."""
    test_file = "tests/wf/scatter-wf4.cwl"
    exit_code = main(
        [
            "--target",
            "dummy_target",
            get_data(test_file),
            "--inp1",
            "INP1",
            "--inp2",
            "INP2",
        ]
    )
    assert exit_code == 1
Example #42
0
    def test_updateval(self):
        try:
            tmp = tempfile.mkdtemp()
            with open(os.path.join(tmp, "value"), "w") as f:
                f.write("1")
            out = tempfile.mkdtemp()
            self.assertEquals(main(["--outdir", out, get_data('tests/wf/updateval.cwl'), "-r", os.path.join(tmp, "value")]), 0)

            with open(os.path.join(tmp, "value"), "r") as f:
                self.assertEquals("1", f.read())
            with open(os.path.join(out, "value"), "r") as f:
                self.assertEquals("2", f.read())
        finally:
            shutil.rmtree(tmp)
            shutil.rmtree(out)
Example #43
0
def test_argparse(name, script_contents, params, tmpdir):
    try:
        script = NamedTemporaryFile(mode='w', delete=False)
        script.write(script_contents)
        script.close()

        my_params = ["--outdir", str(tmpdir)]
        my_params.extend(params(script.name))
        assert main(my_params) == 0, name

    except SystemExit as err:
        assert err.code == 0, name
    finally:
        if os.path.exists(script.name):
            os.unlink(script.name)
Example #44
0
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)
Example #45
0
def test_docker_iwdr():
    result_code = main(
        [
            "--default-container",
            "debian",
            get_data("tests/wf/iwdr-entry.cwl"),
            "--message",
            "hello",
        ]
    )
    docker_installed = bool(spawn.find_executable("docker"))
    if docker_installed:
        assert result_code == 0
    else:
        assert result_code != 0
def test_dont_require_inputs(tmp_path: Path) -> None:
    stream = StringIO()

    script_name = tmp_path / "script"
    try:
        with script_name.open(mode="w") as script:
            script.write(script_a)

        assert (
            main(
                argsl=["--debug", str(script_name), "--input", str(script_name)],
                executor=cwltool.executors.NoopJobExecutor(),
                stdout=stream,
            )
            == 0
        )
        assert (
            main(
                argsl=["--debug", str(script_name)],
                executor=cwltool.executors.NoopJobExecutor(),
                stdout=stream,
            )
            == 2
        )
        assert (
            main(
                argsl=["--debug", str(script_name)],
                executor=cwltool.executors.NoopJobExecutor(),
                input_required=False,
                stdout=stream,
            )
            == 0
        )

    except SystemExit as err:
        assert err.code == 0, script_name if script else None
Example #47
0
def test_write_write_conflict():
    with temp_dir('tmp') as tmp:
        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
Example #48
0
def test_disable_dir_overwrite_without_ext(tmp_path: Path) -> None:
    """Test that we can write into a "writable" input Directory w/o ext."""
    tmp = tmp_path / "tmp"
    out = tmp_path / "outdir"
    tmp.mkdir()
    out.mkdir()
    assert (main([
        "--outdir",
        str(out),
        get_data("tests/wf/updatedir.cwl"), "-r",
        str(tmp)
    ]) == 0)

    assert not os.listdir(tmp)
    assert os.listdir(out)
Example #49
0
def test_iwdr_permutations_readonly(tmp_path_factory: Any) -> None:
    """Confirm that readonly input files are properly made writable."""
    misc = tmp_path_factory.mktemp("misc")
    fifth = misc / "fifth"
    fifth.mkdir()
    sixth = misc / "sixth"
    sixth.mkdir()
    fifth_file = fifth / "bar"
    fifth_dir = fifth / "foo"
    fifth_file.touch()
    fifth_dir.mkdir()
    sixth = tmp_path_factory.mktemp("sixth")
    first = misc / "first"
    first.touch()
    second = misc / "second"
    second.touch()
    outdir = str(tmp_path_factory.mktemp("outdir"))
    for entry in [first, second, fifth, sixth, fifth_file, fifth_dir]:
        mode = entry.stat().st_mode
        ro_mask = 0o777 ^ (S_IWRITE | S_IWGRP | S_IWOTH)
        entry.chmod(mode & ro_mask)
    assert (
        main(
            [
                "--no-container",
                "--debug",
                "--leave-outputs",
                "--outdir",
                outdir,
                get_data("tests/wf/iwdr_permutations_nocontainer.cwl"),
                "--first",
                str(first),
                "--second",
                str(second),
                "--fifth",
                str(fifth),
                "--sixth",
                str(sixth),
            ]
        )
        == 0
    )
    for entry in [first, second, fifth, sixth, fifth_file, fifth_dir]:
        try:
            mode = entry.stat().st_mode
            entry.chmod(mode | S_IWRITE)
        except PermissionError:
            pass
def test_empty_input(tmp_path: Path) -> None:
    """Affirm that an empty input works."""
    empty_json = "{}"
    empty_input = StringIO(empty_json)

    params = [
        "--outdir",
        str(tmp_path),
        get_data("tests/wf/no-parameters-echo.cwl"),
        "-",
    ]

    try:
        assert main(params, stdin=empty_input) == 0
    except SystemExit as err:
        assert err.code == 0
Example #51
0
def test_singularity_iwdr():
    result_code = main(
        [
            "--singularity",
            "--default-container",
            "debian",
            get_data("tests/wf/iwdr-entry.cwl"),
            "--message",
            "hello",
        ]
    )
    singularity_installed = bool(distutils.spawn.find_executable("singularity"))
    if singularity_installed:
        assert result_code == 0
    else:
        assert result_code != 0
Example #52
0
def test_fetcher() -> None:
    def test_resolver(d: Any, a: str) -> str:
        if a.startswith("baz:bar/"):
            return a
        return "baz:bar/" + a

    loadingContext = LoadingContext({
        "construct_tool_object": default_make_tool,
        "resolver": test_resolver,
        "fetcher_constructor": CWLTestFetcher,
    })

    load_tool("foo.cwl", loadingContext)

    assert (main(["--print-pre", "--debug", "foo.cwl"],
                 loadingContext=loadingContext) == 0)
Example #53
0
def test_double_overwrite(tmpdir):
    with temp_dir() as tmp:
        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
Example #54
0
    def test_sequencing(self):
        try:
            tmp = tempfile.mkdtemp()
            with open(os.path.join(tmp, "value"), "w") as f:
                f.write("1")

            self.assertEquals(
                main([
                    "--enable-ext",
                    get_data('tests/wf/mut2.cwl'), "-a",
                    os.path.join(tmp, "value")
                ]), 0)
            with open(os.path.join(tmp, "value"), "r") as f:
                self.assertEquals("3", f.read())
        finally:
            shutil.rmtree(tmp)
def test_singularity_iwdr() -> None:
    result_code = main(
        [
            "--singularity",
            "--default-container",
            "docker.io/debian:stable-slim",
            get_data("tests/wf/iwdr-entry.cwl"),
            "--message",
            "hello",
        ]
    )
    singularity_installed = bool(shutil.which("singularity"))
    if singularity_installed:
        assert result_code == 0
    else:
        assert result_code != 0
Example #56
0
def test_disable_dir_creation_in_outdir_with_ext() -> None:
    with temp_dir() as tmp:
        with temp_dir() as out:
            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)
Example #57
0
def test_iwdr_permutations_inplace() -> None:
    saved_tempdir = tempfile.tempdir
    with temp_dir() as misc:
        tempfile.tempdir = os.path.realpath(misc)
        with temp_dir() as fifth:
            with temp_dir() as sixth:
                with temp_dir() as seventh:
                    with temp_dir() as eighth:
                        with tempfile.NamedTemporaryFile() as first:
                            with tempfile.NamedTemporaryFile() as second:
                                with tempfile.NamedTemporaryFile() as third:
                                    with tempfile.NamedTemporaryFile() as fourth:
                                        with temp_dir() as outdir:
                                            assert (
                                                main(
                                                    [
                                                        "--outdir",
                                                        outdir,
                                                        "--enable-ext",
                                                        "--overrides",
                                                        get_data(
                                                            "tests/wf/iwdr_permutations_inplace.yml"
                                                        ),
                                                        get_data(
                                                            "tests/wf/iwdr_permutations.cwl"
                                                        ),
                                                        "--first",
                                                        first.name,
                                                        "--second",
                                                        second.name,
                                                        "--third",
                                                        third.name,
                                                        "--fourth",
                                                        fourth.name,
                                                        "--fifth",
                                                        fifth,
                                                        "--sixth",
                                                        sixth,
                                                        "--seventh",
                                                        seventh,
                                                        "--eighth",
                                                        eighth,
                                                    ]
                                                )
                                                == 0
                                            )
    tempfile.tempdir = saved_tempdir
Example #58
0
    def test_simple_mpi_tool(self, fake_mpi_conf: str, tmp_path: Path) -> None:
        stdout = StringIO()
        stderr = StringIO()
        with working_directory(tmp_path):
            rc = main(
                argsl=cwltool_args(fake_mpi_conf)
                + [get_data("tests/wf/mpi_simple.cwl")],
                stdout=stdout,
                stderr=stderr,
            )
            assert rc == 0

            output = json.loads(stdout.getvalue())
            pid_path = output["pids"]["path"]
            with open(pid_path) as pidfile:
                pids = [int(line) for line in pidfile]
            assert len(pids) == 2
Example #59
0
    def test_updatedir(self):
        try:
            tmp = tempfile.mkdtemp()
            with open(os.path.join(tmp, "value"), "w") as f:
                f.write("1")
            out = tempfile.mkdtemp()

            self.assertFalse(os.path.exists(os.path.join(tmp, "blurb")))
            self.assertFalse(os.path.exists(os.path.join(out, "blurb")))

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

            self.assertFalse(os.path.exists(os.path.join(tmp, "blurb")))
            self.assertTrue(os.path.exists(os.path.join(out, "inp/blurb")))
        finally:
            shutil.rmtree(tmp)
            shutil.rmtree(out)
Example #60
0
def test_argparse(name: str, script_contents: str,
                  params: Callable[[str], str], tmpdir: py.path.local) -> None:
    script = None
    try:
        script = NamedTemporaryFile(mode="w", delete=False)
        script.write(script_contents)
        script.close()

        my_params = ["--outdir", str(tmpdir)]
        my_params.extend(params(script.name))
        assert main(my_params) == 0, name

    except SystemExit as err:
        assert err.code == 0, name
    finally:
        if script and script.name and os.path.exists(script.name):
            os.unlink(script.name)