mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-19 15:28:28 +01:00
* Update some tests first fix #3736 * first edition * solve failure in Windows * For Windows ci * Some help ducuments issue. * Update dvc/ignore.py abspath Co-authored-by: Ruslan Kuprieiev <[email protected]> * Refactor with OutOfWorkSpaceError * Solve a bug * Update dvc/command/check_ignore.py Co-authored-by: Jorge Orpinel <[email protected]> * Update dvc/command/check_ignore.py Co-authored-by: Jorge Orpinel <[email protected]> * Update dvc/command/check_ignore.py * Revert "Refactor with OutOfWorkSpaceError" This reverts commit 27eec49ed67346c89157edea998b6b5fa81d88f5. * Two change request 1. Argument `targets`'s description. 2. Error handling of `_get_normalize_path` * Update dvc/main.py Co-authored-by: Ruslan Kuprieiev <[email protected]> * `check_ignore` now only accept one path a time 1. Add a new test for the out side repo cases 2. check ignore now only check one file not file lists Co-authored-by: Ruslan Kuprieiev <[email protected]> Co-authored-by: karajan1001 <[email protected]> Co-authored-by: Jorge Orpinel <[email protected]>
110 lines
3.1 KiB
Python
110 lines
3.1 KiB
Python
import os
|
|
|
|
import pytest
|
|
|
|
from dvc.ignore import DvcIgnore
|
|
from dvc.main import main
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"file,ret,output", [("ignored", 0, "ignored\n"), ("not_ignored", 1, "")]
|
|
)
|
|
def test_check_ignore(tmp_dir, dvc, file, ret, output, caplog):
|
|
tmp_dir.gen(DvcIgnore.DVCIGNORE_FILE, "ignored")
|
|
|
|
assert main(["check-ignore", file]) == ret
|
|
assert output in caplog.text
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"file,ret,output",
|
|
[
|
|
("file", 0, "{}:1:f*\tfile\n".format(DvcIgnore.DVCIGNORE_FILE)),
|
|
("foo", 0, "{}:2:!foo\tfoo\n".format(DvcIgnore.DVCIGNORE_FILE)),
|
|
(
|
|
os.path.join("dir", "foobar"),
|
|
0,
|
|
"{}:1:foobar\t{}\n".format(
|
|
os.path.join("dir", DvcIgnore.DVCIGNORE_FILE),
|
|
os.path.join("dir", "foobar"),
|
|
),
|
|
),
|
|
],
|
|
)
|
|
def test_check_ignore_details(tmp_dir, dvc, file, ret, output, caplog):
|
|
tmp_dir.gen(DvcIgnore.DVCIGNORE_FILE, "f*\n!foo")
|
|
tmp_dir.gen({"dir": {DvcIgnore.DVCIGNORE_FILE: "foobar"}})
|
|
|
|
assert main(["check-ignore", "-d", file]) == ret
|
|
assert output in caplog.text
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"non_matching,output", [(["-n"], "::\tfile\n"), ([], "")]
|
|
)
|
|
def test_check_ignore_non_matching(tmp_dir, dvc, non_matching, output, caplog):
|
|
tmp_dir.gen(DvcIgnore.DVCIGNORE_FILE, "other")
|
|
|
|
assert main(["check-ignore", "-d"] + non_matching + ["file"]) == 1
|
|
assert output in caplog.text
|
|
|
|
|
|
def test_check_ignore_non_matching_without_details(tmp_dir, dvc):
|
|
tmp_dir.gen(DvcIgnore.DVCIGNORE_FILE, "other")
|
|
|
|
assert main(["check-ignore", "-n", "file"]) == 255
|
|
|
|
|
|
def test_check_ignore_details_with_quiet(tmp_dir, dvc):
|
|
tmp_dir.gen(DvcIgnore.DVCIGNORE_FILE, "other")
|
|
|
|
assert main(["check-ignore", "-d", "-q", "file"]) == 255
|
|
|
|
|
|
@pytest.mark.parametrize("path,ret", [({"dir": {}}, 0), ({"dir": "files"}, 1)])
|
|
def test_check_ignore_dir(tmp_dir, dvc, path, ret):
|
|
tmp_dir.gen(DvcIgnore.DVCIGNORE_FILE, "dir/")
|
|
tmp_dir.gen(path)
|
|
|
|
assert main(["check-ignore", "-q", "dir"]) == ret
|
|
|
|
|
|
def test_check_ignore_default_dir(tmp_dir, dvc):
|
|
assert main(["check-ignore", "-q", ".dvc"]) == 1
|
|
|
|
|
|
def test_check_ignore_out_side_repo(tmp_dir, dvc):
|
|
tmp_dir.gen(DvcIgnore.DVCIGNORE_FILE, "file")
|
|
assert main(["check-ignore", "-q", "../file"]) == 1
|
|
|
|
|
|
def test_check_ignore_sub_repo(tmp_dir, dvc):
|
|
tmp_dir.gen(
|
|
{DvcIgnore.DVCIGNORE_FILE: "other", "dir": {".dvc": {}, "foo": "bar"}}
|
|
)
|
|
|
|
assert main(["check-ignore", "-q", os.path.join("dir", "foo")]) == 1
|
|
|
|
|
|
def test_check_sub_dir_ignore_file(tmp_dir, dvc, caplog):
|
|
tmp_dir.gen(
|
|
{
|
|
DvcIgnore.DVCIGNORE_FILE: "other",
|
|
"dir": {DvcIgnore.DVCIGNORE_FILE: "bar\nfoo", "foo": "bar"},
|
|
}
|
|
)
|
|
|
|
assert main(["check-ignore", "-d", os.path.join("dir", "foo")]) == 0
|
|
assert (
|
|
"{}:2:foo\t{}".format(
|
|
os.path.join("dir", DvcIgnore.DVCIGNORE_FILE),
|
|
os.path.join("dir", "foo"),
|
|
)
|
|
in caplog.text
|
|
)
|
|
|
|
sub_dir = tmp_dir / "dir"
|
|
with sub_dir.chdir():
|
|
assert main(["check-ignore", "-d", "foo"]) == 0
|
|
assert ".dvcignore:2:foo\tfoo" in caplog.text
|