mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-12-03 15:28:28 +01:00
cli: add short alias for --show-{csv,json,md} (#6711)
As `--csv`/`--json`/`--md`
This commit is contained in:
@@ -57,7 +57,7 @@ def test_list_outputs_only(mocker):
|
||||
|
||||
|
||||
def test_show_json(mocker, capsys):
|
||||
cli_args = parse_args(["list", "local_dir", "--show-json"])
|
||||
cli_args = parse_args(["list", "local_dir", "--json"])
|
||||
assert cli_args.func == CmdList
|
||||
|
||||
cmd = cli_args.func(cli_args)
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
from itertools import takewhile
|
||||
|
||||
import pytest
|
||||
|
||||
from dvc.cli import parse_args
|
||||
|
||||
|
||||
def _id_gen(val) -> str:
|
||||
if isinstance(val, list):
|
||||
return "-".join(takewhile(lambda v: not v.startswith("-"), val))
|
||||
return str(val)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"args, key",
|
||||
[
|
||||
(["diff", "--show-json"], "json"),
|
||||
(["diff", "--show-md"], "markdown"),
|
||||
(["experiments", "diff", "--show-json"], "json"),
|
||||
(["experiments", "diff", "--show-md"], "markdown"),
|
||||
(["experiments", "show", "--show-json"], "json"),
|
||||
(["experiments", "show", "--show-csv"], "csv"),
|
||||
(["ls", "--show-json", "."], "json"),
|
||||
(["metrics", "diff", "--show-json"], "json"),
|
||||
(["metrics", "diff", "--show-md"], "markdown"),
|
||||
(["metrics", "show", "--show-json"], "json"),
|
||||
(["metrics", "show", "--show-md"], "markdown"),
|
||||
(["params", "diff", "--show-json"], "json"),
|
||||
(["params", "diff", "--show-md"], "markdown"),
|
||||
(["status", "--show-json"], "json"),
|
||||
],
|
||||
ids=_id_gen,
|
||||
)
|
||||
def test_backward_compat_flags(args, key):
|
||||
"""Test support for --show-csv/--show-json/--show-md flags."""
|
||||
cli_args = parse_args(args)
|
||||
d = vars(cli_args)
|
||||
assert d[key] is True
|
||||
@@ -4,7 +4,7 @@ import os
|
||||
import pytest
|
||||
|
||||
from dvc.cli import parse_args
|
||||
from dvc.command.diff import _digest, _show_md
|
||||
from dvc.command.diff import _digest, _show_markdown
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -102,7 +102,7 @@ def test_show_hash(mocker, capsys):
|
||||
|
||||
|
||||
def test_show_json(mocker, capsys):
|
||||
args = parse_args(["diff", "--show-json"])
|
||||
args = parse_args(["diff", "--json"])
|
||||
cmd = args.func(args)
|
||||
diff = {
|
||||
"added": [
|
||||
@@ -124,7 +124,7 @@ def test_show_json(mocker, capsys):
|
||||
|
||||
|
||||
def test_show_json_and_hash(mocker, capsys):
|
||||
args = parse_args(["diff", "--show-json", "--show-hash"])
|
||||
args = parse_args(["diff", "--json", "--show-hash"])
|
||||
cmd = args.func(args)
|
||||
|
||||
diff = {
|
||||
@@ -161,7 +161,7 @@ def test_show_json_and_hash(mocker, capsys):
|
||||
|
||||
|
||||
def test_show_json_hide_missing(mocker, capsys):
|
||||
args = parse_args(["diff", "--show-json", "--hide-missing"])
|
||||
args = parse_args(["diff", "--json", "--hide-missing"])
|
||||
cmd = args.func(args)
|
||||
diff = {
|
||||
"added": [
|
||||
@@ -190,22 +190,22 @@ def test_show_json_hide_missing(mocker, capsys):
|
||||
|
||||
|
||||
@pytest.mark.parametrize("show_hash", [None, True, False])
|
||||
def test_diff_show_md_and_hash(mocker, show_hash):
|
||||
options = ["diff", "--show-md"] + (["--show-hash"] if show_hash else [])
|
||||
def test_diff_show_markdown_and_hash(mocker, show_hash):
|
||||
options = ["diff", "--md"] + (["--show-hash"] if show_hash else [])
|
||||
args = parse_args(options)
|
||||
cmd = args.func(args)
|
||||
|
||||
diff = {}
|
||||
show_hash = show_hash if show_hash else False
|
||||
mock_show_md = mocker.patch("dvc.command.diff._show_md")
|
||||
mock_show_markdown = mocker.patch("dvc.command.diff._show_markdown")
|
||||
mocker.patch("dvc.repo.Repo.diff", return_value=diff.copy())
|
||||
|
||||
assert 0 == cmd.run()
|
||||
mock_show_md.assert_called_once_with(diff, show_hash, False)
|
||||
mock_show_markdown.assert_called_once_with(diff, show_hash, False)
|
||||
|
||||
|
||||
def test_no_changes(mocker, capsys):
|
||||
args = parse_args(["diff", "--show-json"])
|
||||
args = parse_args(["diff", "--json"])
|
||||
cmd = args.func(args)
|
||||
mocker.patch("dvc.repo.Repo.diff", return_value={})
|
||||
|
||||
@@ -220,7 +220,7 @@ def test_no_changes(mocker, capsys):
|
||||
assert not out
|
||||
|
||||
|
||||
def test_show_md(capsys):
|
||||
def test_show_markdown(capsys):
|
||||
diff = {
|
||||
"deleted": [
|
||||
{"path": "zoo"},
|
||||
@@ -234,7 +234,7 @@ def test_show_md(capsys):
|
||||
"not in cache": [{"path": "file2"}],
|
||||
}
|
||||
|
||||
_show_md(diff)
|
||||
_show_markdown(diff)
|
||||
out, _ = capsys.readouterr()
|
||||
assert out == (
|
||||
"| Status | Path |\n"
|
||||
@@ -251,7 +251,7 @@ def test_show_md(capsys):
|
||||
).format(sep=os.path.sep)
|
||||
|
||||
|
||||
def test_show_md_with_hash(capsys):
|
||||
def test_show_markdown_with_hash(capsys):
|
||||
diff = {
|
||||
"deleted": [
|
||||
{"path": "zoo", "hash": "22222"},
|
||||
@@ -272,7 +272,7 @@ def test_show_md_with_hash(capsys):
|
||||
"not in cache": [{"path": "file2", "hash": "12345678"}],
|
||||
}
|
||||
|
||||
_show_md(diff, show_hash=True)
|
||||
_show_markdown(diff, show_hash=True)
|
||||
|
||||
out, _ = capsys.readouterr()
|
||||
assert out == (
|
||||
@@ -290,7 +290,7 @@ def test_show_md_with_hash(capsys):
|
||||
).format(sep=os.path.sep)
|
||||
|
||||
|
||||
def test_show_md_hide_missing(capsys):
|
||||
def test_show_markdown_hide_missing(capsys):
|
||||
diff = {
|
||||
"deleted": [
|
||||
{"path": "zoo"},
|
||||
@@ -304,7 +304,7 @@ def test_show_md_hide_missing(capsys):
|
||||
"not in cache": [{"path": "file2"}],
|
||||
}
|
||||
|
||||
_show_md(diff, hide_missing=True)
|
||||
_show_markdown(diff, hide_missing=True)
|
||||
|
||||
out, _ = capsys.readouterr()
|
||||
assert out == (
|
||||
|
||||
@@ -42,8 +42,8 @@ def test_experiments_diff(dvc, scm, mocker):
|
||||
"HEAD~1",
|
||||
"--all",
|
||||
"--param-deps",
|
||||
"--show-json",
|
||||
"--show-md",
|
||||
"--json",
|
||||
"--md",
|
||||
"--old",
|
||||
"--precision",
|
||||
"10",
|
||||
@@ -381,7 +381,7 @@ all_experiments = {
|
||||
|
||||
def test_show_experiments(capsys):
|
||||
show_experiments(
|
||||
all_experiments, precision=None, fill_value="", iso=True, show_csv=True
|
||||
all_experiments, precision=None, fill_value="", iso=True, csv=True
|
||||
)
|
||||
cap = capsys.readouterr()
|
||||
assert (
|
||||
|
||||
@@ -13,7 +13,7 @@ def test_metrics_diff(dvc, mocker, capsys):
|
||||
"HEAD~1",
|
||||
"-R",
|
||||
"--all",
|
||||
"--show-md",
|
||||
"--md",
|
||||
"--targets",
|
||||
"target1",
|
||||
"target2",
|
||||
@@ -59,7 +59,7 @@ def test_metrics_diff_json(dvc, mocker, capsys):
|
||||
"HEAD~1",
|
||||
"-R",
|
||||
"--all",
|
||||
"--show-json",
|
||||
"--json",
|
||||
"--targets",
|
||||
"target1",
|
||||
"target2",
|
||||
@@ -139,7 +139,7 @@ def test_metrics_show_json(dvc, mocker, capsys):
|
||||
[
|
||||
"metrics",
|
||||
"show",
|
||||
"--show-json",
|
||||
"--json",
|
||||
"-R",
|
||||
"--all-tags",
|
||||
"--all-branches",
|
||||
|
||||
@@ -12,8 +12,8 @@ def test_params_diff(dvc, mocker):
|
||||
"--targets",
|
||||
"target",
|
||||
"--all",
|
||||
"--show-json",
|
||||
"--show-md",
|
||||
"--json",
|
||||
"--md",
|
||||
"--no-path",
|
||||
"--deps",
|
||||
]
|
||||
@@ -61,9 +61,7 @@ def test_params_diff_from_cli(dvc, mocker):
|
||||
|
||||
|
||||
def test_params_diff_show_json(dvc, mocker, capsys):
|
||||
cli_args = parse_args(
|
||||
["params", "diff", "HEAD~10", "HEAD~1", "--show-json"]
|
||||
)
|
||||
cli_args = parse_args(["params", "diff", "HEAD~10", "HEAD~1", "--json"])
|
||||
cmd = cli_args.func(cli_args)
|
||||
mocker.patch(
|
||||
"dvc.repo.params.diff.diff", return_value={"params.yaml": {"a": "b"}}
|
||||
|
||||
@@ -46,7 +46,7 @@ def test_cloud_status(tmp_dir, dvc, mocker):
|
||||
|
||||
@pytest.mark.parametrize("status", [{}, {"a": "b", "c": [1, 2, 3]}, [1, 2, 3]])
|
||||
def test_status_show_json(dvc, mocker, capsys, status):
|
||||
cli_args = parse_args(["status", "--show-json"])
|
||||
cli_args = parse_args(["status", "--json"])
|
||||
assert cli_args.func == CmdDataStatus
|
||||
|
||||
cmd = cli_args.func(cli_args)
|
||||
|
||||
Reference in New Issue
Block a user