Files
dvc/tests/func/test_cli.py
T
2c9cb87679 Subcommand help (#3956)
* change DvcParser to print subcommand help

* add tests for subcommand help

* docstring refactoring

* remote: finish separating RemoteTree methods (#3946)

* remote: move upload()/download() into tree

* remote: move path_info/path_cls into tree

* remote.azure: finish moving methods into tree

* remote.gs: finish moving methods into tree

* remote.hdfs: finish moving methods to tree

* remote.http: finish moving methods into tree

* remote.oss: finish moving methods into tree

* remote.s3: finish moving methods into tree

* remote.ssh: finish moving methods into tree

* remote.gdrive: finish moving methods into tree

* tests: update remote unit tests

* tests: update func tests

* remote: use walk_files() for all remotes

* list_cache_paths() now uses tree.walk_files() for all remotes except
  local/ssh

* fix DS warnings

* bugfixes

* Unify metrics behavior with dirs (#3935)

* run: disable directories for -m/-M flags

* run: reformatted string literals

* run: simplified metrics check

* tests: func: run: dirs as metrics outs

* tests: func: run: reformatted string literals

* tests: use pytest

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

* refactor/test multistage load for params and outputs (#3949)

* refactor multistage load for params and outputs

* tests: load params

* tests: output loading from pipeline file

* fix test

* fix typo in name

* split params load

* rename params func s/inject_values/fill_values

* fix tests

* simplify loads_params and output.load_from_pipeline

* address @pared's suggestions for tests

* remote: fix build errors (#3957)

* remote: fix remaining gdrive build issues (#3959)

* tests: fix gdrive build

* remote.gdrive: fix walk_files prefix relpath

* change DvcParser to print subcommand help

* add tests for subcommand help

* docstring refactoring

* change tests to pytest-style

* remove gettext

Co-authored-by: Peter Rowlands (변기호) <[email protected]>
Co-authored-by: nik123 <[email protected]>
Co-authored-by: Ruslan Kuprieiev <[email protected]>
Co-authored-by: Saugat Pachhai <[email protected]>
2020-06-05 23:44:02 +03:00

207 lines
5.1 KiB
Python

import os
from dvc.cli import parse_args
from dvc.command.add import CmdAdd
from dvc.command.base import CmdBase
from dvc.command.checkout import CmdCheckout
from dvc.command.config import CmdConfig
from dvc.command.data_sync import CmdDataPull, CmdDataPush
from dvc.command.gc import CmdGC
from dvc.command.init import CmdInit
from dvc.command.remove import CmdRemove
from dvc.command.repro import CmdRepro
from dvc.command.run import CmdRun
from dvc.command.status import CmdDataStatus
from dvc.exceptions import DvcException, DvcParserError
from tests.basic_env import TestDvc
class TestArgParse(TestDvc):
def test(self):
args = parse_args(["init"])
self.assertIsInstance(args.func(args), CmdInit)
class TestRun(TestDvc):
def test(self):
dep1 = "dep1"
dep2 = "dep2"
out1 = "out1"
out2 = "out2"
out_no_cache1 = "out_no_cache1"
out_no_cache2 = "out_no_cache2"
fname = "dvc.dvc"
cmd = "cmd"
arg1 = "arg1"
arg2 = "arg2"
args = parse_args(
[
"run",
"-d",
dep1,
"--deps",
dep2,
"-o",
out1,
"--outs",
out2,
"-O",
out_no_cache1,
"--outs-no-cache",
out_no_cache2,
"-f",
fname,
"--file",
fname,
cmd,
arg1,
arg2,
]
)
self.assertIsInstance(args.func(args), CmdRun)
self.assertEqual(args.deps, [dep1, dep2])
self.assertEqual(args.outs, [out1, out2])
self.assertEqual(args.outs_no_cache, [out_no_cache1, out_no_cache2])
self.assertEqual(args.file, fname)
self.assertEqual(args.command, [cmd, arg1, arg2])
class TestPull(TestDvc):
def test(self):
args = parse_args(["pull"])
self.assertIsInstance(args.func(args), CmdDataPull)
class TestPush(TestDvc):
def test(self):
args = parse_args(["push"])
self.assertIsInstance(args.func(args), CmdDataPush)
class TestStatus(TestDvc):
def test(self):
args = parse_args(["status"])
self.assertIsInstance(args.func(args), CmdDataStatus)
class TestRepro(TestDvc):
def test(self):
target1 = "1"
target2 = "2"
args = parse_args(
["repro", target1, target2, "-f", "--force", "-s", "--single-item"]
)
self.assertIsInstance(args.func(args), CmdRepro)
self.assertEqual(args.targets, [target1, target2])
self.assertEqual(args.force, True)
self.assertEqual(args.single_item, True)
class TestRemove(TestDvc):
def test(self):
target1 = "1"
target2 = "2"
args = parse_args(["remove", target1, target2])
self.assertIsInstance(args.func(args), CmdRemove)
self.assertEqual(args.targets, [target1, target2])
class TestAdd(TestDvc):
def test(self):
target1 = "1"
target2 = "2"
args = parse_args(["add", target1, target2])
self.assertIsInstance(args.func(args), CmdAdd)
self.assertEqual(args.targets, [target1, target2])
class TestGC(TestDvc):
def test(self):
args = parse_args(["gc"])
self.assertIsInstance(args.func(args), CmdGC)
class TestGCMultipleDvcRepos(TestDvc):
def test(self):
args = parse_args(["gc", "-p", "/tmp/asdf", "/tmp/xyz"])
self.assertIsInstance(args.func(args), CmdGC)
self.assertEqual(args.repos, ["/tmp/asdf", "/tmp/xyz"])
class TestConfig(TestDvc):
def test(self):
name = "param"
value = "1"
args = parse_args(["config", "-u", "--unset", name, value])
self.assertIsInstance(args.func(args), CmdConfig)
self.assertEqual(args.unset, True)
self.assertEqual(args.name, name)
self.assertEqual(args.value, value)
class TestCheckout(TestDvc):
def test(self):
args = parse_args(["checkout"])
self.assertIsInstance(args.func(args), CmdCheckout)
class TestFindRoot(TestDvc):
def test(self):
os.chdir("..")
class A:
quiet = False
verbose = True
args = A()
with self.assertRaises(DvcException):
CmdBase(args)
def test_unknown_command_help(capsys):
try:
_ = parse_args(["unknown"])
except DvcParserError:
pass
captured = capsys.readouterr()
output = captured.out
try:
_ = parse_args(["--help"])
except SystemExit:
pass
captured = capsys.readouterr()
help_output = captured.out
assert output == help_output
def test_unknown_subcommand_help(capsys):
sample_subcommand = "push"
try:
_ = parse_args([sample_subcommand, "--unknown"])
except DvcParserError:
pass
captured = capsys.readouterr()
output = captured.out
try:
_ = parse_args([sample_subcommand, "--help"])
except SystemExit:
pass
captured = capsys.readouterr()
help_output = captured.out
assert output == help_output