def test_machine_list(tmp_dir, dvc, capsys): from dvc.commands.machine import CmdMachineList (tmp_dir / ".dvc" / "config").write_text(FULL_CONFIG_TEXT) with console_width(ui.rich_console, 255): assert main(["machine", "list"]) == 0 out, _ = capsys.readouterr() for key in CmdMachineList.TABLE_COLUMNS: assert f"{key}" in out assert "bar azure - -" in out assert "foo aws us-west iterative-cml True 1.2345" in out assert "10 l *** ***" in out assert "tesla" in out with console_width(ui.rich_console, 255): assert main(["machine", "list", "bar"]) == 0 out, _ = capsys.readouterr() assert "foo" not in out assert "name cloud" in out assert "bar azure" in out
def test_status(tmp_dir, scm, dvc, machine_config, machine_instance, capsys): assert main(["machine", "add", "bar", "aws"]) == 0 with console_width(ui.rich_console, 255): assert main(["machine", "status"]) == 0 cap = capsys.readouterr() assert ("name instance status cloud instance_ip " "instance_type instance_hdd_size instance_gpu") in cap.out assert ("bar - offline - - " "- - -") in cap.out assert ("foo num_1 running aws 123.123.123.123 " "m 35 None") in cap.out
def test_show_filter( tmp_dir, scm, dvc, capsys, i_metrics, i_params, e_metrics, e_params, included, excluded, ): from dvc.ui import ui capsys.readouterr() div = "│" if os.name == "nt" else "┃" tmp_dir.gen("copy.py", COPY_SCRIPT) params_file = tmp_dir / "params.yaml" params_data = { "foo": 1, "bar": 1, "train/foo": 1, "train/bar": 1, "nested": {"foo": 1, "bar": 1}, } (tmp_dir / params_file).dump(params_data) dvc.run( cmd="python copy.py params.yaml metrics.yaml", metrics_no_cache=["metrics.yaml"], params=["foo"], name="copy-file", deps=["copy.py"], ) scm.add( [ "dvc.yaml", "dvc.lock", "copy.py", "params.yaml", "metrics.yaml", ".gitignore", ] ) scm.commit("init") command = ["exp", "show", "--no-pager", "--no-timestamp"] if i_metrics is not None: command.append(f"--include-metrics={i_metrics}") if i_params is not None: command.append(f"--include-params={i_params}") if e_metrics is not None: command.append(f"--exclude-metrics={e_metrics}") if e_params is not None: command.append(f"--exclude-params={e_params}") with console_width(ui.rich_console, 255): assert main(command) == 0 cap = capsys.readouterr() for i in included: assert f"{div} params.yaml:{i} {div}" in cap.out assert f"{div} metrics.yaml:{i} {div}" in cap.out for e in excluded: assert f"{div} params.yaml:{e} {div}" not in cap.out assert f"{div} metrics.yaml:{e} {div}" not in cap.out