コード例 #1
0
ファイル: test_api.py プロジェクト: JapneetSingh/mutatest
def test_GenomeGroup_add_folder_with_exclusions(tmp_path):
    """Ensure excluded files are not used in the GenomeGroup add folder method."""
    f = tmp_path / "folder"
    f.mkdir()

    test_files = [
        tmp_path / "first.py",
        tmp_path / "second.py",
        tmp_path / "test_first.py",
        tmp_path / "test_second.py",
        tmp_path / "third_test.py",
        f / "third.py",
        f / "test_third.py",
    ]

    exclude = [(tmp_path / "second.py").resolve(), (f / "third.py").resolve()]
    expected = "first.py"

    # need at least on valid location operation to return a value for trees/targets
    for tf in test_files:
        with open(tf, "w") as temp_py:
            temp_py.write("x: int = 1 + 2")

    ggrp = GenomeGroup()
    ggrp.add_folder(tmp_path, exclude_files=exclude)

    assert len(ggrp) == 1
    assert list(ggrp.keys())[0].name == expected
コード例 #2
0
ファイル: run.py プロジェクト: davidlibland/mutatest
def get_genome_group(src_loc: Path, config: Config) -> GenomeGroup:
    """Get the ``GenomeGroup`` based on ``src_loc`` and ``config``.

    ``Config`` is used to set global filter codes and exclude files on group creation.

    Args:
        src_loc: Path, can be directory or file
        config: the running config object

    Returns:
        ``GenomeGroup`` based on ``src_loc`` and config.
    """
    ggrp = GenomeGroup()

    # check if src_loc is a single file, otherwise assume it's a directory
    if src_loc.is_file():
        ggrp.add_file(source_file=src_loc)

    else:
        ggrp.add_folder(source_folder=src_loc,
                        exclude_files=config.exclude_files,
                        ignore_test_files=True)

    if config.filter_codes:
        LOGGER.info("Category restriction, chosen categories: %s",
                    sorted(config.filter_codes))
        ggrp.set_filter(filter_codes=config.filter_codes)

    for k, genome in ggrp.items():
        LOGGER.info(
            "%s",
            colorize_output(
                f"{len(genome.targets)} mutation targets found in {genome.source_file} AST.",
                "green" if len(genome.targets) > 0 else "yellow",
            ),
        )

    for e in config.exclude_files:
        LOGGER.info("%s", colorize_output(f"{e.resolve()} excluded.",
                                          "yellow"))

    return ggrp
コード例 #3
0
ファイル: test_api.py プロジェクト: JapneetSingh/mutatest
def test_GenomeGroup_folder_exception():
    """Invalid folders raise a type error."""
    with pytest.raises(TypeError):
        ggrp = GenomeGroup()
        ggrp.add_folder("somethingrandom")