def test_ignore_collecting_dvcignores(tmp_dir, dvc, dname): tmp_dir.gen({"dir": {"subdir": {}}}) top_ignore_file = (tmp_dir / dname).with_name(DvcIgnore.DVCIGNORE_FILE) top_ignore_file.write_text(os.path.basename(dname)) dvc.tree.__dict__.pop("dvcignore", None) ignore_file = tmp_dir / dname / DvcIgnore.DVCIGNORE_FILE ignore_file.write_text("foo") assert len(dvc.tree.dvcignore.ignores) == 3 assert DvcIgnoreDirs([".git", ".hg", ".dvc"]) in dvc.tree.dvcignore.ignores ignore_pattern_trie = None for ignore in dvc.tree.dvcignore.ignores: if isinstance(ignore, DvcIgnorePatternsTrie): ignore_pattern_trie = ignore assert ignore_pattern_trie is not None assert (DvcIgnorePatterns.from_files( os.fspath(top_ignore_file), LocalRemoteTree(None, {"url": dvc.root_dir}), ) == ignore_pattern_trie[os.fspath(ignore_file)]) assert any(i for i in dvc.tree.dvcignore.ignores if isinstance(i, DvcIgnoreRepo))
def test_should_ignore_dir(omit_dir): ignore = DvcIgnoreDirs([".git", ".hg", ".dvc"]) root = os.path.join(os.path.sep, "walk", "dir", "root") dirs = [omit_dir, "dir1", "dir2"] files = [] new_dirs, _ = ignore(root, dirs, files) assert set(new_dirs) == {"dir1", "dir2"}
def test_ignore_collecting_dvcignores(tmp_dir, dvc, dname): tmp_dir.gen({"dir": {"subdir": {}}}) top_ignore_file = (tmp_dir / dname).with_name(DvcIgnore.DVCIGNORE_FILE) top_ignore_file.write_text(os.path.basename(dname)) ignore_file = tmp_dir / dname / DvcIgnore.DVCIGNORE_FILE ignore_file.write_text("foo") assert dvc.tree.dvcignore.ignores == { DvcIgnoreDirs([".git", ".hg", ".dvc"]), DvcIgnorePatterns(fspath(top_ignore_file), WorkingTree(dvc.root_dir)), }
def test_ignore_collecting_dvcignores(repo_dir, dname): top_ignore_file = os.path.join( repo_dir.root_dir, os.path.dirname(dname), DvcIgnore.DVCIGNORE_FILE ) repo_dir.create(top_ignore_file, os.path.basename(dname)) ignore_file = os.path.join( repo_dir.root_dir, dname, DvcIgnore.DVCIGNORE_FILE ) repo_dir.create(ignore_file, repo_dir.FOO) assert DvcIgnoreFilter(repo_dir.root_dir).ignores == { DvcIgnoreDirs([".git", ".hg", ".dvc"]), DvcIgnorePatterns(top_ignore_file), }
def test_ignore_collecting_dvcignores(tmp_dir, dvc, dname): tmp_dir.gen({"dir": {"subdir": {}}}) top_ignore_file = (tmp_dir / dname).with_name(DvcIgnore.DVCIGNORE_FILE) top_ignore_file.write_text(os.path.basename(dname)) ignore_file = tmp_dir / dname / DvcIgnore.DVCIGNORE_FILE ignore_file.write_text("foo") assert len(dvc.tree.dvcignore.ignores) == 3 assert DvcIgnoreDirs([".git", ".hg", ".dvc"]) in dvc.tree.dvcignore.ignores assert (DvcIgnorePatterns(os.fspath(top_ignore_file), WorkingTree(dvc.root_dir)) in dvc.tree.dvcignore.ignores) assert any(i for i in dvc.tree.dvcignore.ignores if isinstance(i, DvcIgnoreRepo))