From 9d9ff10be1f516d0c6459370c8089caac52e91fb Mon Sep 17 00:00:00 2001 From: Hadas Arik <39025628+hadasarik@users.noreply.github.com> Date: Tue, 6 Jul 2021 15:03:32 +0300 Subject: [PATCH] diff: only show states with values in summary (#6229) * Fixed diff summary to only show states with values. * Removed redundant comma by using join. * Swithced for loop to generator for better readability. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- dvc/command/diff.py | 12 +++++------- tests/unit/command/test_diff.py | 8 +++----- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/dvc/command/diff.py b/dvc/command/diff.py index bc96a38f9..d717bf2fd 100644 --- a/dvc/command/diff.py +++ b/dvc/command/diff.py @@ -111,14 +111,12 @@ class CmdDiff(CmdBase): if not sum(summary.values()): return None - fmt = ( - "files summary: {added} added, {deleted} deleted," - " {renamed} renamed, {modified} modified" + states_summary = ", ".join( + f"{summary[state]} {state}" + for state in states + if summary[state] > 0 ) - if not hide_missing: - fmt += ", {not in cache} not in cache" - - ui.write(fmt.format_map(summary)) + ui.write("files summary:", states_summary) def run(self): from dvc.exceptions import DvcException diff --git a/tests/unit/command/test_diff.py b/tests/unit/command/test_diff.py index 023ceccb2..70877c33d 100644 --- a/tests/unit/command/test_diff.py +++ b/tests/unit/command/test_diff.py @@ -48,8 +48,7 @@ def test_default(mocker, capsys): "Renamed:\n" " data{sep}file_old -> data{sep}file_new\n" "\n" - "files summary: 1 added, 0 deleted, " - "1 renamed, 0 modified, 0 not in cache" + "files summary: 1 added, 1 renamed" ).format(sep=os.path.sep) in capsys.readouterr()[0] @@ -99,8 +98,7 @@ def test_show_hash(mocker, capsys): " CCCCCCCC..DDDDDDDD file1\n" " AAAAAAAA..BBBBBBBB file2\n" "\n" - "files summary: 0 added, 2 deleted, " - "1 renamed, 2 modified, 0 not in cache" + "files summary: 2 deleted, 1 renamed, 2 modified" ) in out @@ -350,6 +348,6 @@ def test_hide_missing(mocker, capsys): "Renamed:\n" " file_old -> file_new\n" "\n" - "files summary: 1 added, 0 deleted, 1 renamed, 0 modified" + "files summary: 1 added, 1 renamed" ) in out assert "not in cache" not in out