Skip to content

Commit

Permalink
params: diff: sort table (#3617)
Browse files Browse the repository at this point in the history
  • Loading branch information
efiop authored Apr 9, 2020
1 parent cdef709 commit 0e854f9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
7 changes: 5 additions & 2 deletions dvc/command/params.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import argparse
import logging

from collections import OrderedDict

from dvc.command.base import append_doc_link
from dvc.command.base import CmdBase
from dvc.command.base import fix_subparsers
Expand All @@ -14,8 +16,9 @@ def _show_diff(diff):
from dvc.utils.diff import table

rows = []
for fname, mdiff in diff.items():
for param, change in mdiff.items():
for fname, pdiff in diff.items():
sorted_pdiff = OrderedDict(sorted(pdiff.items()))
for param, change in sorted_pdiff.items():
rows.append([fname, param, change["old"], change["new"]])

return table(["Path", "Param", "Old", "New"], rows)
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/command/test_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,20 @@ def test_params_diff_show_json(dvc, mocker, caplog):
with caplog.at_level(logging.INFO, logger="dvc"):
assert cmd.run() == 0
assert '{"params.yaml": {"a": "b"}}\n' in caplog.text


def test_params_diff_sorted():
assert _show_diff(
{
"params.yaml": {
"x.b": {"old": 5, "new": 6},
"a.d.e": {"old": 3, "new": 4},
"a.b.c": {"old": 1, "new": 2},
}
}
) == (
" Path Param Old New\n"
"params.yaml a.b.c 1 2 \n"
"params.yaml a.d.e 3 4 \n"
"params.yaml x.b 5 6 "
)

0 comments on commit 0e854f9

Please sign in to comment.