예제 #1
0
def test_explore_dinosaur():
    """
    Python has an issue with killing process trees, whereby the subprocess runs another subprocess.
    This tests that dinosaur
    :return:
    """
    command = explore_command(["dinosaur"], max_depth=1)
예제 #2
0
def acclimatise_exe(
    exe: pathlib.Path,
    out_dir: pathlib.Path,
    verbose: bool = True,
    exit_on_failure: bool = False,
    run_kwargs: dict = {},
):
    """
    Given an executable path, acclimatises it, and dumps the results in out_dir
    """
    with log_around("Exploring {}".format(exe.name), verbose):
        try:
            # Briefly cd into the temp directory, so we don't fill up the cwd with junk
            cmd = explore_command([exe.name], run_kwargs={"check": False, **run_kwargs})

            # Dump a YAML version of the tool
            with (out_dir / exe.name).with_suffix(".yml").open("w") as out_fp:
                yaml.dump(cmd, out_fp)

        except Exception as e:
            if exit_on_failure:
                raise e
            else:
                handle_exception(
                    e,
                    msg="Acclimatising the command {}".format(exe.name),
                    log_path=(out_dir / exe.name).with_suffix(".error.txt"),
                    print=verbose,
                    exit=exit_on_failure,
                )
예제 #3
0
def test_explore_samtools_pl(yaml_converter):
    """
    Tests that commands with a non-standard file extension include their extension in the final output, and don't
    override another command with the same stem
    """
    samtools = explore_command(["samtools"], max_depth=0)
    samtools_pl = explore_command(["samtools.pl"], max_depth=0)
    with tempfile.TemporaryDirectory() as temp_dir:
        path = Path(temp_dir)
        filenames = set()
        for path, command in itertools.chain(
            yaml_converter.generate_tree(samtools, temp_dir),
            yaml_converter.generate_tree(samtools_pl, temp_dir),
        ):
            filenames.add(path.name)

        assert filenames == {"samtools.yml", "samtools.pl.yml"}
예제 #4
0
def test_explore_bwa():
    """
    This tests specifically that exploring bwa yields a proper bwa mem
    """
    command = explore_command(["bwa"], max_depth=1)

    # Check that we parsed bwa mem correctly
    mem = command.subcommands[1]
    assert len(mem.positional) == 3
    assert len(mem.subcommands) == 0
    assert len(mem.named) >= 30
예제 #5
0
def test_explore(test: HelpText):
    """
    A comprehensive end-to-end test that tests the parser and converters, after exploring a given command
    """
    if not shutil.which(test.cmd[0]):
        pytest.skip("{} is not installed".format(test.cmd[0]))

    try:
        ensure_conda()
    except:
        pytest.skip("Not in a conda environment")

    # For speed's sake, only explore to depth 2
    command = explore_command(test.cmd, max_depth=1)

    # Check we parsed correctly
    assert len(command.subcommands) == test.subcommands
    assert len(command.positional) == test.positional
    assert len(command.named) == test.named

    # Check this can be converted properly to all formats
    convert_validate(command, explore=True)
예제 #6
0
    out_dir: Path,
    formats: Tuple[str],
    subcommands: bool,
    case: str,
    generate_names: bool,
    pos: bool,
    help_flag: str,
    depth: int = None,
):
    # Optionally parse subcommands
    kwargs = {}
    if help_flag is not None:
        kwargs["flags"] = [[help_flag]]

    if subcommands:
        command = explore_command(list(cmd), max_depth=depth, **kwargs)
    else:
        command = best_cmd(list(cmd), **kwargs)

    for format in formats:
        converter_cls = WrapperGenerator.choose_converter(format)
        converter = converter_cls(
            generate_names=generate_names,
            ignore_positionals=not pos,
            case=case,
        )
        list(converter.generate_tree(command, out_dir))


@main.command(
    help="Read a command help from stdin and output a tool definition to stdout"