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
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
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
def test_init_GenomeGroup_from_single_file(binop_file): """Initialize the GenomgGroup from a single file. This tests Genome as well.""" ggrp = GenomeGroup(binop_file) assert len(ggrp.keys()) == 1 assert list(ggrp.keys())[0].resolve() == binop_file.resolve()