Files
dvc/tests/unit/command/test_plot.py
T
Paweł RedzyńskiandRuslan Kuprieiev e553511085 Metrics - plotting for multiple revisions initial (#3577)
* init

* rename to plot data insertion basig on dicts update

* revision support

* roll back revision

* plot makedirs for backward compatibility

* log path

* pretty plot link to visualization page

* make target default title

* efiop review

* efiop review

* plot multiple initial

* add some missing metric file tests

* proper id generation

* proper id generation

* add confusion matrix template

* refactor tests

* plot from dvct file

* plot from dvct

* brush up commands

* fix confusion matrix multiple plot

* plot: change confusion matrix data schema

* should be working as intended

* support for src file in dvct files

* minor fixes

* plot: support json templates

* plot: rename confusion template

* plot: polish command behaviour

* fix test for json

* plot: test command

* some minor fixes for tests

* plot: unit test loading

* plot: unit test loading

* plot: handle TODOS

* cleanup

* use mocker

* plot: support tsv

* plot: command refactoring

* plot: fix windows issues with tests

* plot: test: some more windows fixes

* plot: _load_from_revisions complexity fix

* plot: reduce complexity

* plot: complexity reduction

* plot: deepsource suggestions

* plot: move template path evaluation

* fixup

* fixup

* exception on no datafile and no template

* json metric load with OrderedDict

* plot: improve handling non-existing files on revisions

* plot: improve handling non-existing files on revisions

* change default plot path

* some exceptions and fixes

* add yaml metrics support

* fixup

* some more suggestions

* default filename fix

* efiop review requests

* log exception on failur

* move revisions deduction to commands

* json templates

* extract template filling to separate method

* some parsing improvements

* add columns functionality

* extract default data transformation to separate method

* plot: initial support for jsonpath

* plot: rename columns to filters, tests are dict based

* plot: fixups

* plot: refactoring

* repo: plot: convert to package

* plot: data loading refactor, support searching for data

* plot: raise if wrong fields provided

* plot: command description

* plot: default: pass y axis info for default plot

* plot: get rid of fieldnames, expect ordered data

* plot: handle default plot in separate method

* plot: fix default

* plot: command option names fixes

* refactoring

* fixes

* plot: provide option for stdout redirection

* plot: rename show-json to no-html

* plot: add no-csv-header option

* plot: improve error message for wrongly structured metric

* plot: match template name exactly, whit suffix appended only

* plot: dmpetrov and ivan review

* plot: refactor --stdout help message

* plot: move template to repo/plot

* plot: add -x and -y options

* plot: add -x and -y options

* plot: command: order change

* plot: scatter

* plot: rename confusion matrix template, new name generation format

* plot: add title anchor

* plot: review from jorgeorpinel

* plot: rename filter and result options to select and file

* plot: add --title, --x-title, --y-title

* plot: xlab ylab

* Update dvc/repo/plot/template.py

Co-authored-by: Ruslan Kuprieiev <[email protected]>

* Update dvc/repo/plot/template.py

Co-authored-by: Ruslan Kuprieiev <[email protected]>

* efiop review

* plot: bash completion

* plot: static code analysis fixes

Co-authored-by: Ruslan Kuprieiev <[email protected]>
2020-05-01 22:45:03 +03:00

123 lines
2.8 KiB
Python

import pytest
from dvc.cli import parse_args
from dvc.command.plot import CmdPlotShow, CmdPlotDiff
def test_metrics_diff(mocker):
cli_args = parse_args(
[
"plot",
"diff",
"--file",
"result.extension",
"-t",
"template",
"-d",
"datafile",
"--select",
"column1,column2",
"--no-html",
"--stdout",
"-x",
"x_field",
"-y",
"y_field",
"--title",
"my_title",
"--xlab",
"x_title",
"--ylab",
"y_title",
"HEAD",
"tag1",
"tag2",
]
)
assert cli_args.func == CmdPlotDiff
cmd = cli_args.func(cli_args)
m = mocker.patch.object(cmd.repo, "plot", autospec=True)
mocker.patch("builtins.open")
mocker.patch("os.path.join")
assert cmd.run() == 0
m.assert_called_once_with(
datafile="datafile",
template="template",
revisions=["HEAD", "tag1", "tag2"],
fields={"column1", "column2"},
path=None,
embed=False,
x_field="x_field",
y_field="y_field",
csv_header=True,
title="my_title",
x_title="x_title",
y_title="y_title",
)
def test_metrics_show(mocker):
cli_args = parse_args(
[
"plot",
"show",
"-f",
"result.extension",
"-t",
"template",
"-s",
"$.data",
"--no-html",
"--stdout",
"--no-csv-header",
"datafile",
]
)
assert cli_args.func == CmdPlotShow
cmd = cli_args.func(cli_args)
m = mocker.patch.object(cmd.repo, "plot", autospec=True)
mocker.patch("builtins.open")
mocker.patch("os.path.join")
assert cmd.run() == 0
m.assert_called_once_with(
datafile="datafile",
template="template",
revisions=None,
fields=None,
path="$.data",
embed=False,
x_field=None,
y_field=None,
csv_header=False,
title=None,
x_title=None,
y_title=None,
)
@pytest.mark.parametrize(
"arg_revisions,is_dirty,expected_revisions",
[
([], False, ["workspace"]),
([], True, ["HEAD", "workspace"]),
(["v1", "v2", "workspace"], False, ["v1", "v2", "workspace"]),
(["v1", "v2", "workspace"], True, ["v1", "v2", "workspace"]),
],
)
def test_revisions(mocker, arg_revisions, is_dirty, expected_revisions):
args = mocker.MagicMock()
cmd = CmdPlotDiff(args)
mocker.patch.object(args, "revisions", arg_revisions)
mocker.patch.object(cmd.repo.scm, "is_dirty", return_value=is_dirty)
assert cmd._revisions() == expected_revisions