mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-06 15:28:28 +01:00
* Implement export-to-remote functionality * Redistrubition of functionality from tree to remote * Pass chunk size into the open_url * Move functionality away from remote to cache * Basic progress bars for both transfer types * Proper job calculation * Redesign .open() usage in order to work with different trees * Align the signatures of other open() functions to accept **kwargs * Implement chunked uploading to the ssh * Use local cache to compute directory hash (md5) * S3: multipart upload test * Wrap local cache's hash_to_path with PathInfo * Use .isdir() instead of a try/except statement for calculating the from_infos * New CLI layout (add/import-url) * Adjust CLI tests to accept new arguments * tests: import_url/add func/unit tests * Introduce cache.transfer() * Invalid CLI combination tests * Store dir_info key in the transfer_directory * LocalTree.upload_fobj * Tests for utils * Lazy imports on some places * --to-remote migration (and repo._transfer) * Use proper temporary location, more efficient pbar calc * Directory transfer logic rewrite * Use shutil.copyfileobj() * Rebase... * Better tests * Inline transfer operation to .add() / .transfer() * Open in the 'rb' mode for the tests * More tests, better invalid option handling at repo level * .read() certain amount of bytes to validate the content * Better invalid argument handling * Better progress bars by using .getsize() API * For fallback upload, use the from_info.name instead of temporary naem * introduce --jobs for add/import-url
102 lines
2.3 KiB
Python
102 lines
2.3 KiB
Python
import logging
|
|
|
|
from dvc.cli import parse_args
|
|
from dvc.command.add import CmdAdd
|
|
|
|
|
|
def test_add(mocker, dvc):
|
|
cli_args = parse_args(
|
|
[
|
|
"add",
|
|
"--recursive",
|
|
"--no-commit",
|
|
"--external",
|
|
"--glob",
|
|
"--file",
|
|
"file",
|
|
"--desc",
|
|
"stage description",
|
|
"data",
|
|
]
|
|
)
|
|
assert cli_args.func == CmdAdd
|
|
|
|
cmd = cli_args.func(cli_args)
|
|
m = mocker.patch.object(cmd.repo, "add", autospec=True)
|
|
|
|
assert cmd.run() == 0
|
|
|
|
m.assert_called_once_with(
|
|
["data"],
|
|
recursive=True,
|
|
no_commit=True,
|
|
glob=True,
|
|
fname="file",
|
|
external=True,
|
|
out=None,
|
|
remote=None,
|
|
to_remote=False,
|
|
desc="stage description",
|
|
jobs=None,
|
|
)
|
|
|
|
|
|
def test_add_to_remote(mocker):
|
|
cli_args = parse_args(
|
|
[
|
|
"add",
|
|
"s3://bucket/foo",
|
|
"--to-remote",
|
|
"--out",
|
|
"bar",
|
|
"--remote",
|
|
"remote",
|
|
]
|
|
)
|
|
assert cli_args.func == CmdAdd
|
|
|
|
cmd = cli_args.func(cli_args)
|
|
m = mocker.patch.object(cmd.repo, "add", autospec=True)
|
|
|
|
assert cmd.run() == 0
|
|
|
|
m.assert_called_once_with(
|
|
["s3://bucket/foo"],
|
|
recursive=False,
|
|
no_commit=False,
|
|
glob=False,
|
|
fname=None,
|
|
external=False,
|
|
out="bar",
|
|
remote="remote",
|
|
to_remote=True,
|
|
desc=None,
|
|
jobs=None,
|
|
)
|
|
|
|
|
|
def test_add_to_remote_invalid_combinations(mocker, caplog):
|
|
cli_args = parse_args(
|
|
["add", "s3://bucket/foo", "s3://bucket/bar", "--to-remote"]
|
|
)
|
|
assert cli_args.func == CmdAdd
|
|
|
|
cmd = cli_args.func(cli_args)
|
|
with caplog.at_level(logging.ERROR, logger="dvc"):
|
|
assert cmd.run() == 1
|
|
expected_msg = "multiple targets can't be used with --to-remote"
|
|
assert expected_msg in caplog.text
|
|
|
|
for option, value in (
|
|
("--remote", "remote"),
|
|
("--out", "bar"),
|
|
("--jobs", "4"),
|
|
):
|
|
cli_args = parse_args(["add", "foo", option, value])
|
|
|
|
cmd = cli_args.func(cli_args)
|
|
with caplog.at_level(logging.ERROR, logger="dvc"):
|
|
assert cmd.run() == 1
|
|
expected_msg = f"{option} can't be used without --to-remote"
|
|
assert expected_msg in caplog.text
|