Skip to content

Commit

Permalink
Merge branch 'master' into refactor-remote-s3
Browse files Browse the repository at this point in the history
  • Loading branch information
efiop authored Jan 6, 2020
2 parents 78dd489 + 0f08b7e commit 4f312f6
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 48 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ jobs:
tags: true
repo: iterative/dvc
- name: Snapcraft snap
stage: deploy
addons:
snaps:
- name: snapcraft
Expand All @@ -121,6 +122,8 @@ jobs:
snap: dvc_*.snap
channel: ${SOURCE_TAG:+stable}${SOURCE_TAG:-edge}
skip_cleanup: true
on:
branch: master

before_install:
- bash ./scripts/ci/before_install.sh
Expand Down
2 changes: 1 addition & 1 deletion dvc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class NoRemoteError(ConfigError):
def __init__(self, command):
msg = (
"no remote specified. Setup default remote with\n"
" dvc config core.remote <name>\n"
" dvc remote default <name>\n"
"or use:\n"
" dvc {} -r <name>\n".format(command)
)
Expand Down
16 changes: 8 additions & 8 deletions tests/func/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,16 @@ def test(self):
"protected,dir_mode,file_mode",
[(False, 0o775, 0o664), (True, 0o775, 0o444)],
)
def test_shared_cache(repo_dir, dvc_repo, protected, dir_mode, file_mode):
assert main(["config", "cache.shared", "group"]) == 0
def test_shared_cache(tmp_dir, dvc, protected, dir_mode, file_mode):
dvc.config.set("cache", "shared", "group")
dvc.config.set("cache", "protected", str(protected))
dvc.cache = Cache(dvc)

if protected:
assert main(["config", "cache.protected", "true"]) == 0
tmp_dir.dvc_gen(
{"file": "file content", "dir": {"file2": "file 2 " "content"}}
)

assert main(["add", repo_dir.FOO]) == 0
assert main(["add", repo_dir.DATA_DIR]) == 0

for root, dnames, fnames in os.walk(dvc_repo.cache.local.cache_dir):
for root, dnames, fnames in os.walk(dvc.cache.local.cache_dir):
for dname in dnames:
path = os.path.join(root, dname)
assert stat.S_IMODE(os.stat(path).st_mode) == dir_mode
Expand Down
11 changes: 5 additions & 6 deletions tests/func/test_data_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
from tests.remotes import (
_should_test_gcp,
_should_test_hdfs,
_should_test_oss,
_should_test_ssh,
Azure,
GDrive,
S3,
OSS,
TEST_CONFIG,
TEST_SECTION,
TEST_GCP_CREDS_FILE,
Expand All @@ -47,7 +47,6 @@
get_gcp_url,
get_hdfs_url,
get_local_url,
get_oss_url,
get_ssh_url,
get_ssh_url_mocked,
)
Expand Down Expand Up @@ -272,10 +271,10 @@ def _get_cloud_class(self):

class TestRemoteOSS(TestDataCloudBase):
def _should_test(self):
return _should_test_oss()
return OSS.should_test()

def _get_url(self):
return get_oss_url()
return OSS.get_url()

def _get_cloud_class(self):
return RemoteOSS
Expand Down Expand Up @@ -544,10 +543,10 @@ def _test(self):

class TestRemoteOSSCLI(TestDataCloudCLIBase):
def _should_test(self):
return _should_test_oss()
return OSS.should_test()

def _test(self):
url = get_oss_url()
url = OSS.get_url()

self.main(["remote", "add", TEST_REMOTE, url])

Expand Down
4 changes: 2 additions & 2 deletions tests/func/test_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ def _get_dep(dvc, path):


@pytest.mark.parametrize("url,scheme", TESTS)
def test_scheme(dvc_repo, url, scheme):
assert type(_get_dep(dvc_repo, url)) == DEP_MAP[scheme]
def test_scheme(dvc, url, scheme):
assert type(_get_dep(dvc, url)) == DEP_MAP[scheme]
41 changes: 19 additions & 22 deletions tests/remotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,6 @@ def _should_test_gcp():
return True


def _should_test_oss():
do_test = env2bool("DVC_TEST_OSS", undefined=None)
if do_test is not None:
return do_test

return (
os.getenv("OSS_ENDPOINT")
and os.getenv("OSS_ACCESS_KEY_ID")
and os.getenv("OSS_ACCESS_KEY_SECRET")
)


def _should_test_ssh():
do_test = env2bool("DVC_TEST_SSH", undefined=None)
if do_test is not None:
Expand Down Expand Up @@ -165,14 +153,6 @@ def get_gcp_url():
return "gs://" + get_gcp_storagepath()


def get_oss_storagepath():
return "{}/{}".format(TEST_OSS_REPO_BUCKET, (uuid.uuid4()))


def get_oss_url():
return "oss://{}".format(get_oss_storagepath())


# NOTE: staticmethod is only needed in Python 2
class Local:
should_test = staticmethod(lambda: True)
Expand Down Expand Up @@ -268,8 +248,25 @@ def get_url():


class OSS:
should_test = staticmethod(_should_test_oss)
get_url = staticmethod(get_oss_url)
@staticmethod
def should_test():
do_test = env2bool("DVC_TEST_OSS", undefined=None)
if do_test is not None:
return do_test

return (
os.getenv("OSS_ENDPOINT")
and os.getenv("OSS_ACCESS_KEY_ID")
and os.getenv("OSS_ACCESS_KEY_SECRET")
)

@staticmethod
def get_storagepath():
return "{}/{}".format(TEST_OSS_REPO_BUCKET, (uuid.uuid4()))

@staticmethod
def get_url():
return "oss://{}".format(OSS.get_storagepath())


class SSH:
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/command/test_imp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from dvc.command.imp import CmdImport


def test_import(mocker, dvc_repo):
def test_import(mocker):
cli_args = parse_args(
["import", "repo_url", "src", "--out", "out", "--rev", "version"]
)
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/command/test_imp_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from dvc.exceptions import DvcException


def test_import_url(mocker, dvc_repo):
def test_import_url(mocker):
cli_args = parse_args(["import-url", "src", "out", "--file", "file"])
assert cli_args.func == CmdImportUrl

Expand All @@ -17,7 +17,7 @@ def test_import_url(mocker, dvc_repo):
m.assert_called_once_with("src", out="out", fname="file")


def test_failed_import_url(mocker, caplog, dvc_repo):
def test_failed_import_url(mocker, caplog):
cli_args = parse_args(["import-url", "http://somesite.com/file_name"])
assert cli_args.func == CmdImportUrl

Expand Down
8 changes: 4 additions & 4 deletions tests/unit/remote/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@
from tests.utils.httpd import StaticFileServer


def test_no_traverse_compatibility(dvc_repo):
def test_no_traverse_compatibility(dvc):
config = {
"url": "http://example.com/",
"path_info": "file.html",
"no_traverse": False,
}

with pytest.raises(ConfigError):
RemoteHTTP(dvc_repo, config)
RemoteHTTP(dvc, config)


def test_download_fails_on_error_code(dvc_repo):
def test_download_fails_on_error_code(dvc):
with StaticFileServer() as httpd:
url = "http://localhost:{}/".format(httpd.server_port)
config = {"url": url}

remote = RemoteHTTP(dvc_repo, config)
remote = RemoteHTTP(dvc, config)

with pytest.raises(HTTPError):
remote._download(URLInfo(url) / "missing.txt", "missing.txt")
4 changes: 2 additions & 2 deletions tests/unit/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ def test_send(mock_post, tmp_path):
({"analytics": "false", "unknown": "broken"}, False),
],
)
def test_is_enabled(dvc_repo, config, result, monkeypatch, tmp_global_config):
configobj = dvc_repo.config._repo_config
def test_is_enabled(dvc, config, result, monkeypatch, tmp_global_config):
configobj = dvc.config._repo_config
configobj["core"] = config
configobj.write()

Expand Down

0 comments on commit 4f312f6

Please sign in to comment.