mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
ui: migrate cache:dir and check-ignore to ui.write (#6021)
This commit is contained in:
@@ -9,11 +9,13 @@ from dvc.main import main
|
||||
@pytest.mark.parametrize(
|
||||
"file,ret,output", [("ignored", 0, True), ("not_ignored", 1, False)]
|
||||
)
|
||||
def test_check_ignore(tmp_dir, dvc, file, ret, output, caplog):
|
||||
def test_check_ignore(tmp_dir, dvc, file, ret, output, caplog, capsys):
|
||||
tmp_dir.gen(DvcIgnore.DVCIGNORE_FILE, "ignored")
|
||||
|
||||
assert main(["check-ignore", file]) == ret
|
||||
assert (file in caplog.text) is output
|
||||
|
||||
out, _ = capsys.readouterr()
|
||||
assert (file in out) is output
|
||||
assert "Having any troubles?" not in caplog.text
|
||||
|
||||
|
||||
@@ -32,23 +34,24 @@ def test_check_ignore(tmp_dir, dvc, file, ret, output, caplog):
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_check_ignore_details(tmp_dir, dvc, file, ret, output, caplog):
|
||||
def test_check_ignore_details(tmp_dir, dvc, file, ret, output, capsys):
|
||||
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
|
||||
assert (output, "") == capsys.readouterr()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("non_matching", [True, False])
|
||||
def test_check_ignore_non_matching(tmp_dir, dvc, non_matching, caplog):
|
||||
def test_check_ignore_non_matching(tmp_dir, dvc, non_matching, caplog, capsys):
|
||||
tmp_dir.gen(DvcIgnore.DVCIGNORE_FILE, "other")
|
||||
if non_matching:
|
||||
assert main(["check-ignore", "-d", "-n", "file"]) == 1
|
||||
else:
|
||||
assert main(["check-ignore", "-d", "file"]) == 1
|
||||
|
||||
assert ("::\tfile\n" in caplog.text) is non_matching
|
||||
out, _ = capsys.readouterr()
|
||||
assert ("::\tfile\n" in out) is non_matching
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -83,19 +86,19 @@ def test_check_ignore_out_side_repo(tmp_dir, dvc):
|
||||
assert main(["check-ignore", "-q", "../file"]) == 1
|
||||
|
||||
|
||||
def test_check_ignore_sub_repo(tmp_dir, dvc, caplog):
|
||||
def test_check_ignore_sub_repo(tmp_dir, dvc, capsys):
|
||||
tmp_dir.gen(
|
||||
{DvcIgnore.DVCIGNORE_FILE: "other", "dir": {".dvc": {}, "foo": "bar"}}
|
||||
)
|
||||
|
||||
assert main(["check-ignore", "-d", os.path.join("dir", "foo")]) == 0
|
||||
out, _ = capsys.readouterr()
|
||||
assert (
|
||||
"in sub_repo:{}\t{}".format("dir", os.path.join("dir", "foo"),)
|
||||
in caplog.text
|
||||
"in sub_repo:{}\t{}".format("dir", os.path.join("dir", "foo"),) in out
|
||||
)
|
||||
|
||||
|
||||
def test_check_sub_dir_ignore_file(tmp_dir, dvc, caplog):
|
||||
def test_check_sub_dir_ignore_file(tmp_dir, dvc, capsys):
|
||||
tmp_dir.gen(
|
||||
{
|
||||
DvcIgnore.DVCIGNORE_FILE: "other",
|
||||
@@ -104,36 +107,41 @@ def test_check_sub_dir_ignore_file(tmp_dir, dvc, caplog):
|
||||
)
|
||||
|
||||
assert main(["check-ignore", "-d", os.path.join("dir", "foo")]) == 0
|
||||
|
||||
out, _ = capsys.readouterr()
|
||||
assert (
|
||||
"{}:2:foo\t{}".format(
|
||||
os.path.join("dir", DvcIgnore.DVCIGNORE_FILE),
|
||||
os.path.join("dir", "foo"),
|
||||
)
|
||||
in caplog.text
|
||||
in out
|
||||
)
|
||||
|
||||
sub_dir = tmp_dir / "dir"
|
||||
with sub_dir.chdir():
|
||||
assert main(["check-ignore", "-d", "foo"]) == 0
|
||||
assert ".dvcignore:2:foo\tfoo" in caplog.text
|
||||
out, _ = capsys.readouterr()
|
||||
assert ".dvcignore:2:foo\tfoo" in out
|
||||
|
||||
|
||||
def test_check_ignore_details_all(tmp_dir, dvc, caplog):
|
||||
def test_check_ignore_details_all(tmp_dir, dvc, capsys):
|
||||
tmp_dir.gen(DvcIgnore.DVCIGNORE_FILE, "f*\n!foo")
|
||||
|
||||
assert main(["check-ignore", "-d", "-a", "foo"]) == 0
|
||||
assert "{}:1:f*\tfoo\n".format(DvcIgnore.DVCIGNORE_FILE) in caplog.text
|
||||
assert "{}:2:!foo\tfoo\n".format(DvcIgnore.DVCIGNORE_FILE) in caplog.text
|
||||
out, _ = capsys.readouterr()
|
||||
assert "{}:1:f*\tfoo\n".format(DvcIgnore.DVCIGNORE_FILE) in out
|
||||
assert "{}:2:!foo\tfoo\n".format(DvcIgnore.DVCIGNORE_FILE) in out
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"file,ret,output", [("ignored", 0, True), ("not_ignored", 1, False)]
|
||||
)
|
||||
def test_check_ignore_stdin_mode(
|
||||
tmp_dir, dvc, file, ret, output, caplog, mocker
|
||||
tmp_dir, dvc, file, ret, output, capsys, mocker
|
||||
):
|
||||
tmp_dir.gen(DvcIgnore.DVCIGNORE_FILE, "ignored")
|
||||
mocker.patch("builtins.input", side_effect=[file, ""])
|
||||
|
||||
assert main(["check-ignore", "--stdin"]) == ret
|
||||
assert (file in caplog.text) is output
|
||||
out, _ = capsys.readouterr()
|
||||
assert (file in out) is output
|
||||
|
||||
Reference in New Issue
Block a user