Exemple #1
0
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))
Exemple #2
0
def mock_dvcignore(dvcignore_path, patterns):
    fs = MagicMock()
    with patch.object(fs, "open", mock_open(read_data="\n".join(patterns))):
        ignore_patterns = DvcIgnorePatterns.from_files(dvcignore_path, fs,
                                                       None)

    return ignore_patterns