コード例 #1
0
ファイル: test_api.py プロジェクト: JapneetSingh/mutatest
def test_init_GenomeGroup_from_flat_folder(tmp_path):
    """Test the only .py files are grabbed with GenomeGroup default initialization.
    This tests Genome as well.
    """
    test_files = [
        "first.py",
        "second.py",
        "third.py",
        "test_first.py",
        "test_second.py",
        "third_test.py",
        "fourth_test.py",
        "first.pyc",
        "first.pyo",
        "first.pyi",
    ]

    expected = ["first.py", "second.py", "third.py"]

    for tf in test_files:
        with open(tmp_path / tf, "w") as temp_py:
            temp_py.write("import this")

    ggrp = GenomeGroup(tmp_path)
    assert sorted([g.name for g in ggrp.keys()]) == sorted(expected)

    for k, v in ggrp.items():
        assert v.source_file.name in expected
コード例 #2
0
ファイル: test_api.py プロジェクト: JapneetSingh/mutatest
def test_init_GenomeGroup_from_recursive_folder(tmp_path):
    """Ensure recursive glob search works for finding py files. This tests Genome as well."""
    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",
    ]

    expected = ["first.py", "second.py", "third.py"]

    for tf in test_files:
        with open(tf, "w") as temp_py:
            temp_py.write("import this")

    ggrp = GenomeGroup(tmp_path)
    assert sorted([g.name for g in ggrp.keys()]) == sorted(expected)

    for k, v in ggrp.items():
        assert v.source_file.name in expected
コード例 #3
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
コード例 #4
0
ファイル: test_api.py プロジェクト: JapneetSingh/mutatest
def test_GenomeGroup_basic_properties(binop_file, boolop_file, compare_file):
    """Basic class property tests and dictionary manipulation."""
    ggrp = GenomeGroup(binop_file)
    ggrp.add_file(boolop_file)
    ggrp.add_file(compare_file)

    # test ValuesView is iterable view.
    for v in ggrp.values():
        assert isinstance(v, Genome)

    # test basic __iter__ property
    keys = [k for k in ggrp]
    assert len(keys) == 3

    # __repr__ is a string representation of the store
    assert isinstance(ggrp.__repr__(), str)

    # test basic .items() method, uses .pop() to activate __del__
    key_values = [(k, v) for k, v in ggrp.items()]
    for k, v in key_values:
        v2 = ggrp.pop(k)
        assert v2 == v