diff: fix missing key bug (#6720)

This commit is contained in:
dberenbaum
2022-03-02 19:10:31 +01:00
committed by David de la Iglesia Castro
parent 6bb3794f52
commit fc3f3ca8d7
2 changed files with 21 additions and 10 deletions
+1 -1
View File
@@ -128,7 +128,7 @@ class CmdDiff(CmdBase):
show_hash = self.args.show_hash
hide_missing = self.args.b_rev or self.args.hide_missing
if hide_missing:
del diff["not in cache"]
diff.pop("not in cache", None)
for key, entries in diff.items():
entries = sorted(
+20 -9
View File
@@ -204,20 +204,31 @@ def test_diff_show_markdown_and_hash(mocker, show_hash):
mock_show_markdown.assert_called_once_with(diff, show_hash, False)
def test_no_changes(mocker, capsys):
args = parse_args(["diff", "--json"])
@pytest.mark.parametrize(
"opts",
(
[],
["a_rev", "b_rev"],
["--targets", "."],
["--hide-missing"],
),
)
@pytest.mark.parametrize(
"show, expected",
(
([], ""),
(["--json"], "{}"),
(["--md"], "| Status | Path |\n|----------|--------|"),
),
)
def test_no_changes(mocker, capsys, opts, show, expected):
args = parse_args(["diff", *opts, *show])
cmd = args.func(args)
mocker.patch("dvc.repo.Repo.diff", return_value={})
assert 0 == cmd.run()
out, _ = capsys.readouterr()
assert "{}" in out
args = parse_args(["diff"])
cmd = args.func(args)
assert 0 == cmd.run()
out, _ = capsys.readouterr()
assert not out
assert expected == out.strip()
def test_show_markdown(capsys):