Files
dvc/tests/unit/command/test_checkout.py
T
Saugat PachhaiandJorge Orpinel 066ccea733 checkout: show summary by default and introduce --show-changes flag (#3401)
* checkout: implement --show-changes flag to show detailed checkout details
Show summary by default on checkout

checkout: show directory modified even when files are removed from inside it

checkout: refactor template logic

checkout: change output format

checkout: do not show summary if nothing's changed

checkout: do not show summary if show_changes is specified

checkout: show '/' at the end if it's a directory

rename variable name

test: cover stats for checkout

checkout: show relink as not modified

checkout: remove unwanted message during empty checkout

pull: show summary on checkout

import/get: change external_repo to catch CheckoutError

fix tests and check if path is url

checkout: support external deps/outputs

tests: checkout on external outputs

* fix tests

* checkout: make show changes default and introduce summary flag to show summary

* address suggestions

* exceptions: remove extra spacing on erorr

* Update dvc/command/checkout.py

Co-Authored-By: Jorge Orpinel <[email protected]>

Co-authored-by: Jorge Orpinel <[email protected]>
2020-03-16 16:29:36 +02:00

77 lines
2.0 KiB
Python

import logging
from dvc.cli import parse_args
from dvc.command.checkout import CmdCheckout, log_summary, log_changes
def test_checkout(tmp_dir, dvc, mocker):
cli_args = parse_args(
["checkout", "foo.dvc", "bar.dvc", "--relink", "--with-deps"]
)
assert cli_args.func == CmdCheckout
cmd = cli_args.func(cli_args)
m = mocker.patch("dvc.repo.Repo.checkout")
assert cmd.run() == 0
m.assert_called_once_with(
targets=["foo.dvc", "bar.dvc"],
force=False,
recursive=False,
relink=True,
with_deps=True,
)
def test_log_summary(caplog):
stats = {
"added": ["file1", "file2", "file3"],
"deleted": ["file4", "file5"],
"modified": ["file6", "file7"],
}
def _assert_output(stats, expected_text):
with caplog.at_level(logging.INFO, logger="dvc"):
caplog.clear()
log_summary(stats)
assert expected_text in caplog.text
_assert_output(stats, "3 added, 2 deleted and 2 modified")
del stats["deleted"][1]
_assert_output(stats, "3 added, 1 deleted and 2 modified")
del stats["deleted"][0]
_assert_output(stats, "3 added and 2 modified")
del stats["modified"]
_assert_output(stats, "3 added")
_assert_output({}, "")
def test_log_changes(caplog):
stats = {
"added": ["file1", "dir1/"],
"deleted": ["dir2/"],
"modified": ["file2"],
}
from itertools import zip_longest
def _assert_output(stats, expected_outs):
with caplog.at_level(logging.INFO, logger="dvc"):
caplog.clear()
log_changes(stats)
actual_output = caplog.text.splitlines()
for out, line in zip_longest(expected_outs, actual_output):
assert out in line
_assert_output(stats, ["M\tfile2", "A\tfile1", "A\tdir1/", "D\tdir2/"])
del stats["deleted"][0]
_assert_output(stats, ["M\tfile2", "A\tfile1", "A\tdir1/"])
del stats["modified"]
_assert_output(stats, ["A\tfile1", "A\tdir1/"])